[lld] 2ac8ce5 - Revert D125410 "[ELF] Align the end of PT_GNU_RELRO to max-page-size instead of common-page-size"

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu May 12 20:41:26 PDT 2022


Author: Fangrui Song
Date: 2022-05-12T20:41:22-07:00
New Revision: 2ac8ce5d563b7f877706eaefe7683fdc9ca5c0ce

URL: https://github.com/llvm/llvm-project/commit/2ac8ce5d563b7f877706eaefe7683fdc9ca5c0ce
DIFF: https://github.com/llvm/llvm-project/commit/2ac8ce5d563b7f877706eaefe7683fdc9ca5c0ce.diff

LOG: Revert D125410 "[ELF] Align the end of PT_GNU_RELRO to max-page-size instead of common-page-size"

This reverts commit ebdb9d635a077274e38baa8584f5b0e631b4b1d3.

Changing p_memsz is insufficient and may make PT_GNU_RELRO extend beyond the
PT_LOAD.

Added: 
    

Modified: 
    lld/ELF/Writer.cpp
    lld/docs/ReleaseNotes.rst
    lld/test/ELF/aarch64-relro.s
    lld/test/ELF/basic-ppc64.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0f53b7f488bd5..649958b747986 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2638,10 +2638,11 @@ template <class ELFT> void Writer<ELFT>::setPhdrs(Partition &part) {
 
     if (p->p_type == PT_GNU_RELRO) {
       p->p_align = 1;
-      // 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;
+      // 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;
     }
   }
 }

diff  --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index 645721fbb8038..b3751e53db55c 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -29,10 +29,6 @@ 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 4223156df996e..4047382c8aa1b 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: 65136
+# CHECK-NEXT: MemSize: 3696
 
 .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 b3740230c41ed..4032ceca614fb 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: 64968
+// CHECK-NEXT:    MemSize: 3528
 // CHECK-NEXT:    Flags [ (0x4)
 // CHECK-NEXT:      PF_R (0x4)
 // CHECK-NEXT:    ]


        


More information about the llvm-commits mailing list