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]

Re: Conditionals in Linker Scripts


Hi Nick,

> > 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?
> Yes.  If you use different linker scripts for the different sceanarios then
> you can arrange for each script to use INPUT() directives to include only the
> necessary startup code.

> 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.

Felix


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