[PATCH] D125410: [ELF] Align the end of PT_GNU_RELRO to max-page-size instead of common-page-size
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 13:16:11 PDT 2022
MaskRay created this revision.
MaskRay added a reviewer: peter.smith.
Herald added subscribers: StephenFan, pengfei, kbarton, arichardson, nemanjai, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The resolution to GNU ld https://sourceware.org/bugzilla/show_bug.cgi?id=28824
(milestone: binutils 2.39) switched to max-page-size so that the last page can
be protected by RELRO (x86-64 has been updated as well on 2022-02-14).
Thanks to the two RW PT_LOAD scheme, switching to max-page-size does not change
file size for us. We used common-page-size just for some compatibility.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125410
Files:
lld/ELF/Writer.cpp
lld/test/ELF/aarch64-relro.s
lld/test/ELF/basic-ppc64.s
Index: lld/test/ELF/basic-ppc64.s
===================================================================
--- lld/test/ELF/basic-ppc64.s
+++ lld/test/ELF/basic-ppc64.s
@@ -336,7 +336,7 @@
// CHECK-NEXT: VirtualAddress: 0x20238
// CHECK-NEXT: PhysicalAddress: 0x20238
// CHECK-NEXT: FileSize: 96
-// CHECK-NEXT: MemSize: 3528
+// CHECK-NEXT: MemSize: 64968
// CHECK-NEXT: Flags [ (0x4)
// CHECK-NEXT: PF_R (0x4)
// CHECK-NEXT: ]
Index: lld/test/ELF/aarch64-relro.s
===================================================================
--- lld/test/ELF/aarch64-relro.s
+++ lld/test/ELF/aarch64-relro.s
@@ -8,7 +8,7 @@
# CHECK-NEXT: VirtualAddress: 0x220190
# CHECK-NEXT: PhysicalAddress:
# CHECK-NEXT: FileSize:
-# CHECK-NEXT: MemSize: 3696
+# CHECK-NEXT: MemSize: 65136
.section .data.rel.ro,"aw",%progbits
.byte 1
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2638,11 +2638,10 @@
if (p->p_type == PT_GNU_RELRO) {
p->p_align = 1;
- // musl/glibc ld.so 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_offset + p->p_memsz, config->commonPageSize) -
- p->p_offset;
+ // musl/glibc/FreeBSD ld.so rounds the size down, so we need to round up
+ // to protect the last page.
+ p->p_memsz =
+ alignTo(p->p_offset + p->p_memsz, config->maxPageSize) - p->p_offset;
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125410.428752.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220511/30164259/attachment.bin>
More information about the llvm-commits
mailing list