Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][picolibc] improve gcc picolibc support #8220

Merged
merged 3 commits into from
Nov 8, 2023

Conversation

iDings
Copy link
Contributor

@iDings iDings commented Nov 3, 2023

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

现阶段的绝大部分的gcc编译工具链默认都是使用newlibc,crosstool-ng可以制作
带picolibc的gcc编译工具链, 使用该工具链接rt-thread无法编译编译

你的解决方案是什么 (what is your solution)

增加部分缺失的picolibc依赖接口:https://github.com/picolibc/picolibc/blob/main/doc/os.md

在什么测试环境下测试通过 (what is the test environment)

  • 使用crosstool-ng生成的gcc(picolibc)工具链编译,qemu-vexpress-a9 正常启动运行
  • llvm-arm能正常编译stm32f407-rt-spark

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@iDings
Copy link
Contributor Author

iDings commented Nov 3, 2023

后续改进点:
zephyr-sdk的gcc编译工具链包含newlibc跟picolibc,可以通过gcc的--specs=参数指定picolibc,
现阶段的tools/gcc.py查找头文件include路径是固定的,改成自动获取搜索路径的方式https://stackoverflow.com/questions/4980819/what-are-the-gcc-default-include-directories, 这样兼容性应该会更好点

arm-zephyr-eabi-gcc  -xc /dev/null -E -Wp,-v 2>&1 | sed -n 's,^ ,,p'

/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/sys-include
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/include
./bin/arm-zephyr-eabi-gcc --specs=arm-zephyr-eabi/lib/picolibc.specs -xc /dev/null -E -Wp,-v 2>&1 | sed -n 's,^ ,,p'
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/../../picolibc/include
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/sys-include
/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/include

@Guozhanxin
Copy link
Member

@iDings 可以帮忙用 llvm-arm 试一下这个bsp吗:https://github.com/RT-Thread/rt-thread/tree/master/bsp/renesas/ra8m1-ek

他这个 bsp 好像依赖了 picolibc 的 tls 功能。但是我知道该怎么处理。

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2023

CLA assistant check
All committers have signed the CLA.

@iDings
Copy link
Contributor Author

iDings commented Nov 3, 2023

@iDings 可以帮忙用 llvm-arm 试一下这个bsp吗:https://github.com/RT-Thread/rt-thread/tree/master/bsp/renesas/ra8m1-ek

他这个 bsp 好像依赖了 picolibc 的 tls 功能。但是我知道该怎么处理。

我也发现这个bsp, llvm-arm编译不过. 我可以看下,看能不能找到原因

@iDings
Copy link
Contributor Author

iDings commented Nov 3, 2023

