This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Disambiguate bitcode files with the same name by archive name/offset in archive
ClosedPublic

Authored by lgrey on Jul 16 2021, 12:27 PM.

Details

Summary

Ported from COFF/ELF; test is adapted from test/COFF/thinlto-archivecollision.ll

LTO expects every bitcode file to have a unique name. If given multiple bitcode files with the same name, it errors with "Expected at most one ThinLTO module per
bitcode file".

This change incorporates the archive name, to disambiguate members with the same name in different archives and the offset in archive to disambiguate members with the same name in the same archive.

Diff Detail

Event Timeline

lgrey created this revision.Jul 16 2021, 12:27 PM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
lgrey requested review of this revision.Jul 16 2021, 12:27 PM
int3 requested changes to this revision.Jul 17 2021, 1:50 PM

clearing my queue

This revision now requires changes to proceed.Jul 17 2021, 1:50 PM
lgrey updated this revision to Diff 360588.Jul 21 2021, 1:50 PM
lgrey retitled this revision from [NOT FOR REVIEW][lld-macho] Disambiguate bitcode files with the same name by archive name/offset in archive to [lld-macho] Disambiguate bitcode files with the same name by archive name/offset in archive.
lgrey edited the summary of this revision. (Show Details)
lgrey set the repository for this revision to rG LLVM Github Monorepo.
lgrey added a subscriber: llvm-commits.

Add test. Now ready for review :)

Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2021, 1:50 PM
thakis accepted this revision.Jul 22 2021, 7:55 AM
thakis added a subscriber: thakis.

Generally lg, but I'm confused by the comment (I think I unconfused myself though), and some nits about the test. Thanks!

lld/MachO/InputFiles.cpp
1287

The code adds the archiveName now, which should disambiguate two archives having the same name. Why do we need the offset too?

Looks like the offset used to be added only if archiveName is empty and D75422 changed that.

But when can the archive name be empty?

...aha, D60549 that added this to the COFF port has two obj files with the same name in a single archive. So for that including the offset makes sense. Oh, you have that test too :) So it's just the comment that's confusing. It should say "If one archive defines two members with the same name", right?

lld/test/MachO/lto-archivecollision.ll
4

.obj is a windows name. use .o.

8

nit: one space is enough

12

No need to do this again, %t/a/bar.o and %t/b/bar.o are still around from the previous test

20

Do you even need this? If the link succeeded, it means we pulled in both .o files

lgrey updated this revision to Diff 360854.Jul 22 2021, 9:15 AM
lgrey marked 3 inline comments as done.

Reword comment, refine test

lld/MachO/InputFiles.cpp
1287

It's both (when I ran into this with Chrome, it was two different archives). Rejiggered the comment a little (part about collision is no longer true since it will just error inside LTO); does it make more sense now?

lld/test/MachO/lto-archivecollision.ll
20

Agree, but this applies to all the FileCheck stuff in here. Do you think it's worth keeping as documentation, or should I just run the links, add a comment re: how they would fail, and call it a day?

thakis added inline comments.Jul 22 2021, 12:42 PM
lld/MachO/InputFiles.cpp
1283

It doesn't have to be a thin archive, regular archives can contain several files with the same name:

% echo 'void a() {}' > a.cc
% echo 'void b() {}' > b.cc
% mkdir a
% mkdir b
% clang -flto=thin -c a.cc -o a/a.o
% clang -flto=thin -c b.cc -o b/a.o
% ar -t libfoo.a
__.SYMDEF
a.o
a.o
lld/test/MachO/lto-archivecollision.ll
20

I'd keep comments as is and just remove the FIXME line, but /shruggie

lgrey updated this revision to Diff 360945.Jul 22 2021, 1:07 PM
lgrey marked an inline comment as done.

Reword comment, rm FIXME from test

lld/MachO/InputFiles.cpp
1283

Reworded

lgrey updated this revision to Diff 360998.Jul 22 2021, 3:22 PM

Typo fix

int3, could you retract your "needs changes"? Else phab thinks this isn't accepted.

thakis accepted this revision.Jul 22 2021, 4:40 PM

…and lgtm :)

int3 accepted this revision.Jul 22 2021, 5:00 PM

ah yes, I forgot the external phabricator works differently. done!

This revision is now accepted and ready to land.Jul 22 2021, 5:00 PM