[PATCH] D92362: [lld-macho] Extend PIE option handling
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 1 14:36:18 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b3eecd22ab2: [lld-macho] Extend PIE option handling (authored by int3).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92362/new/
https://reviews.llvm.org/D92362
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
@@ -3,8 +3,17 @@
# RUN: %lld -o %t %t.o
# RUN: llvm-objdump --macho --rebase --full-contents %t | FileCheck %s
-# RUN: %lld -pie -o %t-pie %t.o
+# RUN: %lld -fatal_warnings -pie -o %t-pie %t.o
# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE
+# RUN: %lld -fatal_warnings -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 -fatal_warnings -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
# CHECK: Contents of section __DATA,foo:
# CHECK-NEXT: 100001000 08100000 01000000
@@ -21,6 +30,10 @@
# PIE-DAG: __DATA bar 0x[[#ADDR + 12]] pointer
# PIE-DAG: __DATA baz 0x[[#ADDR + 20]] pointer
+# NO-PIE: Rebase table:
+# NO-PIE-NEXT: segment section address type
+# NO-PIE-EMPTY:
+
.globl _main, _foo, _bar
.section __DATA,foo
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -315,11 +315,9 @@
def pie : Flag<["-"], "pie">,
HelpText<"Build a position independent executable (default for macOS 10.7 and later)">,
- Flags<[HelpHidden]>,
Group<grp_main>;
def no_pie : Flag<["-"], "no_pie">,
HelpText<"Do not build a position independent executable (default for macOS 10.6 and earlier)">,
- Flags<[HelpHidden]>,
Group<grp_main>;
def pagezero_size : Separate<["-"], "pagezero_size">,
MetaVarName<"<size>">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -555,6 +555,21 @@
return getenv("LLD_REPRODUCE");
}
+static bool isPie(opt::InputArgList &args) {
+ if (config->outputType != MH_EXECUTE || args.hasArg(OPT_no_pie))
+ return false;
+
+ // TODO: add logic here as we support more archs. E.g. i386 should default
+ // 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 &&
+ config->platform.minimum >= VersionTuple(10, 6))
+ return true;
+
+ return args.hasArg(OPT_pie);
+}
+
bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
raw_ostream &stdoutOS, raw_ostream &stderrOS) {
lld::stdoutOS = &stdoutOS;
@@ -690,8 +705,7 @@
}
config->isPic = config->outputType == MH_DYLIB ||
- config->outputType == MH_BUNDLE ||
- (config->outputType == MH_EXECUTE && args.hasArg(OPT_pie));
+ config->outputType == MH_BUNDLE || isPie(args);
// Now that all dylibs have been loaded, search for those that should be
// re-exported.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92362.308776.patch
Type: text/x-patch
Size: 3364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201201/0be5088d/attachment.bin>
More information about the llvm-commits
mailing list