RT-Thread / RT-Thread/rt-thread
aarch64-gcc编译,rt_memset等函数编译问题
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
在kservice.c中,提供了rt_memset等标准库函数的等价实现,很方便移植到无libc的平台上。但是gcc似乎并不领情:
在rt_memset末尾有一段针对非对齐地址的逐字节拷贝:
while (count--)
{
*m++ = (char)d;
}
用gcc -O2编译这段代码时,生成了这样的汇编:

其直接调用了memset这个符号,但是当然,这个符号是未定义的。
建议解决方案:
- 使用gcc编译kservice.c文件时,默认加上编译选项-fno-tree-loop-distribute-patterns来阻止编译器自动生成memset等函数调用
或者:
- 在每个CPU平台上分别使用汇编实现memset等函数,并相应定义为rt_memset的别名/宏定义/嵌套调用
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with kservice.c and inspect the rt_memset implementation, then reproduce the aarch64-gcc -O2 build described in the issue. Confirm that the generated code references an undefined memset symbol, and ensure the selected fix keeps the libc-free build working without that unresolved reference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100