diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-04 18:56:15 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-04 18:56:15 +0000 |
| commit | 7b5088b3b267230a4fad4a7400f8ff47e0181d9b (patch) | |
| tree | 62884de66fa1585619eb73308de2b26d30bdce82 | |
| parent | ae7b1c43ee15f40cb6df0166c68b7c7f6c94d653 (diff) | |
| download | bcm5719-llvm-7b5088b3b267230a4fad4a7400f8ff47e0181d9b.tar.gz bcm5719-llvm-7b5088b3b267230a4fad4a7400f8ff47e0181d9b.zip | |
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
llvm-svn: 290986
| -rw-r--r-- | lld/ELF/Writer.cpp | 7 | ||||
| -rw-r--r-- | lld/test/ELF/basic-mips.s | 2 | ||||
| -rw-r--r-- | lld/test/ELF/basic-ppc.s | 2 |
3 files changed, 8 insertions, 3 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 80a636c26ec..154de8cf6d1 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1444,8 +1444,13 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() { } 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. diff --git a/lld/test/ELF/basic-mips.s b/lld/test/ELF/basic-mips.s index dc640edae9f..84a7663675f 100644 --- a/lld/test/ELF/basic-mips.s +++ b/lld/test/ELF/basic-mips.s @@ -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: ] diff --git a/lld/test/ELF/basic-ppc.s b/lld/test/ELF/basic-ppc.s index c0f28bd48c4..e08c7a32eb7 100644 --- a/lld/test/ELF/basic-ppc.s +++ b/lld/test/ELF/basic-ppc.s @@ -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: ] |

