This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Conditionals in Linker Scripts


Gentlemen,

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
dtors?

Thanks for any help you can offer!

Felix


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]