[PATCH] D29242: ELF: Align RELRO to the target page size rather than the max page size.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 09:13:11 PST 2017


LGTM. Thanks

Peter Collingbourne via Phabricator <reviews at reviews.llvm.org> writes:

> pcc created this revision.
>
> If no bss sections appear after the relro segment, the loader will round
> the r/w segment size to the target's page size. Align the relro size in the
> same way to ensure that it does not extend past the end of the program's
> own memory region.
>
>
> https://reviews.llvm.org/D29242
>
> Files:
>   lld/ELF/Writer.cpp
>   lld/test/ELF/aarch64-relro.s
>
>
> Index: lld/test/ELF/aarch64-relro.s
> ===================================================================
> --- /dev/null
> +++ lld/test/ELF/aarch64-relro.s
> @@ -0,0 +1,13 @@
> +# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
> +# RUN: ld.lld %t -o %t2
> +# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
> +
> +# CHECK:      Type: PT_GNU_RELRO
> +# CHECK-NEXT: Offset:
> +# CHECK-NEXT: VirtualAddress:
> +# CHECK-NEXT: PhysicalAddress:
> +# CHECK-NEXT: FileSize:
> +# CHECK-NEXT: MemSize: 4096
> +
> +.section .data.rel.ro,"aw",%progbits
> +.byte 1
> Index: lld/ELF/Writer.cpp
> ===================================================================
> --- lld/ELF/Writer.cpp
> +++ lld/ELF/Writer.cpp
> @@ -1489,7 +1489,7 @@
>        // 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);
> +      P.p_memsz = alignTo(P.p_memsz, Target->PageSize);
>      }
>  
>      // The TLS pointer goes after PT_TLS. At least glibc will align it,
>
>
> Index: lld/test/ELF/aarch64-relro.s
> ===================================================================
> --- /dev/null
> +++ lld/test/ELF/aarch64-relro.s
> @@ -0,0 +1,13 @@
> +# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
> +# RUN: ld.lld %t -o %t2
> +# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
> +
> +# CHECK:      Type: PT_GNU_RELRO
> +# CHECK-NEXT: Offset:
> +# CHECK-NEXT: VirtualAddress:
> +# CHECK-NEXT: PhysicalAddress:
> +# CHECK-NEXT: FileSize:
> +# CHECK-NEXT: MemSize: 4096
> +
> +.section .data.rel.ro,"aw",%progbits
> +.byte 1
> Index: lld/ELF/Writer.cpp
> ===================================================================
> --- lld/ELF/Writer.cpp
> +++ lld/ELF/Writer.cpp
> @@ -1489,7 +1489,7 @@
>        // 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);
> +      P.p_memsz = alignTo(P.p_memsz, Target->PageSize);
>      }
>  
>      // The TLS pointer goes after PT_TLS. At least glibc will align it,


More information about the llvm-commits mailing list