[PATCH] D101513: [lld-macho] Make everything PIE by default
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 28 23:38:47 PDT 2021
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a subscriber: dang.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Modern versions of macOS (>= 10.7) and in general all modern Mach-O
target archs want PIEs by default. ld64 defaults to PIE for iOS >= 4.3,
as well as for all versions of watchOS and simulators. Basically all the
platforms LLD is likely to target want PIE. So instead of cluttering LLD's
code with legacy version checks, I think it's simpler to just default to
PIE for everything.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101513
Files:
lld/MachO/Driver.cpp
lld/MachO/Options.td
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
@@ -7,16 +7,7 @@
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
# RUN: %lld -pie -no_pie -o %t-no-pie %t.o
# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
-# RUN: %lld -no_pie -pie -o %t-no-pie %t.o
-# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE
-
-# RUN: %lld -platform_version macos 10.6.0 11.0 -o %t-pie %t.o
-# 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: %lld -no_pie -pie -o %t-pie %t.o
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
# CHECK: Contents of section __DATA,foo:
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -370,10 +370,10 @@
def grp_main : OptionGroup<"main">, HelpText<"MAIN EXECUTABLE">;
def pie : Flag<["-"], "pie">,
- HelpText<"Build a position independent executable (default for macOS 10.7 and later)">,
+ HelpText<"Build a position independent executable (default)">,
Group<grp_main>;
def no_pie : Flag<["-"], "no_pie">,
- HelpText<"Do not build a position independent executable (default for macOS 10.6 and earlier)">,
+ HelpText<"Do not build a position independent executable">,
Group<grp_main>;
def pagezero_size : Separate<["-"], "pagezero_size">,
MetaVarName<"<size>">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -664,29 +664,6 @@
return getenv("LLD_REPRODUCE");
}
-static bool isPie(InputArgList &args) {
- if (config->outputType != MH_EXECUTE || args.hasArg(OPT_no_pie))
- return false;
- if (config->arch() == AK_arm64 || config->arch() == AK_arm64e ||
- config->arch() == AK_arm64_32)
- return true;
-
- // TODO: add logic here as we support more archs. E.g. i386 should default
- // to PIE from 10.7
- assert(config->arch() == AK_x86_64 || config->arch() == AK_x86_64h ||
- config->arch() == AK_arm64_32);
-
- PlatformKind kind = config->platformInfo.target.Platform;
- if (kind == PlatformKind::macOS &&
- config->platformInfo.minimum >= VersionTuple(10, 6))
- return true;
-
- if (kind == PlatformKind::iOSSimulator || kind == PlatformKind::driverKit)
- return true;
-
- return args.hasArg(OPT_pie);
-}
-
static void parseClangOption(StringRef opt, const Twine &msg) {
std::string err;
raw_string_ostream os(err);
@@ -1061,7 +1038,9 @@
createFiles(args);
config->isPic = config->outputType == MH_DYLIB ||
- config->outputType == MH_BUNDLE || isPie(args);
+ config->outputType == MH_BUNDLE ||
+ (config->outputType == MH_EXECUTE &&
+ args.hasFlag(OPT_pie, OPT_no_pie, true));
// Now that all dylibs have been loaded, search for those that should be
// re-exported.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101513.341412.patch
Type: text/x-patch
Size: 3557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210429/6476d87a/attachment.bin>
More information about the llvm-commits
mailing list