[PATCH] D138884: [lld-macho] Reject -no_pie for unsupported archs
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 29 11:13:24 PST 2022
keith updated this revision to Diff 478653.
keith marked an inline comment as done.
keith added a comment.
Add x86_64 example showing -no_pie isn't rejected in that case
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138884/new/
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,17 @@
+# REQUIRES: aarch64, x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.x86_64.o
+# 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: %lld -arch x86_64 -lSystem -no_pie -o %t %t.x86_64.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.478653.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221129/6af81f29/attachment.bin>
More information about the llvm-commits
mailing list