This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Stricter Bitcode Symbol Resolution
ClosedPublic

Authored by kyulee on Aug 15 2023, 10:49 AM.

Details

Reviewers
int3
thevinster
ellis
Group Reviewers
Restricted Project
Commits
rGa033184abb80: [lld-macho] Stricter Bitcode Symbol Resolution
Summary

LLD resolves symbols before performing LTO compilation, assuming that the symbols in question are resolved by the resulting object files from LTO. However, there is a scenario where the prevailing symbols might be resolved incorrectly due to specific assembly symbols not appearing in the symbol table of the bitcode. This patch deals with such a scenario by generating an error instead of silently allowing a mis-linkage.
If a prevailing symbol is resolved through post-loaded archives via LC linker options, a warning will now be issued.

Diff Detail

Event Timeline

kyulee created this revision.Aug 15 2023, 10:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 15 2023, 10:49 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
kyulee requested review of this revision.Aug 15 2023, 10:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 10:49 AM
kyulee updated this revision to Diff 550396.Aug 15 2023, 10:55 AM

Update format

kyulee updated this revision to Diff 550399.Aug 15 2023, 11:03 AM

Update tests.

thevinster accepted this revision.Aug 21 2023, 3:42 AM

Overall, lgtm. Minor comments

lld/MachO/SymbolTable.cpp
155

Can we also add a condition to cast this file as a bitcode file just make sure that it is in fact a bitcode file?

156–166

So if I understand the comment here correctly, A has a module asm symbol that is defined in B, but incorrectly resolves it to the bitcode file instead of the object file? This dependency issue kinda seems like a bug rather than a limitation and I wonder if this scenario should be supported. Though using module asm in source is already sketchy, in itself, so it might be worth error-ing to as a forcing function to make users fix their errors at the right level.

This revision is now accepted and ready to land.Aug 21 2023, 3:42 AM
kyulee updated this revision to Diff 552376.Aug 22 2023, 8:16 AM

Incorporate the comment.

kyulee marked an inline comment as done.Aug 22 2023, 8:22 AM
kyulee added inline comments.
lld/MachO/SymbolTable.cpp
156–166

This is the case where we error out where we can't resolve the prevailing symbol correctly.
I think blocking module asm itself is an overkill given there exists user code that already has assembly.
I think this is a peculiar case where module asm is used to hold a reference that is even not defined in this compilation unit.

kyulee updated this revision to Diff 552407.Aug 22 2023, 9:32 AM

Fix the rebase.

This revision was automatically updated to reflect the committed changes.