This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Keep empty In.RelaIplt so that __rela_iplt_{start,end} have valid st_shndx
AbandonedPublic

Authored by MaskRay on Nov 27 2018, 6:13 PM.

Details

Reviewers
espindola
Summary

This fixes PR36634 (and https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233397)

In a statically linked executable, if __rela_iplt_{start,end} are
defined with non-existent .rela.plt (In.RelaIplt), the symbols' st_shndx
are 65535 (SHN_XINDEX) which may confuse readelf, objdump, llvm-objdump,
llvm-readelf and some other binutils because the extended symbol table
may not exist.

ld.bfd and gold do not emit empty .rela.plt but seem to use arbitrary
st_shndx for __rela_iplt_{start,end}. We can just emit the empty
.rela.plt .

Event Timeline

MaskRay created this revision.Nov 27 2018, 6:13 PM

This is fine for me (from FreeBSD's perspective), but I suspect some people (on operating systems without ifuncs in libc) may be surprised by having a(n empty) .rela.plt in all of their statically linked binaries.

This is fine for me (from FreeBSD's perspective), but I suspect some people (on operating systems without ifuncs in libc) may be surprised by having a(n empty) .rela.plt in all of their statically linked binaries.

Also read my comment https://bugs.llvm.org/show_bug.cgi?id=36634#c3 This makes most sense to me but it requires lots of changes and I haven't investigated how valid it is to have such empty ALLOC sections (and in the segment end but it probably does not matter)

ruiu added a subscriber: ruiu.Nov 28 2018, 9:26 AM

It feels this patch modifies too many places to fix a cosmetic issue. Doesn't something like this work? https://gist.github.com/rui314/6382995c81689668961caf49a0e695f9

It feels this patch modifies too many places to fix a cosmetic issue. Doesn't something like this work? https://gist.github.com/rui314/6382995c81689668961caf49a0e695f9

This works, but it may better use a SHF_ALLOC section (not sure if that is what ld.bfd uses)

ruiu added a comment.Nov 28 2018, 11:24 AM

This works, but it may better use a SHF_ALLOC section (not sure if that is what ld.bfd uses)

Ideally, yes, but if no one really cares, just using 1 is simpler and sufficient.

Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2019, 5:45 AM