This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix SysV hash tables with --no-rosegment
ClosedPublic

Authored by smeenai on Jan 10 2018, 5:20 PM.

Details

Summary

When setting up the chain, we copy over the bucket's previous symbol
index, assuming that this index will be 0 (STN_UNDEF) for an unused
bucket (marking the end of the chain). When linking with --no-rosegment,
however, unused buckets will in fact contain the padding value, and so
the hash table will end up containing invalid chains. Explicitly
zero-initialize the buckets to fix this problem. Also explicitly
zero-initialize the chain entry for STN_UNDEF; I don't think this is
actually necessary, but it doesn't hurt, and should make the hash table
identical both with and without --no-rosegment.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.Jan 10 2018, 5:20 PM
ruiu added inline comments.Jan 10 2018, 10:42 PM
ELF/SyntheticSections.cpp
1839 ↗(On Diff #129376)

I'd do memset(Buf, 0, Size) here just like we did at beginning of GnuHashTableSection::writeTo(). That's less error-prone and easy to understand than filling holes with zeros. Zero-clearing a contiguous chunk of memory is very fast, so we don't have to minimize the number of bytes written to memory in this case.

smeenai updated this revision to Diff 129394.Jan 10 2018, 10:46 PM
smeenai marked an inline comment as done.

Rui's comment

ruiu accepted this revision.Jan 10 2018, 10:48 PM

LGTM

ELF/SyntheticSections.cpp
1839–1841 ↗(On Diff #129394)

If you copy-n-paste this comment, update the other comment to refer this one, so that we won't end up having the identical comment in two functions.

This revision is now accepted and ready to land.Jan 10 2018, 10:48 PM
smeenai updated this revision to Diff 129395.Jan 10 2018, 10:52 PM

Change comment to refer to existing one

This revision was automatically updated to reflect the committed changes.