This is an archive of the discontinued LLVM Phabricator instance.

Split InputSectionDescription::Sort into SortInner and SortOuter.
ClosedPublic

Authored by ruiu on Aug 3 2016, 2:27 PM.

Details

Summary

The comparator function to compare input sections as instructed by
SORT command was a bit too complicated because it needed to handle
four different cases. This patch split it into two function calls.

This patch also simplifies the parser.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 66723.Aug 3 2016, 2:27 PM
ruiu retitled this revision from to Split InputSectionDescription::Sort into SortInner and SortOuter..
ruiu updated this object.
ruiu added a reviewer: grimar.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 66752.Aug 3 2016, 7:22 PM
  • Rebased.
grimar accepted this revision.Aug 4 2016, 2:11 AM
grimar edited edge metadata.

I like it, LGTM. Comments below.

ELF/LinkerScript.cpp
142 ↗(On Diff #66752)

I found a bug, SORT_BY_ALIGNMENT should sort sections into descending order.
Committed fix as r277706.
So condition should be ">" here.

752 ↗(On Diff #66752)

May be something like:

if (K1 != K2)
Cmd->SortInner = K2;

to avoid double sorting when the same rule is specified twice:
SORT_BY_NAME (SORT_BY_NAME(...))

This revision is now accepted and ready to land.Aug 4 2016, 2:11 AM
grimar added inline comments.Aug 4 2016, 7:09 AM
ELF/LinkerScript.cpp
752 ↗(On Diff #66752)

Though it seems to be useless cornercase and we probably should not really care, preferring shorter code.

ruiu updated this revision to Diff 66865.Aug 4 2016, 3:27 PM
ruiu edited edge metadata.
  • Rebased.
ruiu added inline comments.Aug 4 2016, 3:29 PM
ELF/LinkerScript.cpp
760 ↗(On Diff #66865)

Yup. Double-sorting is wasteful, but it's probably doesn't have to be handled as an error

This revision was automatically updated to reflect the committed changes.
grimar added inline comments.Aug 5 2016, 2:47 AM
lld/trunk/ELF/LinkerScript.cpp
149

btw interesting that gold has an issue here. lld and ld are compatible, but gold sorts by alignment in assending order what
is different from spec and looks like a bug.