This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: reimplemented output sections constrains matching functionality.
ClosedPublic

Authored by grimar on Aug 9 2016, 9:59 AM.

Details

Summary

Previously filtering that was used worked incorrectly.
For example for next script it would just remove both sections completely:

SECTIONS {
. = 0x1000;
.aaa : ONLY_IF_RW { *(.aaa.*) }
. = 0x2000;
.aaa : ONLY_IF_RO { *(.aaa.*) }
}

Patch fixes above issues and adds testcase showing the issue. Testcase is a subset of
FreeBSD script which has:

.eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
...
.eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }

As a side result of a change, behavior of these commands is looks to be equal with ld now.

Diff Detail

Event Timeline

grimar updated this revision to Diff 67363.Aug 9 2016, 9:59 AM
grimar retitled this revision from to [ELF] - Linkerscript: reimplemented output sections constrains matching functionality..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777, davide.
grimar updated this revision to Diff 67480.Aug 10 2016, 1:21 AM
  • Removed dead code and unrelated changes in testcase.
  • Cosmetic changes.
ruiu added inline comments.Aug 10 2016, 6:30 PM
ELF/LinkerScript.cpp
271–272

I cannot infer P.first's class from this local context. Please create a temporary varaible

OutputSectionCommand *Cmd = P.first;

to make it obvious.

grimar updated this revision to Diff 67664.Aug 11 2016, 2:40 AM
  • Rebased.
ELF/LinkerScript.cpp
271–272

Gone after rebasing.

ruiu accepted this revision.Aug 11 2016, 1:48 PM
ruiu edited edge metadata.

LGTM

ELF/LinkerScript.cpp
263–264

Hoist RO and RW because they are actually constants.

bool RO = (Kind == ConstraintKind::ReadOnly);
bool RW = (Kind == ConstraintKind:: ReadWriter);
return !llvm::any_of(Sections, [=](InputSectionBase<ELFT> *Sec) {
  bool Writable = ...;
  return (RO && Writable) || (RW && !Writable);
});
This revision is now accepted and ready to land.Aug 11 2016, 1:48 PM
This revision was automatically updated to reflect the committed changes.