This is an archive of the discontinued LLVM Phabricator instance.

ELF2: Add basic linker script support.
ClosedPublic

Authored by ruiu on Sep 28 2015, 7:48 PM.

Details

Reviewers
rafael
Summary

This linker script parser and evaluator is powerful enough to read
Linux's libc.so, which is (despite its name) a linker script that
contains OUTPUT_FORMAT, GROUP and AS_NEEDED directives.

The parser implemented in this patch is a recursive-descendent one.
It does *not* construct an AST but consumes directives in place and
sets the results to the Config object, like Driver is doing. This
should be very fast since less objects are allocated, and this is
also more readable.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 35934.Sep 28 2015, 7:48 PM
ruiu retitled this revision from to ELF2: Add basic linker script support..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 35935.Sep 28 2015, 8:10 PM
silvas added a subscriber: silvas.Sep 28 2015, 8:23 PM
silvas added inline comments.
test/elf2/basic.s
181

typo: response

test/elf2/invalid-elf.test
1–8 ↗(On Diff #35934)

Why is this test affected?

ruiu added inline comments.Sep 28 2015, 8:42 PM
test/elf2/invalid-elf.test
1–8 ↗(On Diff #35935)

Because these invalid ELF files are not actually recognized as ELF files by their magic bytes. Previously, they were tried to be parsed as ELF files anyways. Now all files that have unrecognized magic are parsed as linker scripts. So these errors are not printed.

ruiu updated this revision to Diff 35936.Sep 28 2015, 8:57 PM

Fix typo, remove debug output, and fix indentation.

silvas added inline comments.Sep 28 2015, 10:35 PM
test/elf2/invalid-elf.test
1–8 ↗(On Diff #35936)

But you did not remove the place where we print the error message. Should we convert the error messages into assertions?

emaste added a subscriber: emaste.Sep 29 2015, 12:50 PM
ruiu updated this revision to Diff 36041.Sep 29 2015, 2:54 PM

Rebased to head

rafael added inline comments.Sep 29 2015, 8:14 PM
ELF/DriverUtils.cpp
203

This opens a file, mmaps it, calls identify_magic and then drops everything and returns a bool :-(

Could this be reorganized into something like

addInptsForArg(StringRef Arg) {

open file
check type
 if (archiver or elf) {
    add it.
    return;
}
parse linker script.

}

That way we only open, mmap and identify each file once.

ikudrin added inline comments.
ELF/DriverUtils.cpp
203

What if we remove intermediate containers like Inputs or InputFiles and just put all files into SymbolTable directly? Anyway, I'm going to suggest this change in my next patch for support --[no-]whole-archive.

ruiu updated this revision to Diff 36066.Sep 29 2015, 9:29 PM

Open file only once.

rafael accepted this revision.Sep 30 2015, 7:14 AM
rafael edited edge metadata.

Please git-clang-format the patch.

It is still undesirable that we call identify_magic twice, but we can work on that on another patch.

LGTM with the patch git-clang-formated.

Thanks a lot!

This revision is now accepted and ready to land.Sep 30 2015, 7:14 AM
ruiu added a subscriber: ruiu.Sep 30 2015, 10:08 AM

Committed as r248918. Thanks!

Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r248918.