链接到另一个启动文件 [英] Linking with another start-up file
问题描述
我试图通过使用LD脚本中的 STARTUP
指令将程序与我自己的启动文件链接:
I am trying to link a program with my own start-up file by using the STARTUP
directive in a LD script:
...
ENTRY(_start)
STARTUP(my_crt1.o)
...
GCC驱动程序用于链接程序(不打扰libgcc等库路径):
GCC driver is used to link the program (not to bother with library paths like libgcc, etc.):
gcc -T my_script.ld ...
不幸的是,它仅适用于为powerpc目标编译的GCC,而arm或i686目标则不行,并且仍然在collect2中包含crt0.o.例如:
Unfortunately, it only works with a GCC compiled for powerpc targets, while arm or i686 targets don't and still include crt0.o in collect2. For example:
arm-eabi-g++ -v -T my_script.ld ...
给我:
collect2 ... /opt/lib/gcc/arm-eabi/4.8.0/../../../../arm-eabi/lib/crt0.o ...
因此:
crt0.S:101: multiple definition of `_start'
似乎完全忽略了 STARTUP
指令(除非指定了 STARTUP
指令,否则powerpc目标也会使用其默认的crt0),并且没有办法禁用默认值crt0.
It seems the STARTUP
directive is totally ignored (the powerpc target uses its default crt0 too unless the STARTUP
directive is specified) and there is no way to disable the default crt0.
是否可以通过便携式方式链接到另一个启动文件?
Is there a portable way to link against another start-up file?
我的启动文件使用 libgcc
函数(调用ctor和dtor),因此使用 crtbegin.o
, crtend.o
等.是必需的,因此我想避免使用 -nostartfiles
选项禁用 crt * .o
-我只需要禁用 crt0.o
.
My start-up file uses libgcc
functions (to call ctors and dtors) so crtbegin.o
, crtend.o
, etc. are needed so I would like to avoid the -nostartfiles
option which disables crt*.o
- I need to disable crt0.o
only.
谢谢
推荐答案
此限制确实迫使您使用 -nostartfiles
禁用默认启动文件(我更喜欢 -nostdlib
).然后,您需要自己构建运行时对象列表.gcc具有 -print-file-name
选项,可打印使用其编译的库的绝对路径(crtbegin.o,crtend.o,libgcc.a ...).例如: arm-eabi-g ++< FLAGS>-print-file-name = crtbegin.o
This limitation indeed forces you to disable the default startup files with -nostartfiles
(I prefer -nostdlib
). You then need to build by yourself the list of run-time objects. gcc has the option -print-file-name
to print the absolute path of libraries it was compiled with (crtbegin.o, crtend.o, libgcc.a...). For example: arm-eabi-g++ <FLAGS> -print-file-name=crtbegin.o
这是我使用的GNU Make宏(提供gcc和cflags):
Here is the GNU Make macro I use (providing gcc and cflags):
define m.in/toolchain/gnu/locate =
$(strip
$(shell $(m.in/toolchain/gnu/bin/gcc) $(m.in/toolchain/gnu/cflags) \
-print-file-name=$(m.in/argv/1))
)
endef
crtn := $(call m.in/toolchain/gnu/locate, crtn.o)
这篇关于链接到另一个启动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!