This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Implement -u flag
ClosedPublic

Authored by thakis on Jan 9 2021, 7:22 PM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rGe0b8604e5d3c: [lld/mac] Implement -u flag
Summary

Since we emit diagnostics for undefineds in Writer::scanRelocations()
and symbols referenced by -u flags aren't referenced by any relocations,
this needs some manual code (similar to the entry point).

Diff Detail

Event Timeline

thakis created this revision.Jan 9 2021, 7:22 PM
thakis requested review of this revision.Jan 9 2021, 7:22 PM
MaskRay added a subscriber: MaskRay.Jan 9 2021, 9:08 PM
MaskRay added inline comments.
lld/test/MachO/u.s
23

Would be nice to check the interaction with .weak_reference

thakis added inline comments.Jan 10 2021, 6:19 AM
lld/test/MachO/u.s
23

As far as I understand, .weak_reference only affects which opcodes are written to the import bind FSA description and doesn't interact with symbol lookup. Are you thinking of -U instead of -u maybe? Or do you mean a test that checks if a -u resolved against a dylib pulls in the dylib (independent of weak_ref)?

int3 added a subscriber: int3.Jan 12 2021, 11:37 AM

Since we emit diagnostics for undefineds in Writer::scanRelocations()

I've been wondering whether this is the right way to do it... in particular, we end up emitting one error message per relocation to an undefined, even if they all point to the same undefined. I made a brief attempt to scan the symbol table instead, but that creates spurious errors for things like .globl unused_and_undefined. I suppose we could always just dedup the symbols when scanning through the relocations though. Do you know how LLD-ELF handles this?

lld/test/MachO/u.s
23

yeah I don't see how weak_reference would need to be tested here either

Since we emit diagnostics for undefineds in Writer::scanRelocations()

I've been wondering whether this is the right way to do it... in particular, we end up emitting one error message per relocation to an undefined, even if they all point to the same undefined. I made a brief attempt to scan the symbol table instead, but that creates spurious errors for things like .globl unused_and_undefined. I suppose we could always just dedup the symbols when scanning through the relocations though. Do you know how LLD-ELF handles this?

COFF goes through the symbol table. ELF is relocation-based (IIRC it used to not be but something moved it to be relocation based.) I made it dedup diags in D63344 (later slightly refined in D77017).

For ELF, both linkers (GNU ld,gold,LLD) and loaders (glibc,musl,FreeBSD rtld,etc) report undefined symbols only when relocations are present.

int3 accepted this revision.Jan 29 2021, 10:25 AM

Thanks for the pointers to the ELF diffs! I guess we'll implement deduplication in a similar way in the future.

lld/test/MachO/u.s
33

nit: extra line

This revision is now accepted and ready to land.Jan 29 2021, 10:25 AM
This revision was automatically updated to reflect the committed changes.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 9 2021, 5:23 AM