This is an archive of the discontinued LLVM Phabricator instance.

[ELF2/LinkerScript] Fix OUTPUT_FORMAT directive parsing
ClosedPublic

Authored by davide on Oct 12 2015, 1:00 PM.

Details

Summary

Right now the parser recognizes
OUTPUT_ARCH("foo")
but not OUTPUT_ARCH("foo", "goo", "blah")
This patch is an attempt to fix.

Side note:
Also, the diagnostic we emit is currently very uninformative.
In the future, I think we could improve this aspect showing which directive failed to parse -- or even better, line/column of failure. I would like to discuss design further.

Diff Detail

Repository
rL LLVM

Event Timeline

davide updated this revision to Diff 37151.Oct 12 2015, 1:00 PM
davide retitled this revision from to [ELF2/LinkerScript] Fix OUTPUT_FORMAT directive parsing.
davide updated this object.
davide added reviewers: ruiu, rafael.
davide added a subscriber: llvm-commits.
ruiu edited edge metadata.Oct 12 2015, 1:17 PM

s/OUTPUT_ARCH/OUTPUT_FORMAT/

Rename linkerscript-outputgroup.s -> linkerscript-outputformat.s.

Regarding better error handling, I don't think now is the right time to do something about that. This parser is a designed to be just enough to read Linux's libc.so, and this should suffice until we link something like a OS kernel, so designing a linker script that is capable more than this one is in my opinion relatively low priority.

ELF/LinkerScript.cpp
222 ↗(On Diff #37151)

Wrong indentation.

test/elf2/linkerscript-ouputgroup.s
2 ↗(On Diff #37151)

You also need a test for OUTPUT_FORMAT(default, big, little)-style directive.

I'm sorry, I updated a wrong/stale diff. I'll update a new one shortly.

In D13668#265235, @ruiu wrote:

s/OUTPUT_ARCH/OUTPUT_FORMAT/

Rename linkerscript-outputgroup.s -> linkerscript-outputformat.s.

Regarding better error handling, I don't think now is the right time to do something about that. This parser is a designed to be just enough to read Linux's libc.so, and this should suffice until we link something like a OS kernel, so designing a linker script that is capable more than this one is in my opinion relatively low priority.

This is exactly my point. In fact, I said "in the future", and not "now". That said, I think it's good to emit meaningful diagnostics for users at some point.

davide updated this revision to Diff 37163.Oct 12 2015, 1:47 PM
davide edited edge metadata.

Now with the correct diff. I also renamed the test. Sorry for messing up the name at least a couple of times, but apparently the code was the only place where I got it right :)

davide updated this revision to Diff 37165.Oct 12 2015, 1:50 PM

Use a real triple for the test.

ruiu added inline comments.Oct 12 2015, 1:55 PM
ELF/LinkerScript.cpp
214–215 ↗(On Diff #37163)
next();
StringRef Tok = next();
test/elf2/linkerscript-ouputformat.s
2–3 ↗(On Diff #37163)

I'd write OUTPUT_FORMAT(x, y, z) as we don't actually care about the values.

8 ↗(On Diff #37163)

So is this.

12 ↗(On Diff #37163)

You also need a test to check OUTPUT_FOMAT(x) is considered valid.

davide added inline comments.Oct 12 2015, 1:58 PM
test/elf2/linkerscript-ouputformat.s
12 ↗(On Diff #37165)

There's one already in linkerscript.s

davide updated this revision to Diff 37166.Oct 12 2015, 1:59 PM

Rename identifiers in test.

ruiu accepted this revision.Oct 12 2015, 2:01 PM
ruiu edited edge metadata.

LGTM with a nit.

ELF/LinkerScript.cpp
214–215 ↗(On Diff #37166)

Please discard the result first next() and assign only the second one.

This revision is now accepted and ready to land.Oct 12 2015, 2:01 PM
This revision was automatically updated to reflect the committed changes.