[lld-macho] Reject -no_pie for unsupported archs
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 Differential Revision: https://reviews.llvm.org/D138884
This commit is contained in:
parent
b42cb2d601
commit
c702bf1400
|
@ -931,6 +931,11 @@ PlatformType macho::removeSimulator(PlatformType platform) {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ static bool dataConstDefault(const InputArgList &args) {
|
|||
|
||||
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 macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue