[lld] r293519 - ELF: Align RELRO to the target page size rather than the max page size.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 10:20:07 PST 2017

Author: pcc
Date: Mon Jan 30 12:20:07 2017
New Revision: 293519

URL: http://llvm.org/viewvc/llvm-project?rev=293519&view=rev
ELF: Align RELRO to the target page size rather than the max page size.

If no bss sections appear after the relro segment, the loader will round
the r/w segment size to the target's page size. Align the relro size in the
same way to ensure that it does not extend past the end of the program's
own memory region.

Differential Revision: https://reviews.llvm.org/D29242


Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=293519&r1=293518&r2=293519&view=diff
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Jan 30 12:20:07 2017
@@ -1498,7 +1498,7 @@ template <class ELFT> void Writer<ELFT>:
       // The glibc dynamic loader rounds the size down, so we need to round up
       // to protect the last page. This is a no-op on FreeBSD which always
       // rounds up.
-      P.p_memsz = alignTo(P.p_memsz, Config->MaxPageSize);
+      P.p_memsz = alignTo(P.p_memsz, Target->PageSize);
     // The TLS pointer goes after PT_TLS. At least glibc will align it,

Added: lld/trunk/test/ELF/aarch64-relro.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-relro.s?rev=293519&view=auto
--- lld/trunk/test/ELF/aarch64-relro.s (added)
+++ lld/trunk/test/ELF/aarch64-relro.s Mon Jan 30 12:20:07 2017
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
+# RUN: ld.lld %t -o %t2
+# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
+# CHECK:      Type: PT_GNU_RELRO
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: VirtualAddress:
+# CHECK-NEXT: PhysicalAddress:
+# CHECK-NEXT: FileSize:
+# CHECK-NEXT: MemSize: 4096
+.section .data.rel.ro,"aw",%progbits
+.byte 1

More information about the llvm-commits mailing list