[lld] r288020 - [ELF] - Implemented -no-rosegment.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 02:05:21 PST 2016
Author: grimar
Date: Mon Nov 28 04:05:20 2016
New Revision: 288020
URL: http://llvm.org/viewvc/llvm-project?rev=288020&view=rev
Log:
[ELF] - Implemented -no-rosegment.
--no-rosegment: Do not put read-only non-executable sections in their own segment
Differential revision: https://reviews.llvm.org/D26889
Added:
lld/trunk/test/ELF/segments.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=288020&r1=288019&r2=288020&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Mon Nov 28 04:05:20 2016
@@ -120,6 +120,7 @@ struct Configuration {
bool Rela;
bool Relocatable;
bool SaveTemps;
+ bool SingleRoRx;
bool Shared;
bool Static = false;
bool SysvHash = true;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=288020&r1=288019&r2=288020&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Nov 28 04:05:20 2016
@@ -696,6 +696,12 @@ void LinkerDriver::createFiles(opt::Inpu
}
}
+ // -no-rosegment is used to avoid placing read only non-executable sections in
+ // their own segment. We do the same if SECTIONS command is present in linker
+ // script. See comment for computeFlags().
+ Config->SingleRoRx =
+ Args.hasArg(OPT_no_rosegment) || ScriptConfig->HasSections;
+
if (Files.empty() && ErrorCount == 0)
error("no input files");
}
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=288020&r1=288019&r2=288020&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Mon Nov 28 04:05:20 2016
@@ -147,6 +147,8 @@ def noinhibit_exec: F<"noinhibit-exec">,
def nopie: F<"nopie">, HelpText<"Do not create a position independent executable">;
+def no_rosegment: F<"no-rosegment">, HelpText<"Do not put read-only non-executable sections in their own segment">;
+
def no_undefined: F<"no-undefined">,
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=288020&r1=288019&r2=288020&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Nov 28 04:05:20 2016
@@ -1096,7 +1096,7 @@ template <class ELFT> static bool needsP
// cannot create a PT_LOAD there.
template <class ELFT>
static typename ELFT::uint computeFlags(typename ELFT::uint F) {
- if (ScriptConfig->HasSections && !(F & PF_W))
+ if (Config->SingleRoRx && !(F & PF_W))
return F | PF_X;
return F;
}
Added: lld/trunk/test/ELF/segments.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/segments.s?rev=288020&view=auto
==============================================================================
--- lld/trunk/test/ELF/segments.s (added)
+++ lld/trunk/test/ELF/segments.s Mon Nov 28 04:05:20 2016
@@ -0,0 +1,88 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t1
+# RUN: llvm-readobj --program-headers %t1 | FileCheck --check-prefix=ROSEGMENT %s
+
+# ROSEGMENT: ProgramHeader {
+# ROSEGMENT: Type: PT_LOAD
+# ROSEGMENT-NEXT: Offset: 0x0
+# ROSEGMENT-NEXT: VirtualAddress:
+# ROSEGMENT-NEXT: PhysicalAddress:
+# ROSEGMENT-NEXT: FileSize:
+# ROSEGMENT-NEXT: MemSize:
+# ROSEGMENT-NEXT: Flags [
+# ROSEGMENT-NEXT: PF_R
+# ROSEGMENT-NEXT: ]
+# ROSEGMENT-NEXT: Alignment: 4096
+# ROSEGMENT-NEXT: }
+# ROSEGMENT-NEXT: ProgramHeader {
+# ROSEGMENT-NEXT: Type: PT_LOAD
+# ROSEGMENT-NEXT: Offset: 0x1000
+# ROSEGMENT-NEXT: VirtualAddress:
+# ROSEGMENT-NEXT: PhysicalAddress:
+# ROSEGMENT-NEXT: FileSize:
+# ROSEGMENT-NEXT: MemSize:
+# ROSEGMENT-NEXT: Flags [
+# ROSEGMENT-NEXT: PF_R
+# ROSEGMENT-NEXT: PF_X
+# ROSEGMENT-NEXT: ]
+# ROSEGMENT-NEXT: Alignment: 4096
+# ROSEGMENT-NEXT: }
+# ROSEGMENT-NEXT: ProgramHeader {
+# ROSEGMENT-NEXT: Type: PT_LOAD
+# ROSEGMENT-NEXT: Offset: 0x2000
+# ROSEGMENT-NEXT: VirtualAddress:
+# ROSEGMENT-NEXT: PhysicalAddress:
+# ROSEGMENT-NEXT: FileSize: 1
+# ROSEGMENT-NEXT: MemSize: 1
+# ROSEGMENT-NEXT: Flags [
+# ROSEGMENT-NEXT: PF_R
+# ROSEGMENT-NEXT: PF_W
+# ROSEGMENT-NEXT: ]
+# ROSEGMENT-NEXT: Alignment: 4096
+# ROSEGMENT-NEXT: }
+
+# RUN: ld.lld -no-rosegment %t -o %t2
+# RUN: llvm-readobj --program-headers %t2 | FileCheck --check-prefix=NOROSEGMENT %s
+
+# NOROSEGMENT: ProgramHeader {
+# NOROSEGMENT: Type: PT_LOAD
+# NOROSEGMENT-NEXT: Offset: 0x0
+# NOROSEGMENT-NEXT: VirtualAddress:
+# NOROSEGMENT-NEXT: PhysicalAddress:
+# NOROSEGMENT-NEXT: FileSize:
+# NOROSEGMENT-NEXT: MemSize:
+# NOROSEGMENT-NEXT: Flags [
+# NOROSEGMENT-NEXT: PF_R
+# NOROSEGMENT-NEXT: PF_X
+# NOROSEGMENT-NEXT: ]
+# NOROSEGMENT-NEXT: Alignment: 4096
+# NOROSEGMENT-NEXT: }
+# NOROSEGMENT-NEXT: ProgramHeader {
+# NOROSEGMENT-NEXT: Type: PT_LOAD
+# NOROSEGMENT-NEXT: Offset: 0x1000
+# NOROSEGMENT-NEXT: VirtualAddress:
+# NOROSEGMENT-NEXT: PhysicalAddress:
+# NOROSEGMENT-NEXT: FileSize:
+# NOROSEGMENT-NEXT: MemSize:
+# NOROSEGMENT-NEXT: Flags [
+# NOROSEGMENT-NEXT: PF_R
+# NOROSEGMENT-NEXT: PF_W
+# NOROSEGMENT-NEXT: ]
+# NOROSEGMENT-NEXT: Alignment: 4096
+# NOROSEGMENT-NEXT: }
+# NOROSEGMENT-NEXT: ProgramHeader {
+# NOROSEGMENT-NEXT: Type: PT_GNU_STACK
+
+.global _start
+_start:
+ nop
+
+.section .ro,"a"
+nop
+
+.section .rw,"aw"
+nop
+
+.section .rx,"ax"
+nop
More information about the llvm-commits
mailing list