[PATCH] D93741: [lld-macho] Simulator & DriverKit executables should always be PIE

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 21:38:50 PST 2020


int3 updated this revision to Diff 313479.
int3 added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93741/new/

https://reviews.llvm.org/D93741

Files:
  lld/MachO/Driver.cpp
  lld/test/MachO/platform-version.s
  lld/test/MachO/x86-64-reloc-unsigned.s


Index: lld/test/MachO/x86-64-reloc-unsigned.s
===================================================================
--- lld/test/MachO/x86-64-reloc-unsigned.s
+++ 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
Index: lld/test/MachO/platform-version.s
===================================================================
--- lld/test/MachO/platform-version.s
+++ lld/test/MachO/platform-version.s
@@ -55,7 +55,7 @@
 # RUN:        -platform_version 0 1 5 \
 # RUN:     | FileCheck --check-prefix=FAIL-PLATFORM %s
 # RUN: not %lld -o %t %t.o 2>&1 \
-# RUN:        -platform_version 10 1 5 \
+# RUN:        -platform_version 11 1 5 \
 # RUN:     | FileCheck --check-prefix=FAIL-PLATFORM %s
 # FAIL-PLATFORM: malformed platform: {{.*}}
 # FAIL-PLATFORM-NOT: malformed {{minimum|sdk}} version: {{.*}}
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ 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<llvm::MachO::PlatformKind>(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<PlatformKind>(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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93741.313479.patch
Type: text/x-patch
Size: 4057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201223/fdc76485/attachment.bin>


More information about the llvm-commits mailing list