RT-Thread / RT-Thread/rt-thread

[Bug] smart版本启用RT_USING_PTHREADS配置后,无法通过编译,类型冲突

Open
#11,339 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

RT-Thread Version

v5.2.2 Release

Hardware Type/Architectures

arm

Develop Toolchain

GCC

Describe the bug

编译器类型是arm-linux-musleabi-gcc,版本信息如下:

arm-linux-musleabi-gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

build date: Jan  6 2023 18:24:13
musl  sha: 3536b4bc84df4672ac3b3747e36e3fa1332efc9b
build sha: 3536b4bc84df4672ac3b3747e36e3fa1332efc9b
build job: 434371

启用RT_USING_PTHREADS配置后,components/libc/posix/pthreads组件就无法通过编译:

/home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.h:37:14: error: conflicting types for 'pthread_t'
 typedef long pthread_t;
              ^~~~~~~~~
In file included from /home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/sys/types.h:57:0,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rttypes.h:20,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtsched.h:14,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtdef.h:68,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rthw.h:23,
                 from /home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.c:16:
/home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/bits/alltypes.h:301:28: note: previous declaration of 'pthread_t' was here
 typedef struct __pthread * pthread_t;
                            ^~~~~~~~~
In file included from /home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.c:17:0:
/home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.h:38:14: error: conflicting types for 'pthread_condattr_t'
 typedef long pthread_condattr_t;
              ^~~~~~~~~~~~~~~~~~
In file included from /home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/sys/types.h:57:0,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rttypes.h:20,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtsched.h:14,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtdef.h:68,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rthw.h:23,
                 from /home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.c:16:
/home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/bits/alltypes.h:327:37: note: previous declaration of 'pthread_condattr_t' was here
 typedef struct { unsigned __attr; } pthread_condattr_t;
                                     ^~~~~~~~~~~~~~~~~~
In file included from /home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.c:17:0:
/home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.h:39:14: error: conflicting types for 'pthread_rwlockattr_t'
 typedef long pthread_rwlockattr_t;
              ^~~~~~~~~~~~~~~~~~~~
In file included from /home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/sys/types.h:57:0,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rttypes.h:20,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtsched.h:14,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rtdef.h:68,
                 from /home/Tiimmi/codes/rtthread/rtthread/include/rthw.h:23,
                 from /home/Tiimmi/codes/rtthread/rtthread/components/libc/posix/pthreads/pthread.c:16:
/home/Tiimmi/codes/rtthread/env/arm-linux-musleabi-linux-gnu/arm-linux-musleabi/include/bits/alltypes.h:337:40: note: previous declaration of 'pthread_rwlockattr_t' was here
 typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t;

节选了部分报错信息,剩余的报错基本都是rtthread中定义的类型与编译器头文件中定义的类型冲突了。

在网上搜索好像都没看到有人说过这个问题,只有一个2019年的issue:#3070

但是也没说解决方法。

smart版本的lwp组件强制要求musllibc,更换其他类型编译器会报:“No compatible lwp set status provided for this libc”

但是musl编译器的头文件定义的pthread类型和rtthread里的pthread.h头文件里定义的类型冲突。如何能够仍smart版本也能启用RT_USING_PTHREADS配置?

还是smart版本上使用pthread不需要启用这个配置?或者smart版本的pthread就是有问题的?

Other additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with components/libc/posix/pthreads/pthread.h and pthread.c, then inspect the include chain through rttypes.h and the musl headers at bits/alltypes.h. Reproduce the RT_USING_PTHREADS build with arm-linux-musleabi-gcc 7.3.0 and compare the conflicting type declarations. Done means the smart configuration builds without pthread type conflicts.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.