Skip to content

Commit 9d1140e

Browse files
committed
[lld-macho] Simulator & DriverKit executables should always be PIE
We didn't have support for parsing DriverKit in our `-platform` flag, so add that too. Also remove a bunch of unnecessary namespace prefixes. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D93741
1 parent e122a71 commit 9d1140e

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

lld/MachO/Driver.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,19 @@ static void handlePlatformVersion(const opt::Arg *arg) {
548548

549549
// TODO(compnerd) see if we can generate this case list via XMACROS
550550
config->platform.kind =
551-
llvm::StringSwitch<llvm::MachO::PlatformKind>(lowerDash(platformStr))
552-
.Cases("macos", "1", llvm::MachO::PlatformKind::macOS)
553-
.Cases("ios", "2", llvm::MachO::PlatformKind::iOS)
554-
.Cases("tvos", "3", llvm::MachO::PlatformKind::tvOS)
555-
.Cases("watchos", "4", llvm::MachO::PlatformKind::watchOS)
556-
.Cases("bridgeos", "5", llvm::MachO::PlatformKind::bridgeOS)
557-
.Cases("mac-catalyst", "6", llvm::MachO::PlatformKind::macCatalyst)
558-
.Cases("ios-simulator", "7", llvm::MachO::PlatformKind::iOSSimulator)
559-
.Cases("tvos-simulator", "8",
560-
llvm::MachO::PlatformKind::tvOSSimulator)
561-
.Cases("watchos-simulator", "9",
562-
llvm::MachO::PlatformKind::watchOSSimulator)
563-
.Default(llvm::MachO::PlatformKind::unknown);
564-
if (config->platform.kind == llvm::MachO::PlatformKind::unknown)
551+
StringSwitch<PlatformKind>(lowerDash(platformStr))
552+
.Cases("macos", "1", PlatformKind::macOS)
553+
.Cases("ios", "2", PlatformKind::iOS)
554+
.Cases("tvos", "3", PlatformKind::tvOS)
555+
.Cases("watchos", "4", PlatformKind::watchOS)
556+
.Cases("bridgeos", "5", PlatformKind::bridgeOS)
557+
.Cases("mac-catalyst", "6", PlatformKind::macCatalyst)
558+
.Cases("ios-simulator", "7", PlatformKind::iOSSimulator)
559+
.Cases("tvos-simulator", "8", PlatformKind::tvOSSimulator)
560+
.Cases("watchos-simulator", "9", PlatformKind::watchOSSimulator)
561+
.Cases("driverkit", "10", PlatformKind::driverKit)
562+
.Default(PlatformKind::unknown);
563+
if (config->platform.kind == PlatformKind::unknown)
565564
error(Twine("malformed platform: ") + platformStr);
566565
// TODO: check validity of version strings, which varies by platform
567566
// NOTE: ld64 accepts version strings with 5 components
@@ -637,10 +636,14 @@ static bool isPie(opt::InputArgList &args) {
637636
// to PIE from 10.7, arm64 should always be PIE, etc
638637
assert(config->arch == AK_x86_64 || config->arch == AK_x86_64h);
639638

640-
if (config->platform.kind == MachO::PlatformKind::macOS &&
639+
PlatformKind kind = config->platform.kind;
640+
if (kind == PlatformKind::macOS &&
641641
config->platform.minimum >= VersionTuple(10, 6))
642642
return true;
643643

644+
if (kind == PlatformKind::iOSSimulator || kind == PlatformKind::driverKit)
645+
return true;
646+
644647
return args.hasArg(OPT_pie);
645648
}
646649

lld/test/MachO/platform-version.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# RUN: -platform_version 0 1 5 \
5656
# RUN: | FileCheck --check-prefix=FAIL-PLATFORM %s
5757
# RUN: not %lld -o %t %t.o 2>&1 \
58-
# RUN: -platform_version 10 1 5 \
58+
# RUN: -platform_version 11 1 5 \
5959
# RUN: | FileCheck --check-prefix=FAIL-PLATFORM %s
6060
# FAIL-PLATFORM: malformed platform: {{.*}}
6161
# FAIL-PLATFORM-NOT: malformed {{minimum|sdk}} version: {{.*}}

lld/test/MachO/x86-64-reloc-unsigned.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
1515
# RUN: %lld -platform_version macos 10.5.0 11.0 -o %t-no-pie %t.o
1616
# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
17+
# RUN: %lld -platform_version ios-simulator 11.0.0 14.2 -o %t-pie %t.o
18+
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
19+
# RUN: %lld -platform_version driverkit 19.0 20.0 -o %t-pie %t.o
20+
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
1721

1822
# CHECK: Contents of section __DATA,foo:
1923
# CHECK-NEXT: 100001000 08100000 01000000

0 commit comments

Comments
 (0)