[PATCH] D28267: ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 19:09:30 PST 2017


pcc added inline comments.


================
Comment at: lld/ELF/Writer.cpp:1452-1453
       P.p_align = 1;
+      // The glibc dynamic loader rounds the size down, so we need to round up
+      // to protect the last page.
+      P.p_memsz = alignTo(P.p_memsz, Config->MaxPageSize);
----------------
emaste wrote:
> For reference the FreeBSD rtld algorithm is:
> ```
>             obj->relro_page = obj->relocbase + trunc_page(ph->p_vaddr);
>             obj->relro_size = round_page(ph->p_memsz);
> ```
> https://svnweb.freebsd.org/base/head/libexec/rtld-elf/rtld.c?annotate=310422#l1334
Thanks. `round_page` appears to be system-specific but always seems to round up [0]. I've added a note to the comment.

[0] https://github.com/freebsd/freebsd/search?utf8=%E2%9C%93&q=%22define+round_page%22&type=Code


https://reviews.llvm.org/D28267





More information about the llvm-commits mailing list