Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-05-12 21:03:12 +0300
committerFangrui Song <i@maskray.me>2022-05-12 21:03:12 +0300
commitebdb9d635a077274e38baa8584f5b0e631b4b1d3 (patch)
tree48ae88185cc7454eba9de4afd5e10bf6f6065bf0 /lld
parent9f732af583c0dba58847b753a87cc5432ec33f09 (diff)
[ELF] Align the end of PT_GNU_RELRO to max-page-size instead of common-page-size
We picked common-page-size to match GNU ld. Recently, the resolution to GNU ld https://sourceware.org/bugzilla/show_bug.cgi?id=28824 (milestone: 2.39) switched to max-page-size so that the last page can be protected by RELRO in case the system page size is larger than common-page-size. Thanks to our two RW PT_LOAD scheme (D58892), switching to max-page-size does not change file size (while GNU ld's scheme may increase file size). Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D125410
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Writer.cpp9
-rw-r--r--lld/docs/ReleaseNotes.rst4
-rw-r--r--lld/test/ELF/aarch64-relro.s2
-rw-r--r--lld/test/ELF/basic-ppc64.s2
4 files changed, 10 insertions, 7 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 649958b74798..0f53b7f488bd 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2638,11 +2638,10 @@ template <class ELFT> void Writer<ELFT>::setPhdrs(Partition &part) {
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;
}
}
}
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index b3751e53db55..645721fbb803 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -29,6 +29,10 @@ ELF Improvements
* ``-z pack-relative-relocs`` is now available to support ``DT_RELR`` for glibc 2.36+.
(`D120701 <https://reviews.llvm.org/D120701>`_)
* ``--no-fortran-common`` (pre 12.0.0 behavior) is now the default.
+* The end of ``PT_GNU_RELRO`` is now aligned by ``max-page-size`` instead of ``common-page-size``.
+ This matches GNU ld from 2.39 onwards. If the system page size is larger than ``common-page-size``,
+ the previous choice may make a partial page not protected by RELRO.
+ (`D125410 <https://reviews.llvm.org/D125410>`_)
Breaking changes
----------------
diff --git a/lld/test/ELF/aarch64-relro.s b/lld/test/ELF/aarch64-relro.s
index 4047382c8aa1..4223156df996 100644
--- a/lld/test/ELF/aarch64-relro.s
+++ b/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
diff --git a/lld/test/ELF/basic-ppc64.s b/lld/test/ELF/basic-ppc64.s
index 4032ceca614f..b3740230c41e 100644
--- a/lld/test/ELF/basic-ppc64.s
+++ b/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: ]