diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -15,6 +15,7 @@ #include "llvm/Support/VersionTuple.h" #include "llvm/TextAPI/MachO/Architecture.h" #include "llvm/TextAPI/MachO/Platform.h" +#include "llvm/TextAPI/MachO/Target.h" #include @@ -82,6 +83,10 @@ llvm::DenseMap priorities; SectionRenameMap sectionRenameMap; SegmentRenameMap segmentRenameMap; + + llvm::MachO::Target target() const { + return llvm::MachO::Target(arch, platform.kind); + } }; // The symbol with the highest priority should be ordered first in the output diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -721,9 +721,9 @@ if (umbrella == nullptr) umbrella = this; - if (!interface.getArchitectures().has(config->arch)) { + if (!is_contained(interface.targets(), config->target())) { error(toString(this) + " is incompatible with " + - getArchitectureName(config->arch)); + std::string(config->target())); return; } @@ -764,8 +764,11 @@ const InterfaceFile *topLevel = interface.getParent() == nullptr ? &interface : interface.getParent(); - for (InterfaceFileRef intfRef : interface.reexportedLibraries()) - loadReexport(intfRef.getInstallName(), exportingFile, topLevel); + for (InterfaceFileRef intfRef : interface.reexportedLibraries()) { + auto targets = intfRef.targets(); + if (is_contained(targets, config->target())) + loadReexport(intfRef.getInstallName(), exportingFile, topLevel); + } } ArchiveFile::ArchiveFile(std::unique_ptr &&f) diff --git a/lld/test/MachO/Inputs/libStubLink.tbd b/lld/test/MachO/Inputs/libStubLink.tbd new file mode 100644 --- /dev/null +++ b/lld/test/MachO/Inputs/libStubLink.tbd @@ -0,0 +1,24 @@ +--- !tapi-tbd +tbd-version: 4 +targets: [ arm64-ios-simulator, arm64-ios ] +uuids: + - target: arm64-ios-simulator + value: 00000000-0000-0000-0000-000000000002 + - target: arm64-ios + value: 00000000-0000-0000-0000-000000000003 +install-name: '/usr/lib/libStubLink.dylib' +current-version: 1.0.0 +reexported-libraries: + - targets: [ arm64-ios-simulator ] + libraries: [ '/usr/lib/libArm64Sim.dylib' ] +--- !tapi-tbd +tbd-version: 4 +targets: [ arm64-ios-simulator ] +uuids: + - target: arm64-ios-simulator + value: 00000000-0000-0000-0000-000000000001 +install-name: '/usr/lib/libArm64Sim.dylib' +current-version: 1.0.0 +exports: + - targets: [ arm64-ios-simulator ] + symbols: [ _arm64_sim_only ] diff --git a/lld/test/MachO/invalid/Inputs/libincompatible.tbd b/lld/test/MachO/invalid/Inputs/libincompatible.tbd --- a/lld/test/MachO/invalid/Inputs/libincompatible.tbd +++ b/lld/test/MachO/invalid/Inputs/libincompatible.tbd @@ -7,3 +7,4 @@ exports: - archs: [ 'x86_64', 'arm64' ] symbols: [ ] +... diff --git a/lld/test/MachO/invalid/incompatible-arch-tapi.s b/lld/test/MachO/invalid/incompatible-arch-tapi.s deleted file mode 100644 --- a/lld/test/MachO/invalid/incompatible-arch-tapi.s +++ /dev/null @@ -1,10 +0,0 @@ -# REQUIRES: x86 -# RUN: rm -rf %t; split-file %s %t -# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macosx %t/main.s -o %t/main.o -# RUN: not %lld -arch x86_64 -lSystem %S/Inputs/libincompatible.tbd %t/main.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ARCH -# ARCH: error: {{.*}}libincompatible.tbd is incompatible with x86_64 - -#--- main.s -.globl _main -_main: - ret diff --git a/lld/test/MachO/invalid/incompatible-target-tapi.test b/lld/test/MachO/invalid/incompatible-target-tapi.test new file mode 100644 --- /dev/null +++ b/lld/test/MachO/invalid/incompatible-target-tapi.test @@ -0,0 +1,10 @@ +REQUIRES: x86, aarch64 +RUN: rm -rf %t; mkdir -p %t +RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-macosx -o %t/x86_64-test.o +RUN: echo "" | llvm-mc -filetype=obj -triple=arm64-apple-iossimulator -o %t/arm64-test.o +RUN: not %lld -dylib -arch x86_64 %S/Inputs/libincompatible.tbd %t/x86_64-test.o \ +RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=ARCH +RUN: not %lld -dylib -arch arm64 -platform_version ios-simulator 14.0 15.0 %t/arm64-test.o \ +RUN: %S/Inputs/libincompatible.tbd -o /dev/null 2>&1 | FileCheck %s --check-prefix=PLATFORM +ARCH: error: {{.*}}libincompatible.tbd is incompatible with x86_64 (macOS) +PLATFORM: error: {{.*}}libincompatible.tbd is incompatible with arm64 (iOS Simulator) diff --git a/lld/test/MachO/stub-link-by-arch.s b/lld/test/MachO/stub-link-by-arch.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/stub-link-by-arch.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# RUN: mkdir -p %t +# RUN: llvm-mc -filetype obj -triple arm64-apple-ios14.4 %s -o %t/arm64-ios.o +# RUN: not %lld -dylib -arch arm64 -platform_version ios 10 11 -o /dev/null \ +# RUN: -lSystem %S/Inputs/libStubLink.tbd %t/arm64-ios.o 2>&1 | FileCheck %s + +# RUN: llvm-mc -filetype obj -triple x86_64-apple-iossimulator14.4 %s -o %t/x86_64-sim.o +# RUN: not %lld -dylib -arch x86_64 -platform_version ios-simulator 10 11 -o /dev/null \ +# RUN: -lSystem %S/Inputs/libStubLink.tbd %t/x86_64-sim.o 2>&1 | FileCheck %s + +# RUN: llvm-mc -filetype obj -triple arm64-apple-iossimulator14.4 %s -o %t/arm64-sim.o +# RUN: %lld -dylib -arch arm64 -platform_version ios-simulator 10 11 -o \ +# RUN: /dev/null %S/Inputs/libStubLink.tbd %t/arm64-sim.o + +# CHECK: error: undefined symbol: _arm64_sim_only + +.data +.quad _arm64_sim_only