Linker Bug or Design Intent (Absolute symbols in zero sized sections)

Jakub Jelinek jakub@redhat.com
Wed Oct 11 14:45:00 GMT 2006


On Wed, Oct 11, 2006 at 01:23:05PM +0930, Alan Modra wrote:
> On Wed, Oct 11, 2006 at 01:19:22AM +0200, Jakub Jelinek wrote:
> > Either we could add here REMOVE_EMPTY flag, or, perhaps better, not consider
> > at least symbol = absolute value assignments as section relative,
> 
> Sections containing symbols really do need to stay, for --emit-relocs
> and dynamic relocs.  Or at least, we need to do something to make them
> work properly.

Dynamic relocs aren't an issue here, in both cases we are talking about
executables and the the __{{pre,}init,fini}_array_{start,end} symbols
are PROVIDE_HIDDEN and __SDA_BASE__ likely should be PROVIDE_HIDDEN too
(and, furthermore for __SDA_BASE__ using section relative symbol is wrong,
as it is assigned a constant value, unrelated to the current section
(and in any case tweaked by the ppc backend; if there is non-empty
.sdata, __SDA_BASE__ is even ABS, only when it is empty it is section
relative ATM)).  For --emit-relocs and the init/fini array symbols
we again don't care what exact values they have, as long as a post-linking
tool doesn't want to add things into one of the previously empty
.init_array etc. sections.  But, such tool either would need to be
aware what these symbols mean and set them properly after inserting
stuff there, the *_array_start one to the beginning of the section and
*_array_end to the end of the section, or it would do the wrong thing
(kept either both symbols at the beginning, or end of the section it
grew, in any case for the _start code this would mean there is no such
section).

Against emitting empty sections speaks both that it is a wasted space
in section header table/.shstrtab, but more importantly that empty
sections are an endless source of bugs (as shown yesterday e.g.
on x86-64) in almost every tool that needs to deal with them.
This is not the first time ld didn't get sh_offsets for empty sections
right, I remember fighting with that several times in prelink, strip/objcopy
was messing them up in the past too and prelink had bugs in handling them
too.

	Jakub



More information about the Binutils mailing list