This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver] add clang driver support for emitting macho files with two build version load commands
ClosedPublic

Authored by arphaman on Feb 2 2022, 4:38 PM.

Details

Summary

This patch extends clang driver to pass the right flags to the clang frontend, and ld64, so that they can emit macho files with two build version load commands. It adds a new -darwin-target-variant option which complements -target and also can be used to specify different target variants when multi-arch compilations are invoked with multiple -arch commands.

MachO uses two build version load commands to represent an object file / binary that is targeting both the macOS target,
and the Mac Catalyst target. At runtime, a dynamic library that supports both targets can be loaded from either a native
macOS or a Mac Catalyst app on a macOS system. We want to add support to this to upstream to LLVM to be able to build
compiler-rt for both targets, to finish the complete support for the Mac Catalyst platform, which is right now targetable
by upstream clang, but the compiler-rt bits aren't supported because of the lack of this multiple build version support.

Diff Detail

Event Timeline

arphaman created this revision.Feb 2 2022, 4:38 PM
arphaman requested review of this revision.Feb 2 2022, 4:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2022, 4:38 PM
arphaman edited the summary of this revision. (Show Details)Feb 2 2022, 4:40 PM
bc-lee added a subscriber: bc-lee.Feb 3 2022, 12:35 PM
This revision is now accepted and ready to land.Feb 8 2022, 9:57 AM
This revision was landed with ongoing or failed builds.Feb 14 2022, 12:27 PM
This revision was automatically updated to reflect the committed changes.
gulfem added a subscriber: gulfem.Feb 14 2022, 4:03 PM

The following two tests started failing in our bots:

Clang :: Driver/darwin-ld-platform-version-target-version.c
Clang :: Driver/darwin-zippered-target-version.c

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8822219707275734081/overview

The error message is as the following:

Script:
--
: 'RUN: at line 1';   touch /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o
: 'RUN: at line 3';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target x86_64-apple-ios13.1-macabi -darwin-target-variant x86_64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 5';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target x86_64-apple-macos10.14.3 -darwin-target-variant x86_64-apple-ios13.1-macabi -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=CHECK-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 8';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-ios13.1-macabi -darwin-target-variant arm64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_NEW /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 10';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-macos10.15 -darwin-target-variant arm64-apple-ios13.1-macabi  -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_NEW-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 12';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-ios13.1-macabi -darwin-target-variant arm64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=400 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_OLD /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 14';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-macos10.15 -darwin-target-variant arm64-apple-ios13.1-macabi -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=400 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_OLD-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
--
Exit Code: 1

Command Output (stderr):
--
/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c:29:15: error: ARM64_OLD: expected string not found in input
// ARM64_OLD: "-maccatalyst_version_min" "14.0.0" "-macosx_version_min" "11.0.0"
              ^
<stdin>:1:1: note: scanning from here
Fuchsia clang version 15.0.0 (https://llvm.googlesource.com/a/llvm-project cccef321096c20825fe8738045c1d91d3b9fd57d)
^
<stdin>:5:109: note: possible intended match here
 "/b/s/w/ir/x/w/staging/llvm_build/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "arm64" "-platform_version" "mac catalyst" "14.0.0" "13.1" "-platform_version" "macos" "11.0.0" "10.15" "-syslibroot" "/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk" "-o" "a.out" "/b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o" "-lSystem"
                                                                                                            ^

Input file: <stdin>
Check file: /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: Fuchsia clang version 15.0.0 (https://llvm.googlesource.com/a/llvm-project cccef321096c20825fe8738045c1d91d3b9fd57d) 
check:29'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
            2: Target: arm64-apple-ios13.1-macabi 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            3: Thread model: posix 
check:29'0     ~~~~~~~~~~~~~~~~~~~~
            4: InstalledDir: /b/s/w/ir/x/w/staging/llvm_build/bin 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5:  "/b/s/w/ir/x/w/staging/llvm_build/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "arm64" "-platform_version" "mac catalyst" "14.0.0" "13.1" "-platform_version" "macos" "11.0.0" "10.15" "-syslibroot" "/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk" "-o" "a.out" "/b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o" "-lSystem" 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:29'1                                                                                                                 ?                                                                                                                                                                                                                                                                                                                           possible intended match
>>>>>>

--

The following two tests started failing in our bots:

Clang :: Driver/darwin-ld-platform-version-target-version.c
Clang :: Driver/darwin-zippered-target-version.c

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8822219707275734081/overview

The error message is as the following:

Script:
--
: 'RUN: at line 1';   touch /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o
: 'RUN: at line 3';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target x86_64-apple-ios13.1-macabi -darwin-target-variant x86_64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 5';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target x86_64-apple-macos10.14.3 -darwin-target-variant x86_64-apple-ios13.1-macabi -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=CHECK-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 8';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-ios13.1-macabi -darwin-target-variant arm64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_NEW /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 10';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-macos10.15 -darwin-target-variant arm64-apple-ios13.1-macabi  -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=520 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_NEW-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 12';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-ios13.1-macabi -darwin-target-variant arm64-apple-macos10.15 -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=400 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_OLD /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
: 'RUN: at line 14';   /b/s/w/ir/x/w/staging/llvm_build/bin/clang -target arm64-apple-macos10.15 -darwin-target-variant arm64-apple-ios13.1-macabi -isysroot /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk -mlinker-version=400 -### /b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o 2>&1    | /b/s/w/ir/x/w/staging/llvm_build/bin/FileCheck --check-prefix=ARM64_OLD-INV /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c
--
Exit Code: 1

Command Output (stderr):
--
/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c:29:15: error: ARM64_OLD: expected string not found in input
// ARM64_OLD: "-maccatalyst_version_min" "14.0.0" "-macosx_version_min" "11.0.0"
              ^
<stdin>:1:1: note: scanning from here
Fuchsia clang version 15.0.0 (https://llvm.googlesource.com/a/llvm-project cccef321096c20825fe8738045c1d91d3b9fd57d)
^
<stdin>:5:109: note: possible intended match here
 "/b/s/w/ir/x/w/staging/llvm_build/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "arm64" "-platform_version" "mac catalyst" "14.0.0" "13.1" "-platform_version" "macos" "11.0.0" "10.15" "-syslibroot" "/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk" "-o" "a.out" "/b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o" "-lSystem"
                                                                                                            ^

Input file: <stdin>
Check file: /b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/darwin-ld-platform-version-target-version.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: Fuchsia clang version 15.0.0 (https://llvm.googlesource.com/a/llvm-project cccef321096c20825fe8738045c1d91d3b9fd57d) 
check:29'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
            2: Target: arm64-apple-ios13.1-macabi 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            3: Thread model: posix 
check:29'0     ~~~~~~~~~~~~~~~~~~~~
            4: InstalledDir: /b/s/w/ir/x/w/staging/llvm_build/bin 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5:  "/b/s/w/ir/x/w/staging/llvm_build/bin/ld64.lld" "-demangle" "-dynamic" "-arch" "arm64" "-platform_version" "mac catalyst" "14.0.0" "13.1" "-platform_version" "macos" "11.0.0" "10.15" "-syslibroot" "/b/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk" "-o" "a.out" "/b/s/w/ir/x/w/staging/llvm_build/tools/clang/test/Driver/Output/darwin-ld-platform-version-target-version.c.tmp.o" "-lSystem" 
check:29'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:29'1                                                                                                                 ?                                                                                                                                                                                                                                                                                                                           possible intended match
>>>>>>

--

Thanks, this should be fixed now with a commit I did earlier today to fix them:

commit 688622ff607ca1b15e76f9b4f6216f78dd22fab2