Comments (10)
一个有趣的发现:
目前主线上自从 ”beee77f372 feat: support ARCH_REMAP_KERNEL on libcpu/c906 (#9123)" 合入后,atoi 的问题就不见了。使用 newlib gcc 一样工作正常。
目前来看,这个问题和网上的 https://zhuanlan.zhihu.com/p/619893693 这个分析是一个道理。
没有合入 beee77f 之前,libcpu/risc-v/t-head/c906/startup_gcc.S
中没有为 boot_hartid
明确指定的 section,
boot_hartid: .int
.global boot_hartid
......
/* save hartid */
la t0, boot_hartid /* global varible rt_boot_hartid */
mv t1, a0 /* get hartid in S-mode frome a0 register */
sw t1, (t0) /* store t1 register low 4 bits in memory address which is stored in t0 */
这导致链接后 boot_hartid 被默认放到 text section,和 atoi 函数的地址一样,这会导致 save hartid 的动作覆盖了 atoi 的 text。具体见 rtthread.map
中符号的地址分布:
...
.text 0x00000000802001c6 0x0 build/kernel/libcpu/risc-v/t-head/c906/startup_gcc.o
0x00000000802001c6 boot_hartid
.text 0x00000000802001c6 0x28 /home/u/ws/bin/rtt-xuantie900-newlib-gcc/Xuantie-900-gcc-elf-newlib-x86_64-V2.8.1/bin/../lib/gcc/riscv64-unknown-elf/10.4.0/../../../../riscv64-unknown-elf/lib/rv64imac/lp64/libc.a(lib_a-atoi.o)
0x00000000802001c6 atoi
0x00000000802001da _atoi_r
最终导致执行 atoi 时发生异常。
原先换成 musl gcc 不出问题,只是因为不同编译器分配地址不同,正好没有覆盖 atoi 而已,并没有本质上解决这个潜在问题。
合入 beee77f 后,明确将 boot_hartid 分配到 .data
section,杜绝了这个问题。
--- a/libcpu/risc-v/t-head/c906/startup_gcc.S
+++ b/libcpu/risc-v/t-head/c906/startup_gcc.S
......
-boot_hartid: .int
- .global boot_hartid
+ .data
+ .global boot_hartid /* global varible rt_boot_hartid in .data section */
+boot_hartid:
+ .word 0xdeadbeef
from rt-thread.
好像很神奇呢,或许是对齐的缘故?atoi是libc的函数,目前用的libc是哪个
from rt-thread.
v5.1.0正常,master有问题
from rt-thread.
网上看到一篇文章,可能和这个问题有关系,just FYI:https://zhuanlan.zhihu.com/p/619893693
from rt-thread.
当前 小核和 大核的 gcc 用的都是 Xuantie-900-gcc-elf-newlib-x86_64-V2.8.1,但是大核需要使用 musl 的gcc,对大核换成 musleabi 的之后就不会 crash 了。
有个问题,我用的 musleabi 的 gcc 是 https://download.rt-thread.org/rt-smart/riscv64/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_180881.tar.bz2,换成其他的 musl gcc 都不行,是不是 rtt 有特殊的需求?这个问题已经提 issue,参考#9049 的讨论。
后面具体怎么解,还要看看能否将大核和小核的工程尽量统一起来。参考 #9028 的讨论。
from rt-thread.
v5.1.0正常,master有问题
5.1.0 应该也不行吧
from rt-thread.
小核目前用 newlib gcc 是好的。
from rt-thread.
RFC:
为了解决这个问题,打算将 cv18xx_riscv-v 默认切换到 musl gcc。即修改 bsp/cvitek/cv18xx_risc-v/rtconfig.py
中对 EXEC_PATH 和 PREFIX, 具体参考 bsp/qemu-virt64-riscv/rtconfig.py
比较担心的是,我这里一直用 newlib gcc 编译大核的,换成 musl gcc 后影响会有多大?
from rt-thread.
libc 的差别我理解应该没有太严重的功能影响,特别是系统内核这边用到的主要是字符处理、数学库这类的。
from rt-thread.
关闭这个 issue,目前 master 已经不会出错。
from rt-thread.
Related Issues (20)
- [Bug] bsp/cvitek/drivers gpio driver can not support cv18xx_aarch64 HOT 1
- [Bug] bsp/cvitek/drivers uart driver can not support cv18xx_aarch64 HOT 1
- [Bug] Could not compile the rt-thread\bsp\stm32\stm32f429-fire-challenger in HOT 2
- [Feature] bsp/cvitek: drivers_path_prefix can be optimized
- [Bug] bsp/qemu-virt64-riscv/SConstruct 中的 stack_size 问题 HOT 4
- [Bug] DFS_V2 无法在非smart环境下编译通过 HOT 1
- [Bug] bsp/cvitek/cv18xx_risc-v/SConstruct 中的 stack_size 问题
- [Bug] bsp/cvitek: 某些 配置宏名称不符合规范,需要改进 HOT 2
- [Bug] bsp/cvitek/cv18xx_aarch64 无法 boot 进入控制台界面 HOT 17
- [Bug] bsp/cvitek cv18xx_aarch64 miss rt_fdt_commit_memregion_early HOT 1
- [Bug] bsp/cvitek cv18xx_risc-v IRQ_MAX_NR num error HOT 3
- [Feature] lwp, dm 等组件需要补充 doxygen 注释 | Add Doxygen Comments for Components
- [Bug] ART-Pi Smart 平台 alarm() 定时相对现实时间不准确 | Inaccurate Timing of alarm()
- [Bug] DFSv1 mount rw flags
- [Bug] RP2040/Pico build error
- [Bug] FAL头文件可能会污染ulog HOT 3
- [Bug] bsp/cvitek cv18xx_aarch64 build error HOT 4
- [Bug] 无符号整形和负数进行判断是否相等
- [Bug] phytium需要使用rt_hw_common_setup启动内核
- [Bug] rt_thread_mdelay 不是延时的ms,是systick的时钟周期的和rt_thread_delay函数没区别 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rt-thread.