[PATCH] D138884: [lld-macho] Reject -no_pie for unsupported archs

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 28 17:46:42 PST 2022


keith created this revision.
Herald added a subscriber: kristof.beyls.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

ld64 rejects `-no_pie` when targeting arm64, this mirrors that behavior.
Newer versions of ld64 also reject it based on minimum OS versions, but
that logic isn't in an open source dump yet so it isn't implemented
here.

Fixes https://github.com/llvm/llvm-project/issues/59115


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138884

Files:
  lld/MachO/Driver.cpp
  lld/test/MachO/no-pie.s


Index: lld/test/MachO/no-pie.s
===================================================================
--- /dev/null
+++ lld/test/MachO/no-pie.s
@@ -0,0 +1,15 @@
+# REQUIRES: aarch64
+
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.arm64.o
+# RUN: llvm-mc -filetype=obj -triple=arm64e-apple-darwin %s -o %t.arm64e.o
+# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %s -o %t.arm64_32.o
+
+# RUN: not %lld -arch arm64 -lSystem -no_pie -o %t %t.arm64.o 2>&1 | FileCheck %s
+# RUN: not %lld -arch arm64e -lSystem -no_pie -o %t %t.arm64e.o 2>&1 | FileCheck %s
+# RUN: not %lld-watchos -arch arm64_32 -lSystem -no_pie -o %t %t.arm64_32.o 2>&1 | FileCheck %s
+
+# CHECK: error: -no_pie ignored for arm64
+
+.globl _main
+_main:
+  ret
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -931,6 +931,11 @@
   }
 }
 
+static bool supportsNoPie() {
+  return !(config->arch() == AK_arm64 || config->arch() == AK_arm64e ||
+           config->arch() == AK_arm64_32);
+}
+
 static bool dataConstDefault(const InputArgList &args) {
   static const std::array<std::pair<PlatformType, VersionTuple>, 5> minVersion =
       {{{PLATFORM_MACOS, VersionTuple(10, 15)},
@@ -947,7 +952,7 @@
 
   switch (config->outputType) {
   case MH_EXECUTE:
-    return !args.hasArg(OPT_no_pie);
+    return !(args.hasArg(OPT_no_pie) && supportsNoPie());
   case MH_BUNDLE:
     // FIXME: return false when -final_name ...
     // has prefix "/System/Library/UserEventPlugins/"
@@ -1425,10 +1430,15 @@
     }
   }
 
+  bool pie = args.hasFlag(OPT_pie, OPT_no_pie, true);
+  if (!supportsNoPie() && !pie) {
+    warn("-no_pie ignored for arm64");
+    pie = true;
+  }
+
   config->isPic = config->outputType == MH_DYLIB ||
                   config->outputType == MH_BUNDLE ||
-                  (config->outputType == MH_EXECUTE &&
-                   args.hasFlag(OPT_pie, OPT_no_pie, true));
+                  (config->outputType == MH_EXECUTE && pie);
 
   // Must be set before any InputSections and Symbols are created.
   config->deadStrip = args.hasArg(OPT_dead_strip);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138884.478429.patch
Type: text/x-patch
Size: 2170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221129/24352557/attachment-0001.bin>


More information about the llvm-commits mailing list