[lld] r290986 - ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 4 10:56:15 PST 2017
Author: pcc
Date: Wed Jan 4 12:56:15 2017
New Revision: 290986
URL: http://llvm.org/viewvc/llvm-project?rev=290986&view=rev
Log:
ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.
The glibc dynamic loader rounds the size down, so without this the loader
will fail to change the memory protection for the last page.
Differential Revision: https://reviews.llvm.org/D28267
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/basic-mips.s
lld/trunk/test/ELF/basic-ppc.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=290986&r1=290985&r2=290986&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jan 4 12:56:15 2017
@@ -1444,8 +1444,13 @@ template <class ELFT> void Writer<ELFT>:
}
if (P.p_type == PT_LOAD)
P.p_align = Config->MaxPageSize;
- else if (P.p_type == PT_GNU_RELRO)
+ else if (P.p_type == PT_GNU_RELRO) {
P.p_align = 1;
+ // 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);
+ }
// The TLS pointer goes after PT_TLS. At least glibc will align it,
// so round up the size to make sure the offsets are correct.
Modified: lld/trunk/test/ELF/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=290986&r1=290985&r2=290986&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-mips.s (original)
+++ lld/trunk/test/ELF/basic-mips.s Wed Jan 4 12:56:15 2017
@@ -297,7 +297,7 @@ __start:
# CHECK-NEXT: VirtualAddress: 0x30000
# CHECK-NEXT: PhysicalAddress: 0x30000
# CHECK-NEXT: FileSize: 8
-# CHECK-NEXT: MemSize: 8
+# CHECK-NEXT: MemSize: 65536
# CHECK-NEXT: Flags [ (0x4)
# CHECK-NEXT: PF_R (0x4)
# CHECK-NEXT: ]
Modified: lld/trunk/test/ELF/basic-ppc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-ppc.s?rev=290986&r1=290985&r2=290986&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-ppc.s (original)
+++ lld/trunk/test/ELF/basic-ppc.s Wed Jan 4 12:56:15 2017
@@ -295,7 +295,7 @@
// CHECK-NEXT: VirtualAddress: 0x2000
// CHECK-NEXT: PhysicalAddress: 0x2000
// CHECK-NEXT: FileSize: 48
-// CHECK-NEXT: MemSize: 48
+// CHECK-NEXT: MemSize: 4096
// CHECK-NEXT: Flags [ (0x4)
// CHECK-NEXT: PF_R (0x4)
// CHECK-NEXT: ]
More information about the llvm-commits
mailing list