[lld] r284234 - [ELF] - Added support of PT_OPENBSD_RANDOMIZE
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 06:02:23 PDT 2016
Author: grimar
Date: Fri Oct 14 08:02:22 2016
New Revision: 284234
URL: http://llvm.org/viewvc/llvm-project?rev=284234&view=rev
Log:
[ELF] - Added support of PT_OPENBSD_RANDOMIZE
This is 30646.
PT_OPENBSD_RANDOMIZE
The array element specifies the location and size of a part of the memory image of the program that must be filled with random data before any code in the object is executed. The memory region specified by a segment of this type may overlap the region specified by a PT_GNU_RELRO segment, in which case the intersection will be filled with random data before being marked read-only.
Reference links:
http://man.openbsd.org/OpenBSD-current/man5/elf.5
https://github.com/openbsd/src/commit/c494713c450d98da3f2e1451ee8c7fb675a7c461
Differential revision: https://reviews.llvm.org/D25469
Added:
lld/trunk/test/ELF/linkerscript/openbsd-randomize.s
lld/trunk/test/ELF/openbsd-randomize.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=284234&r1=284233&r2=284234&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Oct 14 08:02:22 2016
@@ -1720,6 +1720,7 @@ unsigned ScriptParser::readPhdrType() {
.Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME)
.Case("PT_GNU_STACK", PT_GNU_STACK)
.Case("PT_GNU_RELRO", PT_GNU_RELRO)
+ .Case("PT_OPENBSD_RANDOMIZE", PT_OPENBSD_RANDOMIZE)
.Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED)
.Default(-1);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=284234&r1=284233&r2=284234&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 14 08:02:22 2016
@@ -1097,6 +1097,14 @@ std::vector<PhdrEntry<ELFT>> Writer<ELFT
Hdr.add(Out<ELFT>::EhFrameHdr);
}
+ // PT_OPENBSD_RANDOMIZE specifies the location and size of a part of the
+ // memory image of the program that must be filled with random data before any
+ // code in the object is executed.
+ if (OutputSectionBase<ELFT> *Sec = findSection(".openbsd.randomdata")) {
+ Phdr &Hdr = *AddHdr(PT_OPENBSD_RANDOMIZE, Sec->getPhdrFlags());
+ Hdr.add(Sec);
+ }
+
// PT_ARM_EXIDX is the ARM EHABI equivalent of PT_GNU_EH_FRAME
if (ARMExidx.First)
Ret.push_back(std::move(ARMExidx));
Added: lld/trunk/test/ELF/linkerscript/openbsd-randomize.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/openbsd-randomize.s?rev=284234&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/openbsd-randomize.s (added)
+++ lld/trunk/test/ELF/linkerscript/openbsd-randomize.s Fri Oct 14 08:02:22 2016
@@ -0,0 +1,22 @@
+# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
+# RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; rand PT_OPENBSD_RANDOMIZE; } \
+# RUN: SECTIONS { . = SIZEOF_HEADERS; \
+# RUN: .openbsd.randomdata : { *(.openbsd.randomdata) } : rand }" > %t.script
+# RUN: ld.lld --script %t.script %t.o -o %t
+# RUN: llvm-readobj --program-headers -s %t | FileCheck %s
+
+# CHECK: ProgramHeader {
+# CHECK: Type: (0x65A3DBE6)
+# CHECK-NEXT: Offset: 0x94
+# CHECK-NEXT: VirtualAddress: 0x94
+# CHECK-NEXT: PhysicalAddress: 0x94
+# CHECK-NEXT: FileSize: 8
+# CHECK-NEXT: MemSize: 8
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 1
+# CHECK-NEXT: }
+
+.section .openbsd.randomdata, "a"
+.quad 0
Added: lld/trunk/test/ELF/openbsd-randomize.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/openbsd-randomize.s?rev=284234&view=auto
==============================================================================
--- lld/trunk/test/ELF/openbsd-randomize.s (added)
+++ lld/trunk/test/ELF/openbsd-randomize.s Fri Oct 14 08:02:22 2016
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+# RUN: ld.lld %t -o %t.out
+# RUN: llvm-readobj --program-headers %t.out | FileCheck %s
+
+# CHECK: ProgramHeader {
+# CHECK: Type: (0x65A3DBE6)
+# CHECK-NEXT: Offset: 0x158
+# CHECK-NEXT: VirtualAddress: 0x10158
+# CHECK-NEXT: PhysicalAddress: 0x10158
+# CHECK-NEXT: FileSize: 8
+# CHECK-NEXT: MemSize: 8
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 1
+# CHECK-NEXT: }
+
+.section .openbsd.randomdata, "a"
+.quad 0
More information about the llvm-commits
mailing list