This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Ignore LLVM segments to prevent duplicate syms
ClosedPublic

Authored by thevinster on Aug 12 2021, 11:06 PM.

Details

Reviewers
gkm
int3
Group Reviewers
Restricted Project
Commits
rG15dc93e61c21: [lld-macho] Ignore LLVM segments to prevent duplicate syms
Summary

There was an instance of a third-party archive containing multiple
_llvm symbols from different files that clashed with each other
producing duplicate symbols. Symbols under the LLVM segment
don't seem to be producing any meaningful value, so just ignore them.

Diff Detail

Event Timeline

thevinster created this revision.Aug 12 2021, 11:06 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
thevinster edited the summary of this revision. (Show Details)Aug 12 2021, 11:07 PM

Cleanup wording

thevinster published this revision for review.Aug 12 2021, 11:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2021, 11:19 PM
oontvoo added inline comments.
lld/test/MachO/ignore-symbols.s
11–17 ↗(On Diff #366197)

How does ld64 deal with this, though? (quick glance at the code, I didn't see any special handling for _llvm segments)

Just concerned that this change is hiding a bug somewhere else

int3 added a subscriber: int3.Aug 13 2021, 10:36 AM
int3 added inline comments.
lld/MachO/InputFiles.cpp
294

I would say that ld64 does not appear to emit contents from sections within the __LLVM segment, and that the symbols in those sections point to bitcode metadata rather than being actual symbols. In particular, global symbols within those sections can have the same name without causing duplicate symbol errors.

maybe also add a TODO to figure out if we are supposed to do anything useful with said metadata...

lld/test/MachO/ignore-symbols.s
6–8 ↗(On Diff #366197)

we need to test a few more things:

  1. that we discard __LLVM sections entirely, just like ld64 (you can use llvm-objdump --section-headers)
  2. when an _llvm.foo symbol is not under an __LLVM section, a duplicate symbol error is indeed raised

(test should be retitled too, something like discard-llvm-sections.s)

11–17 ↗(On Diff #366197)

see ld64's LLVMBitcode class :)

oontvoo added inline comments.Aug 13 2021, 9:57 PM
lld/test/MachO/ignore-symbols.s
11–17 ↗(On Diff #366197)

Ah, I see. Thanks!

thevinster marked 3 inline comments as done.Aug 16 2021, 9:46 AM

Address feedback

int3 accepted this revision.Aug 16 2021, 10:26 AM

lgtm

lld/test/MachO/discard-llvm-sections.s
7

nit

19

looks like the windows test is failing as the address is slightly different there. We should probably figure out why at some point, but since it's not really important to this test we can just match any hex value

This revision is now accepted and ready to land.Aug 16 2021, 10:26 AM
thevinster marked 2 inline comments as done.Aug 16 2021, 11:46 AM

Fix minor nits on tests

thevinster edited the summary of this revision. (Show Details)Aug 16 2021, 12:39 PM
int3 added inline comments.Aug 16 2021, 2:49 PM
lld/MachO/InputFiles.cpp
283–284

I realized that we are now constructing isec here redundantly whenever we have an __LLVM section. Can you fix things so that we only construct the isec when it actually gets used?

thevinster marked an inline comment as done.
thevinster added inline comments.
lld/MachO/InputFiles.cpp
283–284

Created follow up - D108167

thevinster marked an inline comment as done.Aug 16 2021, 3:24 PM
MaskRay added inline comments.
lld/test/MachO/discard-llvm-sections.s
26

The convention is not to add a prefix before error: so I dropped it in f74b70ef57fd038e9e6a781ef5cc72bb9734abe4