[PATCH] D33251: [lld][ELF]Add option to make .dynamic read only
Jake Ehrlich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 16:28:28 PDT 2017
jakehehrlich updated this revision to Diff 100329.
jakehehrlich added a comment.
I made the changes Rui recommended.
Repository:
rL LLVM
https://reviews.llvm.org/D33251
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/SyntheticSections.cpp
test/ELF/rodynamic.s
Index: test/ELF/rodynamic.s
===================================================================
--- /dev/null
+++ test/ELF/rodynamic.s
@@ -0,0 +1,13 @@
+# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
+# RUN: ld.lld -shared -z rodynamic %t.o -o %t.so
+# RUN: llvm-readobj -sections %t.so | FileCheck %s
+
+.globl _start
+_start:
+
+# CHECK: Section {
+# CHECK: Name: .dynamic
+# CHECK-NEXT: Type: SHT_DYNAMIC
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: ]
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1005,10 +1005,11 @@
".dynamic") {
this->Entsize = ELFT::Is64Bits ? 16 : 8;
- // .dynamic section is not writable on MIPS.
+ // .dynamic section is not writable on MIPS and on Fuchsia OS
+ // which passes -z rodynamic.
// See "Special Section" in Chapter 4 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
- if (Config->EMachine == EM_MIPS)
+ if (Config->EMachine == EM_MIPS || Config->ZReadOnlyDynamic)
this->Flags = SHF_ALLOC;
addEntries();
@@ -1053,7 +1054,14 @@
if (DtFlags1)
add({DT_FLAGS_1, DtFlags1});
- if (!Config->Shared && !Config->Relocatable)
+ // DT_DEBUG is a pointer to debug informaion used by debuggers at runtime.
+ // We need it for each process, so we don't write it for DSOs.
+ // The loader writes the pointer into this entry.
+ // DT_DEBUG is the only .dynamic entry that needs to be written to.
+ // Some systems (like Fuchsia OS) provide other means to give the debugger
+ // this information. Such systems may choose make .dynamic read-only.
+ // If the target is such a system (used -z rodynamic) don't write DT_DEBUG.
+ if (!Config->Shared && !Config->Relocatable && !Config->ZReadOnlyDynamic)
add({DT_DEBUG, (uint64_t)0});
}
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -687,6 +687,7 @@
Config->ZNodlopen = hasZOption(Args, "nodlopen");
Config->ZNow = hasZOption(Args, "now");
Config->ZOrigin = hasZOption(Args, "origin");
+ Config->ZReadOnlyDynamic = hasZOption(Args, "rodynamic");
Config->ZRelro = !hasZOption(Args, "norelro");
Config->ZStackSize = getZOptionValue(Args, "stack-size", 0);
Config->ZText = !hasZOption(Args, "notext");
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -144,6 +144,7 @@
bool ZNodlopen;
bool ZNow;
bool ZOrigin;
+ bool ZReadOnlyDynamic;
bool ZRelro;
bool ZText;
bool ExitEarly;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33251.100329.patch
Type: text/x-patch
Size: 2733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/defe28e5/attachment.bin>
More information about the llvm-commits
mailing list