Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -1444,8 +1444,13 @@ } 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. Index: lld/trunk/test/ELF/basic-mips.s =================================================================== --- lld/trunk/test/ELF/basic-mips.s +++ lld/trunk/test/ELF/basic-mips.s @@ -297,7 +297,7 @@ # 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: ] Index: lld/trunk/test/ELF/basic-ppc.s =================================================================== --- lld/trunk/test/ELF/basic-ppc.s +++ lld/trunk/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: ]