@Guozhanxin 使用picolibc需要对TLS做些初始化,链接脚本里面需要定义TLS存储信息跟符号
https://github.com/picolibc/picolibc/blob/main/doc/tls.md而且线程里面也需要配合使用这些信息,
之前gcc+newlibc的编译工具链都是--disable-tls 使用的是emulated TLS(https://bugs.launchpad.net/gcc-arm-embedded/+bug/1842725).

TLS的话GCC+PICOLIBC也是有问题,这个我要看下怎么处理.
picolibc的作者在RIOT上有增加TLS改动: https://github.com/RIOT-OS/RIOT/commits?author=keith-packard 可以做点参考

PICOLIBC参考的链接脚本还需要增对不同的ld还需要设置不同的align
https://github.com/picolibc/picolibc/blob/75273b12bba66bbe7633514a2c43690a724458fe/picolibc.ld.in#L183

@mysterywolf
Copy link
Member

感谢提交PR PR准备就绪之后请@我review

@Guozhanxin
Copy link
Member

Guozhanxin commented Nov 6, 2023

感谢提交PR PR准备就绪之后请@我review

@mysterywolf 我感觉现在这个pr就可以review了,tls相关的,下个pr再说吧。

@iDings
Copy link
Contributor Author

iDings commented Nov 6, 2023

我先把这个 #8220 (comment) 做了,这样后面也可以直接使用zephyr sdk的编译工具链验证gcc+picolibc的功能.
然后tls的话后面单独再提交一个PR

@iDings iDings force-pushed the gcc_picolibc branch 3 times, most recently from 4a183e1 to 7b34daa Compare November 7, 2023 12:48
@iDings
Copy link
Contributor Author

iDings commented Nov 7, 2023

@mysterywolf 帮忙review下改动,我这边现在只在ubuntu下做了验证.

验证方法:
zephyr-sdk toolchain 可以使用用来验证同时验证gcc+newlibc与gcc+picolibc.
对于使用gcc+picolibc需要打上如下patch,

diff --git a/bsp/qemu-vexpress-a9/rtconfig.py b/bsp/qemu-vexpress-a9/rtconfig.py
index 77cc9dfb4..391e13f2f 100644
--- a/bsp/qemu-vexpress-a9/rtconfig.py
+++ b/bsp/qemu-vexpress-a9/rtconfig.py
@@ -49,7 +49,9 @@ if PLATFORM == 'gcc':
     STRIP   = PREFIX + 'strip'
     CFPFLAGS = ' -msoft-float'
     AFPFLAGS = ' -mfloat-abi=softfp -mfpu=neon'
-    DEVICE   = ' -march=armv7-a -mtune=cortex-a7 -ftree-vectorize -ffast-math -funwind-tables -fno-strict-aliasing'
+    DEVICE = ''
+    DEVICE += ' --specs=picolibc.specs --picolibc-prefix=' + EXEC_PATH + '/../'
+    DEVICE += ' -march=armv7-a -mtune=cortex-a7 -ftree-vectorize -ffast-math -funwind-tables -fno-strict-aliasing'
 
     CXXFLAGS= DEVICE + CFPFLAGS + ' -Wall -fdiagnostics-color=always'
     CFLAGS  = DEVICE + CFPFLAGS + ' -Wall -Wno-cpp -std=gnu99 -D_POSIX_SOURCE -fdiagnostics-color=always'

按理说可以不使用--picolibc-prefix,但是没有指定的话发现会提示找不到crt0,查找的路径很奇怪,暂时不确定什么原因.

@mysterywolf mysterywolf merged commit da55491 into RT-Thread:master Nov 8, 2023
37 checks passed
@mysterywolf
Copy link
Member

感谢提交PR!

@mysterywolf
Copy link
Member

mysterywolf commented Nov 10, 2023

你好 这个PR改出问题了 https://club.rt-thread.org/ask/question/dfc88acb52dfbaba.html

复现方法 进入任何一个bsp 例如stm32 直接menuconfig刷新一下配置 然后scons 编译即可发现编译报错

image

麻烦修复一下 谢谢!

@Guozhanxin
Copy link
Member

你好 这个PR改出问题了 https://club.rt-thread.org/ask/question/dfc88acb52dfbaba.html

复现方法 进入任何一个bsp 例如stm32 直接menuconfig刷新一下配置 然后scons 编译即可发现编译报错

image

麻烦修复一下 谢谢!

@iDings 麻烦看一下这个问题,好像是 run 在 python2.x 的版本不支持

@iDings
Copy link
Contributor Author

iDings commented Nov 22, 2023

@mysterywolf @Guozhanxin 抱歉刚看到, 我看下

@iDings
Copy link
Contributor Author

iDings commented Nov 22, 2023

如果python支持2.0的话, 建议现在CI检查的时候也是python2.0的版本, 然后建议有文档说明

@mysterywolf
Copy link
Member

mysterywolf commented Nov 22, 2023 via email

@iDings
Copy link
Contributor Author

iDings commented Nov 22, 2023

@mysterywolf 🤝 抱歉哈

@iDings iDings mentioned this pull request Dec 21, 2023
9 tasks
@mysterywolf
Copy link
Member

mysterywolf commented Jan 21, 2024

你好 之前提交了个PR并没有彻底解决这个问题 #8254

请最好确认一下Python2环境可以正常执行,不要用.run这个方法,这个方法只在python3里有,请用subprocess.Popen代替
https://club.rt-thread.org/ask/question/dfc88acb52dfbaba.html

1705821625482

@iDings
Copy link
Contributor Author

iDings commented Jan 25, 2024

好的, 我确认下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants