This is an archive of the discontinued LLVM Phabricator instance.

[lld] [LinkerScript] Handle symbols defined in linker scripts
ClosedPublic

Authored by rafaelauler on Mar 11 2015, 1:12 PM.

Details

Summary

This patch plays on top of D8157 because it needs the expression
evaluation mechanism working in DefaultLayout.

Puts symbols defined in linker script expressions in a runtime file that is
added as input to the resolver, making the input object files see symbols
defined in linker scripts.

Diff Detail

Event Timeline

rafaelauler retitled this revision from to [lld] [LinkerScript] Handle symbols defined in linker scripts.
rafaelauler updated this object.
rafaelauler edited the test plan for this revision. (Show Details)
rafaelauler added a subscriber: Unknown Object (MLST).
ruiu edited edge metadata.Mar 11 2015, 1:19 PM

It looks like you added absolute symbols in the writer, so these absolute symbols don't exist when symbol names are resolved. For example, if your hello world program has a reference to MYSTRING, it fails to link. Is this what you expected?

For now I just used the same mechanism used to add other linker-defined symbols such as _bss_start, etc. I plan to later change this to be more precise.

BTW the linking does not fail, I tested it with another test case that actually depended on MYSTRING and it worked. Not sure if this is the expected behavior though, as I said, I just mimicked the behavior for other linker-defined symbols.

Oh you meant, the linking will fail because it is done in the writer (a final step)? No, this is added before the resolver gets called.

ruiu added a comment.Mar 11 2015, 1:25 PM

Ah, I missed that point. You added symbols to Runtime file, so they are present when the core linker works. LGTM.

davide added a subscriber: davide.Mar 11 2015, 1:27 PM

JFYI, handling of aforementioned symbols isn't completely correct. See D8241 for details.

Thanks for pointing out Davide, I saw this patch. But there are two things that are not correct in init_array:

First, lld couldn't resolve the correct address of init array. This does not affect my patch because I get my addresses from the linker script symbol table.

Second, the symbol is ABS in lld, but in GNU ld it is not. This also happens for symbols defined in linker scripts. As I mentioned, I plan to later change this to emulate the behaviour of GNU ld. However, I'm not sure if this is strictly necessary. I'll do this when I find a test case that proved LLD's way to be incorrect.

davide accepted this revision.Mar 11 2015, 1:37 PM
davide added a reviewer: davide.

Yeah, that's definitely lower priority. The patch looks good to me otherwise, please go for it. I have an use case for this patch in FreeBSD.

This revision is now accepted and ready to land.Mar 11 2015, 1:37 PM
davide added a comment.Apr 6 2015, 4:16 PM

Can this be closed?

rafaelauler closed this revision.Apr 7 2015, 1:20 PM