This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Test case for correct input section order, when sections are listed in linker script
ClosedPublic

Authored by evgeny777 on Jul 11 2016, 5:56 AM.

Details

Reviewers
ruiu
ikudrin
Summary

Current version does not maintain correct input section order, when sections are listed in linker script. Input sections always have the same order as in object files, which is not correct.
Consider this linker script

SECTIONS {
  .foo { *(.foo.*) *(.bar.*) }
}

The result ELF image should have all .foo.* sections placed before all .bar.* sections. This patch implements this adding order value to SectionRule and then sorting input sections properly in case ScriptConfig->DoLayout is true

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 63493.Jul 11 2016, 5:56 AM
evgeny777 retitled this revision from to [ELF] Implement correct input section ordering, when sections are listed in linker script.
evgeny777 updated this object.
evgeny777 added reviewers: ruiu, ikudrin.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
ruiu edited edge metadata.Jul 11 2016, 2:14 PM

Currently we are creating output sections only in Writer.cpp, but George is working on doing it in LinkerScript.cpp if a linker script is given. If the logic is in LinkerScript.cpp, we can create output sections as we visit each SECTIONS subcommand in linker scripts, so we don't need to ask about it to getOutputSections. Therefore, I think you want to wait for that change.

Okay, great. Is someone working on symbol assignment within input section list? If not, I'd like to implement this.

ruiu added a subscriber: ruiu.Jul 11 2016, 2:52 PM

Is it different from your http://reviews.llvm.org/D22088?

Yes it is. I'd like to be able to do this:

SECTIONS {
    .foo : { *(.foo.*) end_foo = .; *(.bar.*) end_bar=.; } }
}
ruiu added a comment.Jul 11 2016, 2:59 PM

I think no one is working on it, but I guess it also depends on the
George's work, as it can be done as we visit each SECTIONS command. If it
is not, feel free to write a patch.

grimar added a subscriber: grimar.Jul 12 2016, 1:05 AM
evgeny777 updated this revision to Diff 65044.Jul 22 2016, 3:15 AM
evgeny777 retitled this revision from [ELF] Implement correct input section ordering, when sections are listed in linker script to [ELF] Test case correct input section ordering, when sections are listed in linker script.
evgeny777 edited edge metadata.
evgeny777 removed rL LLVM as the repository for this revision.
evgeny777 edited subscribers, added: llvm-commits; removed: ruiu.

Input section order problem was fixed by
https://reviews.llvm.org/D22455
and
https://reviews.llvm.org/D22617

This patch adds test case, so it won't be broken occasionally

evgeny777 retitled this revision from [ELF] Test case correct input section ordering, when sections are listed in linker script to [ELF] Test case for correct input section order, when sections are listed in linker script.Jul 22 2016, 3:16 AM
ruiu accepted this revision.Jul 23 2016, 4:31 AM
ruiu edited edge metadata.

LGTM. Please update the commit message as this change now contains only a test.

This revision is now accepted and ready to land.Jul 23 2016, 4:31 AM
evgeny777 closed this revision.Jul 25 2016, 4:07 AM