This is the mail archive of the
mailing list for the binutils project.
Conditionals in Linker Scripts
- From: Felix von Leitner <felix-binutils at fefe dot de>
- To: Binutils Mailing List <binutils at sourceware dot org>
- Date: Tue, 11 Dec 2018 12:56:58 +0100
- Subject: Conditionals in Linker Scripts
I have a small libc for Linux, for static linking only, and as I have
been adding features, I am growing more and more dismayed about how much
boilerplate code I need to add to and/or reference from the start code.
Currently, I allow removing features from the libc via #define at
compile time — of the libc. I would much rather do this at the compile
time of the application.
For example, my startup code has support for static PIE, but without
ld.so, so the startup code has to do some ELF parsing to apply the
relocations. This adds a few KB of code that I would rather not force
upon non-PIE static binaries.
The other example is ctor/dtor and exception handling support.
I have been thinking about how do to this. I have a small wrapper
program around the compiler, so I could theoretically do the linking
step multiple times, but that is very inefficient.
The exception handling problem could be solved with a weak symbol for
_Unwind_RaiseException, but what about the startup code for ctor/dtor
and static PIE? Is it possible to make a linker script that will only
pull in the PIE startup code if the output format is "shared library"?
Is it possible to only pull in the ctor/dtor code if there are ctors or
Thanks for any help you can offer!