diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp --- a/lld/ELF/Writer.cpp +++ b/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; } } } diff --git a/lld/test/ELF/aarch64-relro.s b/lld/test/ELF/aarch64-relro.s --- 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 --- 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: ]