<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJztWOuP2jgQ_2vCFytWHkDgAx8oFGnVq_akver6beUkE3DXiSPb4fHf34wDLKz2qmp7urYqKIrHj3lk_JsZm1yXh9lCN1aWYJjbAKu0UnonmzWzsm4VsEKXwIJkEoyjWsiG10gEyTRIFkG0DKI5dfun7yYp8mnjWJAuPt19kC5IVr7lmyB9f1zk37JxjESicCKFWRcolRUbYYJkTv1tMHoXjJaojgXZu56L4S8YRqJz2oACYaHVWl3P08-A60zDPt3N21bJQjipm4-9tpMmrwHbRqpzMw3SS0XZ8mjxmXjxuf690HUrFTlNWlbJBvi_-GaInly1wm2wcRpfORm0KpRA3nDPdP4FCie3EBYsdGgfOLafjB_Hw1DgZ0AotY2HPAprUYhcsrBCjiIUpjiROxBPLJT2YI3WjtRdfL_F7mfa0DjlCUeJ2Mfdd9A4mlrCFpRuAd2_-lMJV2lT0_hHUdw_fObtcejFyoflh-dFccJjbsujCQ7qH2YBjXsLkJD3Dw9dS6jETmeJRzaF6hDZoayMqGGnzdPPZ-p59A-ZG2EOSK1O1lqGGOkjkoW6p_RXMDqvHIY4oehAQFWqJMwjaJ9YJaSyb4Ns1VkIUVS6RIEs_JsCKayEE-pxJ0yDmuy3AfmG2N8BsT0-7vMvixNtemgtMKUrLbAKPR6xxvmrvBfrYQ9F50Su4MRzsbyPBwTo2Ve-CF0OrHTXlN5xpwDqMa_K8ZBTfKRzBsZoQ8QP9HS__Urm-LYn_2K38FUHPWYcd3lJNfrbFpcHPz-laoWowhn8KHQj20m3OYYplXyMzQWFMoqhwuid4-P-yjOUQjCzoJhaNKVPJlD2omCPHvcHiJjkYa5g4ZY5zSwAat7q3ptn4a8mLu_nIMksW_ic4_f3q9nqbRv1Fx4j8Owhn3mWUIlOOb4v3Gnu7OGrLHhLe7e098unvVeD7_0WGiYrdsd0jWJw9rrk-8vA9x8jbgF0C6CfKoDeeHCgeiibl1Dvq3FfOZMVwZdH5-FSmJ0PBSrStIQqtLZ7LuimmtttKRNe4NHe37lZ3klV0gEeXc7Quey5QtOk86Hob6LN8TaJF1Is7cTnPFNNO0Kr_TgW1v_K2syLx7voRjrU2xk4hu7_eXIYlLO0nKZTMRCd22gzy4tQAQw6o2Yb51qLitF8fNaop8s5aqfPUdtTE7ZGk98IotZ2QCgepcMsG2xmMIFxPJzEIGCSjcosH8EIIMvyrJwWMIkHSuSg7Kz_32Lw_SrlLImSJIqTaRTFcTrhyXRSRekoyyGHKJ9GhGdEoOIkh2uzHpiZF5l3a0vBIa2zz5PCWrluAE4WOumU71AuHy2RQHhsNJJ0Q2SFQBdnPaiu0Dbwds68kf8A96btjw>53477</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lld][macho] lld can't link Mac Catalyst
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bc-lee
      </td>
    </tr>
</table>

<pre>
    Consider the following simple code (`main.m`),
```
#import <UIKit/UIKit.h>

int main(int argc, char* argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, nil);
    }
}
```

Compiling is fine.
```
$ /path/to/bin/clang -x objective-c -target x86_64-apple-ios14.0-macabi -fobjc-arc -fobjc-weak -isysroot /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -isystem /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/usr/include -iframework /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/System/Library/Frameworks -c main.m -o main.o
```

After applying lld, link fails.
```
$ /path/to/bin/clang -fuse-ld=lld -Wl,-fatal_warnings -target x86_64-apple-ios14.0-macabi -isysroot /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -isystem /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/usr/include -iframework /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/System/Library/Frameworks -Wl,-ObjC -Wl,-rpath,@loader_path/../Frameworks -Wl,-rpath,@executable_path/Frameworks main.o -framework UIKit -framework Foundation -o main
ld64.lld: error: /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/system/libcompiler_rt.tbd(/usr/lib/system/libcompiler_rt.dylib) is incompatible with x86_64 (macCatalyst)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

Xcode's Clang works.
```
$ /Applications/Xcode13.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Wl,-fatal_warnings -target x86_64-apple-ios14.0-macabi -isysroot /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -isystem /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/usr/include -iframework /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/System/Library/Frameworks -Wl,-ObjC -Wl,-rpath,@loader_path/../Frameworks -Wl,-rpath,@executable_path/Frameworks main.o -framework UIKit -framework Foundation -o main
```

Even if I omit `-fuse-ld=lld`, link fails.
```
$ /path/to/bin/clang -Wl,-fatal_warnings -target x86_64-apple-ios14.0-macabi -isysroot /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -isystem /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/usr/include -iframework /Applications/Xcode13.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/System/Library/Frameworks -Wl,-ObjC -Wl,-rpath,@loader_path/../Frameworks -Wl,-rpath,@executable_path/Frameworks main.o  -framework UIKit -framework Foundation -o main
ld: in /path/to/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a(absvdi2.c.o), building for Mac Catalyst, but linking in object file built for macOS, file '/path/to/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWFmP2zYQ_jXyCyFCh88HPXjtGFikwRbYBsnbgpJGNrOUKJCUj3_fGcr22ottEGyLJkVtCNLwmIPDb2ZI57o8ZAvdWFmCYW4DrNJK6Z1s1szKulXACl0CC5JpMI5qIRteIxEksyBZBNEyiObU7J--maTIp41jQbr4fP9RuiBZ-S_fBOmH4yT_lo1jJBKFEynMukCprNgIEyRzam-D0V0wWqI6Fkzuei6Gv2AYic5pAwqEhVZrdT1OPwOuMw37fD9vWyUL4aRuPvXaTpq8Bvw2Up0_syC9VDRZHi0-E6-W698LXbdSkdOkZZVsgP-Fb4boyVUr3AY_TuMrJ4NWhRLIG-6Zzr9B4eQWwoKFDu0Dx_bT8dN4GApcBoRS23jIo7AWhcglCyvkKEJhihO5A_HMQmkP1mjtSN3F-i02v9KGxilPOErENu6-g8bR0BK2oHQL6P7V70q4Spua-j-J4uHxK2-PXa9mPi4_vkyKEx5zWx5NcFD_NAuo31uAhHx4fOxaQiU2Oks8silUh8gOZWVEDTttnn89U8-9v8ncCHNAanWy1jLESB-RLNQ9pb-D0XnlMMQJRQcCqlIlYR5B-8wqIZV9H2SrzkKIotIlCmThFwqksBJOqKedMA1qsj8G5Bti_w-I7fHxkH9bnGjTQ2uBKV1pgVXo6Yg1zt_kvZgPey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