I am building a bare-metal code for ARM926 and I need the generated output to be as tight as possible.
我正在为ARM926构建一个裸机代码,我需要生成的输出尽可能紧凑。
In my best effort, though, I still receive this error:
不过,在我的最大努力中,我仍然收到这个错误:
yocto/poky/build-idprint/tmp/work/idprint-poky-linux-gnueabi/idpr/1.0-r0/
recipe-sysroot/usr/lib/libc.a(raise.o):
(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr1'
In my Makefile
I put this linker flags:
在我的Makefile中,我放置了这个链接器标志:
LD_OPT = -Wl,-gc-sections -Wl,-build-id=none -flto
LD_LINK = -static -nostartfiles -nostdlib -Wl,--start-group,-lgcc,-lc,--end-group
LDFLAGS = -T $(BINARY).ld -Xlinker -Map=$(BINARY).map $(LD_OPT)
And the link command is
链接命令是
$(LINK.cc) $(OBJS) $(LD_LINK) src/lib_dummies.o -o $(BINARY).elf
Finally I have a custom linker script as simple as possible:
最后,我有一个尽可能简单的定制链接器脚本:
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(fiq_main)
SECTIONS
{
. = 0x0;
.text : {
KEEP(*(.textEntry));
*(.text*)
*(.text .gnu.linkonce.t.*)
}
. = ALIGN(1024);
_bss_start = .;
.data : { *(.data) }
.bss : { *(.bss) }
_bss_end = .;
}
I added a custom dummy __aeabi_unwind_cpp_pr1
to my code (inspired from libgcc sources) but it didn't help.
我在代码中添加了一个定制的DUMMY__AEABI_UNWIND_CPP_PR1(灵感来自libgcc源代码),但它没有帮助。
I have read about quite a few pages around the web but none explained me why is libgcc
trying to link a C++
function to my C
-only project.
Okay, $(LINK.cc)
is evaluated to arm-poky-linux-gnueabi-g++
but I still se no sense trying to link a C++
function to libgcc
. It would make sense if I was linking libstdc++
. Moreover, $(LD) fails for othre reasons (can't find -lgcc
).
我在网上读过很多页面,但没有人解释为什么libgcc试图将C++函数链接到我的纯C项目。好的,$(link.cc)的计算结果是arm-poky-linux-gnueabi-g++,但我仍然认为尝试将C++函数链接到libgcc没有任何意义。如果我链接libstdc++,这将是有意义的。此外,$(LD)由于其他原因而失败(找不到-lgcc)。
No optimization flags I could find helped me with this either.
我也找不到优化标志来帮助我做到这一点。
Look, it is very important that my code doesn't add any uneeded stuff.
Everything started only because I need to use integer division (unresolved __aeabi_idiv
...)
听着,很重要的一点是,我的代码不会添加任何未添加的内容。一切都开始了,因为我需要使用整数除法(Unsolve__aeabi_iDiv...)
I omitted the optimization flags for simplicity but, if needed, please tell me and I'll add them.
为简单起见,我省略了优化标志,但如果需要,请告诉我,我会添加它们。
Any help will be greatly appreciated.
Thanks.
任何帮助都将不胜感激。谢谢。
更多回答
优秀答案推荐
Well,
井,
after a very long battle, I ended with a relatively simple solution.
In my Makefile, I changed the LD_LINK
line to:
经过一场漫长的战斗,我最终得到了一个相对简单的解决方案。在我的生成文件中,我将LD_LINK行更改为:
LD_LINK = -static -nostartfiles -nostdlib -lgcc
(removed -Wl,--start-group,-lgcc,-lc,--end-group
)
(已删除-wl、--start-group、-lgcc、-lc、--end-group)
This led me to an undefined reference to raise
.
Then I added this few lines to an assembly source file:
这让我想到了一个不明确的提法。然后,我将以下几行添加到汇编源文件中:
.global raise
raise:
b raise
Note:
注:
I tried creating a raise
function in C but, due to name mangling and despite any tricks I've tried, the linker could never find it.
我试着用C语言创建一个Raise函数,但由于名称混乱,尽管我尝试了各种技巧,链接器始终找不到它。
I'd be really happy if someone could show me how to do that in plain C.
如果有人能用C语言向我演示如何做到这一点,我会很高兴的。
Bonus:
奖金:
My final binary is way smaller than what I was getting before, and it is just what I needed!
我最终得到的二进制文件比我以前得到的要小得多,这正是我需要的!
In my case, I found this issue only exists on arm32 but not aarch64. And it happens even when built with pure C code (so apparently no C++ exceptions). The linker complains about missing __aeabi_unwind_cpp_prX, but actually, they are never invoked by disassembling the binaries. Probably there's a bug in the linker? Anyway, the solution is to define their stub symbols and they will be orphan symbols in the final binary.
在我的例子中,我发现这个问题只存在于arm32上,而不是aarch64上。即使在使用纯C代码构建时也会发生这种情况(因此显然没有C++异常)。链接器会抱怨缺少__aeabi_unind_cpp_prx,但实际上,它们从未通过反汇编二进制文件来调用。可能链接器中有错误?无论如何,解决方案是定义它们的存根符号,它们将是最终二进制文件中的孤立符号。
By the way, adding -fno-exceptions
option to the compiler doesn't help with this problem.
顺便说一句,向编译器添加-FNO-EXCEPTIONS选项无助于解决此问题。
更多回答
我是一名优秀的程序员,十分优秀!