This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_ attribute_hidden; return _GLOBAL_OFFSET_TABLE_; // R_X86_64_GOTPC32
In this patch, we
- Change all GOT*_FROM_END to GOTPLT* to fix the problem.
- Add HasGotPltOffRel to denote whether .got.plt should be kept even if the section is empty.
- Simply GotSection::empty and GotPltSection::empty a bit by setting HasGotOffRel and HasGotPltOffRel early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is