LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 49799 - LLD cannot link against iPhoneSimulator libSystem in Xcode 12 and newer
Summary: LLD cannot link against iPhoneSimulator libSystem in Xcode 12 and newer
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: MachO (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Jez Ng
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-31 20:39 PDT by Shoaib Meenai
Modified: 2021-04-20 18:02 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s): https://github.com/llvm/llvm-project/commit/7208bd4b320fac383552995dea41c55677e8f3f5


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shoaib Meenai 2021-03-31 20:39:47 PDT
$ cat null.s
.globl _main
_main:
        retq

$ llvm-mc -filetype obj -triple x86_64-apple-ios14.0.0-simulator \
    -o null.o null.s
$ ld64.lld -platform_version ios-simulator 14.0.0 14.0 -arch x86_64 \
    -o null null.o -lSystem -syslibroot \
    /Applications/Xcode_12.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
ld64.lld: error: /Applications/Xcode_12.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system/libsystem_kernel.tbd(/usr/lib/system/libsystem_kernel.dylib) is incompatible with x86_64 (iOS Simulator)
ld64.lld: error: /Applications/Xcode_12.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system/libsystem_platform.tbd(/usr/lib/system/libsystem_platform.dylib) is incompatible with x86_64 (iOS Simulator)
ld64.lld: error: /Applications/Xcode_12.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system/libsystem_pthread.tbd(/usr/lib/system/libsystem_pthread.dylib) is incompatible with x86_64 (iOS Simulator)

Repros with 12.4 and 12.5 as well (and I presume other 12.x versions).

The error message seems legit, as far as I can tell. If I look at the iPhoneSimulator libSystem.tbd, libsystem_kernel indeed doesn't have x86_64-ios-simulator in its targets list. However, it's re-exported by libsystem_sim_kernel_host, which does mark it as a re-export for the x86_64-ios-simulator target (potentially a bug?). libsystem_sim_kernel_host is re-exported by libsystem_sim_kernel, which is re-exported by libSystem, which is presumably how we end up with the error.

ld64 is able to handle this libSystem. Interestingly enough, even if I force a reference to __kernelrpc_mach_port_destroy_trap, which is not defined for x86_64-ios-simulator (but is defined for x86_64-macos), it's able to link. The link does fail if I reference ___aio_suspend, which is only defined for i386-macos. I don't know if ld64 is specifically treating ios-simulator and macos as equivalent, or if it's only looking at the architecture and not the platform in general.
Comment 1 Jez Ng 2021-04-20 15:38:23 PDT
> I don't know if ld64 is specifically treating ios-simulator and macos as equivalent, or if it's only looking at the architecture and not the platform in general.

I think it's only looking at the architecture. I changed the top-level libSystem.B.dylib's x86_64 target to use watchOS, maccatalyst etc in place of ios-simulator and ld did not complain at all...
Comment 2 Jez Ng 2021-04-20 15:56:14 PDT
Oh... I think ld64 actually just special-cases a bunch of libsystem dylibs.