This is the mail archive of the
mailing list for the binutils project.
Re: Conditionals in Linker Scripts
>> Of course based upon the subject line of your email you would rather have
>> one linker script that the performs these operations conditionally. But
>> why is that ? If you are using gcc as your compiler driver then you can
>> use the spec file syntax to select different linker scripts based upon the
>> command line options used.
> I'm already doing this for static PIE, but I'm thinking: what if someone
> has a hello world static PIE that does not actually have any
> relocations. I would love to use the smaller startup code in that
> scenario, but I don't see how I could do that in a wrapper without
> linking twice.
> Also, the wrapper does not know if there will be constructors or
> destructors in the binary before it has been linked. So I would have to
> link it, see if they are any constructors/destructors, and if not, link
> again with the smaller start code.
> I was hoping there would be a solution where the linker decides this on
> the fly, and I figured linker scripts would be the mechanism.
OK - well the basic answer is the linker scripts do not have conditional
abilities, so you are probably not going to be able to use them.
You might be able to make use of the linker's garbage collection mechanism.
If you put bits of the startup code into different sections and then having
the linker selectively discard them if they are not used. But the garbage
collector does tend to have special exceptions for startup and exit code so
this may not work.
Sorry - I think that basically the linker is not going to be able to help
you here. :-(