与 newlib 链接:对 memcpy 的未定义引用

发布于 2024-12-21 09:14:10 字数 1510 浏览 4 评论 0原文

我正在尝试构建一个arm引导加载程序,它依赖newlib来提供一些系统调用(如memcpy)。

当我运行时:

arm-elf-ld -static -L /usr/arm-elf/lib/thumb/ -lc -nostdlib -nostartfile -Map=loader.map --cref -T loader.lds --gc-sections -Ttext 0x000000 -n -o loader.elf start.o _udivsi3.o _umodsi3.o main.o util.o gpio.o spi.o flashatmel.o flashjedec.o image.o time.o clock.o led.o register.o sdram.o

我得到以下信息:

 flashatmel.o flashjedec.o image.o time.o clock.o led.o register.o sdram.o            
 main.o: In function `TtyPutConfiguration':
/home/shawn/projects/netbridge-fx/loader/main.c:19: undefined reference to `memcpy'
main.o: In function `main':
/home/shawn/projects/netbridge-fx/loader/main.c:135: undefined reference to   `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:145: undefined reference to `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:155: undefined reference to `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:165: undefined reference to `__gnu_thumb1_case_uqi'
gpio.o: In function `GpioTest':
/home/shawn/projects/netbridge-fx/loader/gpio.c:139: undefined reference to `__gnu_thumb1_case_uqi'

现在,我正在攻击 memcpy,并希望其他人跟进。当我运行 nm /usr/arm-elf/lib/thumb/libc.a 时(我相信这是 libc 的 newlib 版本),它显示:

lib_a-memcpy.o:
00000010 N $d
00000000 t $t
00000001 T memcpy

所以,这表明 memcpy 已定义在图书馆里。

我对上面的 ld 命令运行了 strace,以确保它确实在查看该文件,确实如此。

我在这里缺少什么?为什么它抱怨未定义的 memcpy?

I'm trying to build an arm boot loader, and it's relying on newlib to supply some system calls (like memcpy).

When I run:

arm-elf-ld -static -L /usr/arm-elf/lib/thumb/ -lc -nostdlib -nostartfile -Map=loader.map --cref -T loader.lds --gc-sections -Ttext 0x000000 -n -o loader.elf start.o _udivsi3.o _umodsi3.o main.o util.o gpio.o spi.o flashatmel.o flashjedec.o image.o time.o clock.o led.o register.o sdram.o

I get the following:

 flashatmel.o flashjedec.o image.o time.o clock.o led.o register.o sdram.o            
 main.o: In function `TtyPutConfiguration':
/home/shawn/projects/netbridge-fx/loader/main.c:19: undefined reference to `memcpy'
main.o: In function `main':
/home/shawn/projects/netbridge-fx/loader/main.c:135: undefined reference to   `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:145: undefined reference to `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:155: undefined reference to `__gnu_thumb1_case_uqi'
/home/shawn/projects/netbridge-fx/loader/main.c:165: undefined reference to `__gnu_thumb1_case_uqi'
gpio.o: In function `GpioTest':
/home/shawn/projects/netbridge-fx/loader/gpio.c:139: undefined reference to `__gnu_thumb1_case_uqi'

For now, I'm attacking the memcpy, and hoping the others follow. When I run nm /usr/arm-elf/lib/thumb/libc.a (which, I believe, is the newlib version of libc), it shows:

lib_a-memcpy.o:
00000010 N $d
00000000 t $t
00000001 T memcpy

So, that shows that memcpy is defined in the library.

I ran strace on the ld command above to make sure it's actually looking at that file, and indeed, it is.

What am I missing here? Why is it complaining about an undefined memcpy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少跟Wǒ拽 2024-12-28 09:14:10

这看起来很可疑:

-lc -nostdlibs

我认为 -nostdlibs 正在取消 -lc。尝试直接链接 libc.a 并看看会发生什么。

当您这样做时,我看到您正在链接一些内部实现(例如 _udivsi3.o)。尝试与 libgcc.a 链接,它应该具有您需要的所有内在函数的定义。

This looks fishy:

-lc -nostdlibs

I think -nostdlibs is canceling out -lc. Try linking libc.a directly and see what happens.

While you're at it, I see you're linking in some intrinsic implementations (like _udivsi3.o). Try linking with libgcc.a, it should have definitions for all of the intrinsics you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文