diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -548,20 +548,19 @@ // TODO(compnerd) see if we can generate this case list via XMACROS config->platform.kind = - llvm::StringSwitch(lowerDash(platformStr)) - .Cases("macos", "1", llvm::MachO::PlatformKind::macOS) - .Cases("ios", "2", llvm::MachO::PlatformKind::iOS) - .Cases("tvos", "3", llvm::MachO::PlatformKind::tvOS) - .Cases("watchos", "4", llvm::MachO::PlatformKind::watchOS) - .Cases("bridgeos", "5", llvm::MachO::PlatformKind::bridgeOS) - .Cases("mac-catalyst", "6", llvm::MachO::PlatformKind::macCatalyst) - .Cases("ios-simulator", "7", llvm::MachO::PlatformKind::iOSSimulator) - .Cases("tvos-simulator", "8", - llvm::MachO::PlatformKind::tvOSSimulator) - .Cases("watchos-simulator", "9", - llvm::MachO::PlatformKind::watchOSSimulator) - .Default(llvm::MachO::PlatformKind::unknown); - if (config->platform.kind == llvm::MachO::PlatformKind::unknown) + StringSwitch(lowerDash(platformStr)) + .Cases("macos", "1", PlatformKind::macOS) + .Cases("ios", "2", PlatformKind::iOS) + .Cases("tvos", "3", PlatformKind::tvOS) + .Cases("watchos", "4", PlatformKind::watchOS) + .Cases("bridgeos", "5", PlatformKind::bridgeOS) + .Cases("mac-catalyst", "6", PlatformKind::macCatalyst) + .Cases("ios-simulator", "7", PlatformKind::iOSSimulator) + .Cases("tvos-simulator", "8", PlatformKind::tvOSSimulator) + .Cases("watchos-simulator", "9", PlatformKind::watchOSSimulator) + .Cases("driverkit", "10", PlatformKind::driverKit) + .Default(PlatformKind::unknown); + if (config->platform.kind == PlatformKind::unknown) error(Twine("malformed platform: ") + platformStr); // TODO: check validity of version strings, which varies by platform // NOTE: ld64 accepts version strings with 5 components @@ -637,10 +636,14 @@ // to PIE from 10.7, arm64 should always be PIE, etc assert(config->arch == AK_x86_64 || config->arch == AK_x86_64h); - if (config->platform.kind == MachO::PlatformKind::macOS && + PlatformKind kind = config->platform.kind; + if (kind == PlatformKind::macOS && config->platform.minimum >= VersionTuple(10, 6)) return true; + if (kind == PlatformKind::iOSSimulator || kind == PlatformKind::driverKit) + return true; + return args.hasArg(OPT_pie); } diff --git a/lld/test/MachO/x86-64-reloc-unsigned.s b/lld/test/MachO/x86-64-reloc-unsigned.s --- a/lld/test/MachO/x86-64-reloc-unsigned.s +++ b/lld/test/MachO/x86-64-reloc-unsigned.s @@ -14,6 +14,10 @@ # RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE # RUN: %lld -platform_version macos 10.5.0 11.0 -o %t-no-pie %t.o # RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE +# RUN: %lld -platform_version ios-simulator 11.0.0 14.2 -o %t-pie %t.o +# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE +# RUN: %lld -platform_version driverkit 19.0 20.0 -o %t-pie %t.o +# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE # CHECK: Contents of section __DATA,foo: # CHECK-NEXT: 100001000 08100000 01000000