This is the mail archive of the binutils@sources.redhat.com 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]

Re: Symbol re-ordering in ld?


Bryce McKinlay <bryce@albatross.co.nz> writes:

> Is it possible to have the linker emit symbols in some explicit order,
> rather than just whatever order is encountered in the input files?

Possible?  Yes.  However, the current linker does not support this.

> Specifically, GCJ emits a "class registration" global constructor for
> every class it compiles. These end up being dispersed throughout
> generated archives (such as libgcj.so), resulting in added startup
> overhead as the kernel has to bring in many dispersed pages. If we
> could group those global constructor functions together, the number of
> page faults at startup would presumably be reduced resulting in faster
> loading binaries.
> 
> Additionally, wouldn't it be a generally useful optimization to have
> the linker always group global constructors together in an output
> file?

These would indeed be useful.  However, sorting symbols won't do it.
Symbols are just addresses.  It sounds like you want to move code.  I
know that I'm being pedantic, but linkers are nothing if not pedantic.

You may be trying to say something like ``can the linker sort the code
based on the name of the immediately preceding global symbol?''  The
answer to that question, in the general case, is no.

Fortunately, there is a much simpler way to do what you want.  Arrange
to put all global constructors in a specially named section.  The
linker will automatically bring together all sections with the same
name.  This should give you the paging behaviour you want, and the
linker already supports it.

Ian


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