[PATCH] D64906: [ELF][PPC] Allow overlapping PT_LOAD (keep p_offset ranges adjacent) to decrease file size

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 22:19:32 PDT 2019


MaskRay added a comment.

More about PT_GNU_RELRO (this goes beyond the scope of this patch):

1. FreeBSD rtld.c <https://github.com/freebsd/freebsd/blob/master/libexec/rtld-elf/rtld.c#L1458> is wrong: its last page of PT_GNU_RELRO may not be protected whatever lld does:

  obj->relro_page = obj->relocbase + trunc_page(ph->p_vaddr);
  obj->relro_size = round_page(ph->p_memsz);



2. ld.bfd seems to align the end of PT_GNU_RELRO to common-page-size (can be observed with `-z relro -z max-page-size=0x200000 -z common-page-size=0x4000`). If `common-page-size < runtime pagesz <= max-page-size`, the last page may not be protected.

3. The status quo (D29242 <https://reviews.llvm.org/D29242>) seems the best we can do. We cannot round p_memsz up to max-page-size. If `RW(relro(...)) RW(non-relro(empty))`, and `runtime pagesz < max-page-size`, mprotect invoked by ld.so will have an out-of-range `len`. According to POSIX, `[ENOMEM] Addresses in the range [addr,addr+len) are invalid for the address space of a process, or specify one or more pages which are not mapped.`

Discussed with dalias, the best thing is to let ld.so round up p_memsz. All of FreeBSD rtld/glibc/musl currently have issues in this regard.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64906/new/

https://reviews.llvm.org/D64906





More information about the llvm-commits mailing list