This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Warn that writing zippered outputs isn't implemented
ClosedPublic

Authored by thakis on Apr 20 2022, 9:56 AM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rG889847922dc6: [lld/mac] Warn that writing zippered outputs isn't implemented
Summary

A "zippered" dylib contains several LC_BUILD_VERSION load commands, usually
one each for "normal" macOS and one for macCatalyst.

These are usually created by passing something like

-shared -target arm64-apple-macos -darwin-target-variant arm64-apple-ios13.1-macabi

to clang, which turns it into

-platform_version macos 12.0.0 12.3 -platform_version "mac catalyst" 14.0.0 15.4

for the linker.

ld64.lld can read these files fine, but it can't write them. Before this
change, it would just silently use the last -platform_version flag and ignore
the rest.

This change adds a warning that writing zippered dylibs isn't implemented yet
instead.

Sadly, parts of ld64.lld's test suite relied on the previous
"silently use last flag" semantics for its test suite: %lld always expanded
to ld64.lld -platform_version macos 10.15 11.0 and tests that wanted a
different value passed a 2nd -platform_version flag later on. But this now
produces a warning if the platform passed to -platform_version is not macos.

There weren't very many cases of this, so move these to use %no-arg-lld and
manually pass -arch.

Diff Detail

Event Timeline

thakis created this revision.Apr 20 2022, 9:56 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
thakis requested review of this revision.Apr 20 2022, 9:56 AM

This started out very harmless, until I realized I had to rewrite basically all tests :/

(The alternative is to keep the "this means mac" semantics implicitly for %lld and add %lld-no-platform-version, but that seems worse in all aspects except that it's a bit less work short term.)

thakis added inline comments.Apr 20 2022, 10:01 AM
lld/MachO/InputFiles.cpp
119

(I ran rg -i zippered lld/Macho and was surprised there were 0 hits. I expected one here, so I'm adding this comment.)

Maybe it is easier if you only warn if multiple different platforms are specified? You can preserve the last one wins for the same platform.
Or even more specifically, the only supported configuration is macOS + macCatalyst and you can only toss out a warning if this configuration is used.

thakis planned changes to this revision.Apr 20 2022, 10:32 AM

Maybe it is easier if you only warn if multiple different platforms are specified? You can preserve the last one wins for the same platform.
Or even more specifically, the only supported configuration is macOS + macCatalyst and you can only toss out a warning if this configuration is used.

I think that doesn't change all that much: There are things like %lld -dylib -platform_version ios ..., so some of the cases do mix platforms. I suppose I could move those to %no-arg-lld and keep the current "%lld means mac" semantics. I'll do that for this change this it makes the change smaller. (I vaguely like if %lld was just lld, there was no %no-arg-lld, and the current thing was called %lld-mac, but after your suggestion it's really independent of this patch here, and I'm not sure I like it enough to warrant changing all the tests.)

Also, you're right, I have to handle multiple -platform_version flags for the same platform better. Currently this warns on 2 -platform_version macos flags, which is incorrect.

Thanks!

thakis updated this revision to Diff 424186.Apr 21 2022, 6:51 AM
thakis edited the summary of this revision. (Show Details)

Group -platform_version flags by platform and make last flag win for each platform.

(ld64 warns on multiple -platform_version flags for a single platform, but if we do that we're back in the "need to update all tests" land, so punting on that for now.)

int3 accepted this revision.Apr 21 2022, 7:44 AM
int3 added a subscriber: int3.

Nice!

lld/MachO/Driver.cpp
641–651

cover these with a test?

645

nit: seems more direct this way

This revision is now accepted and ready to land.Apr 21 2022, 7:44 AM
oontvoo added inline comments.
lld/MachO/Driver.cpp
649–650

Should we verify that this is indeed because of the zippered dylib expansion of arguments?
(This is now assuming that whenever two or more platform_version arguments are passed, it is because of the zippered dylib, but that might not always be the case, eg. users accidentally pass the args multiple times)
Warning "writing zippered outputs..." here would be a bit confusing.

thakis marked an inline comment as done.Apr 21 2022, 8:51 AM

Thanks!

lld/MachO/Driver.cpp
641–651

Sure, will do.

649–650

How would you verify this? If users typo this, they _will_ get zippered output once we implement support for that (and they do get that with ld64).

(If more more than 2 platform_version args are passed, they'll get the "must specify -platform_version at most twice" diag further up.)

thakis updated this revision to Diff 424217.Apr 21 2022, 8:57 AM

add test

thakis added inline comments.Apr 21 2022, 8:59 AM
lld/MachO/Driver.cpp
649–650

Oh, and passing the flag multiple times for the _same_ platform doesn't emit this warning:

% out/gn/bin/ld64.lld -dylib -arch arm64 -platform_version macos 12.0.0 12.3 -platform_version macos 12.0.0 12.3 foo.o
# ^ no diag
thakis updated this revision to Diff 424221.Apr 21 2022, 9:04 AM

better test

This revision was landed with ongoing or failed builds.Apr 21 2022, 9:06 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2022, 9:06 AM