This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Don't load dylibs more than once
ClosedPublic

Authored by int3 on Dec 9 2020, 10:36 PM.

Details

Reviewers
thakis
Group Reviewers
Restricted Project
Commits
rG76c36c11a9c6: [lld-macho] Don't load dylibs more than once
Summary

Also remove DylibFile::reexported since it's unused.

Fixes llvm.org/PR48393.

Diff Detail

Event Timeline

int3 requested review of this revision.Dec 9 2020, 10:36 PM
int3 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2020, 10:36 PM
int3 planned changes to this revision.Dec 9 2020, 10:39 PM
int3 updated this revision to Diff 310767.Dec 9 2020, 10:46 PM
int3 edited the summary of this revision. (Show Details)

update

thakis accepted this revision.Dec 10 2020, 5:46 AM
thakis added a subscriber: thakis.

Nice! Fixes PR48393 :)

This revision is now accepted and ready to land.Dec 10 2020, 5:46 AM

I guess you could add a test to test/MachO/lc-linker-command.s too. It'll pass, it uses the same codepath, but it's a different way to add -framework flags so maybe it's worth testing.

smeenai added inline comments.
lld/MachO/DriverUtils.cpp
182

StringSet copies all the strings you add to it. I don't think that's a huge deal for this use case, but just something to keep in mind if this ever starts showing up in profiles.

(A SmallSet of StringRef would avoid the copying, but you'd rehash all the strings whenever you grew the set. A SmallSet of CachedHashStringRef would avoid both the copying and the rehashing, but it feels kinda overkill?)

int3 updated this revision to Diff 311044.Dec 10 2020, 3:54 PM
int3 marked an inline comment as done.

test LC_LINKER_OPTION, use CachedHashStringRef

lld/MachO/DriverUtils.cpp
182

I don't know if the set will be small... libSystem alone re-exports 67 dylibs. But a DenseSet of CachedHashStringRef seems easy enough :)

int3 edited the summary of this revision. (Show Details)Dec 10 2020, 3:55 PM
This revision was landed with ongoing or failed builds.Dec 10 2020, 3:58 PM
This revision was automatically updated to reflect the committed changes.

Now that I look at PR48393 again, this gets -framework CoreFoundation -weak_framework CoreFoundation -framework CoreFoundation wrong: CoreFoundation should be linked weakly in that case, but with this patch I think it doesn't. (Sorry for only noticing after you committed.)

int3 added a comment.Dec 10 2020, 4:43 PM

Ah good catch. I'll put up a diff for that later