[PATCH] D26133: [ELF] Allow relative relocations to absolute symbols in PIC

Cary Coutant via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 10:52:12 PST 2017


> Rafael suggested using any section value other than SHN_ABS and SHN_UNDEF,
> but that means the symbol is going to have a section relative value which
> means the section must have the address 0x0. The only candidate I can think
> of is .shstrtab or creating a new synthetic section. It was my understanding
> that the purpose of SHN_ABS is to express that: symbols that are not
> relative to any other section. Those symbols exists, even in ET_DYN objects,
> e.g. _gp and _gp_disp on MIPS. This is also what Ian described in his blog
> post and it is the behavior that ld and gold implements.

No, symbols in an ET_EXEC or ET_DYN object always have
already-relocated values. The section index is irrelevant other than
to indicate that the symbol is not absolute or undefined. That's the
point of the paragraph I quoted from the end of the symbol table
chapter from the ELF spec. In gold, I try to find a section that
belongs to the segment that the symbol is associated with, but setting
st_shndx to 1 would be just as effective.

Yes, SHN_ABS means that the symbol is not relative to any other
section, which means that its value remains constant even if the image
is relocated in memory. Symbols like _etext, _edata, and _end should
*not* be absolute, since they are, in fact, relative to some section
of the image, and should relocate with it. Emitting these as SHN_ABS
symbols is a bug, but has only recently started causing issues because
of the recent increased usage of PIE.

-cary


More information about the llvm-commits mailing list