This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix sorting in combrelocs mode and add DT_REL(A)COUNT to .dynamic
ClosedPublic

Authored by evgeny777 on Aug 18 2016, 6:49 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

evgeny777 updated this revision to Diff 68529.Aug 18 2016, 6:49 AM
evgeny777 retitled this revision from to [ELF] Fix sorting in combrelocs mode and add DT_REL(A)COUNT to .dynamic.
evgeny777 updated this object.
evgeny777 added a reviewer: ruiu.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
grimar added inline comments.Aug 18 2016, 7:14 AM
ELF/OutputSections.cpp
364 ↗(On Diff #68529)

This breaks the optimization implemented in D19528 I think.
We found that sorting by symbol makes sence. So that should be done even for
relative relocations. I would suggest something like:

bool ARel = A.Type == Target->RelativeRel;
bool BRel = B.Type == Target->RelativeRel;
if (ARel && !BRel)
  return true;
else if (!ARel && BRel)
  return false;

return A.getSymbol(Config->Mips64EL) < B.getSymbol(Config->Mips64EL);
test/ELF/aarch64-tls-gdie.s
27 ↗(On Diff #68529)

0x0B0 != 192

test/ELF/aarch64-tls-ie.s
34 ↗(On Diff #68529)

Ditto.

test/ELF/combrelocs.s
43 ↗(On Diff #68529)

You probably want to check that RELACOUNT is present instead of removing it.
Also checking of its value may be useful.

test/ELF/gotpc-relax-nopic.s
19 ↗(On Diff #68529)

Excessive new lines.

ruiu edited edge metadata.Aug 19 2016, 8:42 AM

Did you have comments on George's comments?

evgeny777 updated this revision to Diff 68701.Aug 19 2016, 9:08 AM
evgeny777 edited edge metadata.
evgeny777 removed rL LLVM as the repository for this revision.

Sorry, I missed the comments, because notifications are not working for me today for some reason.
Review updated.

Any comments?

evgeny777 updated this revision to Diff 69491.Aug 27 2016, 8:05 AM

Diff updated

a) Fix bug in calculating number of relative relocs
b) When number of relative relocs is zero DT_REL(A)COUNT is not emitted. This greatly decreased number of patched unit tests
c) For all modified tests, I've added addition check that DET_REL(A)COUNT matches actual number of relative relocs

ruiu added inline comments.Aug 29 2016, 1:34 PM
ELF/OutputSections.cpp
672–674 ↗(On Diff #69491)

I'm not sure if it is the right thing to not emit DT_REL[A]COUNT if there are no relative relocations. If the number of relative relocations is zero, shouldn't we write zero?

evgeny777 added inline comments.Aug 29 2016, 2:06 PM
ELF/OutputSections.cpp
672–674 ↗(On Diff #69491)

This doc:
https://docs.oracle.com/cd/E19957-01/806-0641/6j9vuqujs/index.html

Says that DT_RELACOUNT is an optional field. Our dynamic linker assumes that number of relative relocs is zero, unless there is a DT_REL(A)COUNT tag. That said, I don't see any reason for writing it always.

ruiu added a comment.Aug 30 2016, 1:05 PM

LGTM. If an absence of DT_RELCOUNT doesn't cause any trouble, this is fine by me. By the way, by "our dynamic loader", did you mean a dynamic loader of your operating system or something? Just curious.

Yes,it's dynamic loader of our OS.

This revision was automatically updated to reflect the committed changes.