[PATCH] D80872: [ELF] Set DF_1_PIE for -pie
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 30 11:07:34 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson, psmith, ruiu.
Herald added subscribers: llvm-commits, fedor.sergeev, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
DF_1_PIE originated from Solaris.
GNU ld since
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5fe2850dd96483f176858fd75c098313d5b20bc2
sets the flag on non-Solaris platforms.
It can help distinguish PIE from ET_DYN.
eu-classify from elfutils uses this to recognize PIE (https://sourceware.org/git/?p=elfutils.git;a=commit;h=3f489b5c7c78df6d52f8982f79c36e9a220e8951)
glibc uses this flag to reject dlopen'ing a PIE (https://sourceware.org/bugzilla/show_bug.cgi?id=24323)
If this looks good, I'll fix then 10+ tests.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80872
Files:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/pie.s
Index: lld/test/ELF/pie.s
===================================================================
--- lld/test/ELF/pie.s
+++ lld/test/ELF/pie.s
@@ -8,11 +8,11 @@
## Check -pie.
# RUN: ld.lld -pie %t1.o -o %t
-# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s
+# RUN: llvm-readobj --file-headers --sections -l -d --symbols -r %t | FileCheck %s
## Test --pic-executable alias
# RUN: ld.lld --pic-executable %t1.o -o %t
-# RUN: llvm-readobj --file-headers --sections -l --symbols -r %t | FileCheck %s
+# RUN: llvm-readobj --file-headers --sections -l -d --symbols -r %t | FileCheck %s
# CHECK: ElfHeader {
# CHECK-NEXT: Ident {
@@ -47,6 +47,9 @@
# CHECK: Type: PT_DYNAMIC
+# CHECK: DynamicSection [
+# CHECK: 0x000000006FFFFFFB FLAGS_1 PIE
+
## Check -nopie
# RUN: ld.lld -no-pie %t1.o -o %t2
# RUN: llvm-readobj --file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -1317,6 +1317,8 @@
dtFlags1 |= DF_1_NODELETE;
if (config->zNodlopen)
dtFlags1 |= DF_1_NOOPEN;
+ if (config->pie)
+ dtFlags1 |= DF_1_PIE;
if (config->zNow) {
dtFlags |= DF_BIND_NOW;
dtFlags1 |= DF_1_NOW;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80872.267464.patch
Type: text/x-patch
Size: 1349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200530/11bc40b9/attachment.bin>
More information about the llvm-commits
mailing list