[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
authorFangrui Song <maskray@google.com>
Thu, 14 Mar 2019 03:47:45 +0000 (03:47 +0000)
committerFangrui Song <maskray@google.com>
Thu, 14 Mar 2019 03:47:45 +0000 (03:47 +0000)
commit07f8daf05ed1c6817a02ef89811c955874222245
tree075599f8cc15aeda58e5f2a7379d37608af2233a
parente77e5f44b871faa775b2cfa289b35f900f9443ab
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo

Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)

The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.

Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data

Other advantages:

* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
  simplifies binary manipulation tools.
  GNU strip before 2.31 discards PT_GNU_RELRO if its
  address is not equal to the start of its associated PT_LOAD.
  This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
  But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
  by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
  (start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
  (https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
  can improve on this regard if we'd like to.

Reviewers: ruiu, espindola, pcc

Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert

Differential Revision: https://reviews.llvm.org/D56828

llvm-svn: 356117
117 files changed:
lld/ELF/Writer.cpp
lld/test/ELF/aarch64-condb-reloc.s
lld/test/ELF/aarch64-cortex-a53-843419-large.s
lld/test/ELF/aarch64-cortex-a53-843419-recognize.s
lld/test/ELF/aarch64-cortex-a53-843419-thunk.s
lld/test/ELF/aarch64-gnu-ifunc-address-pie.s
lld/test/ELF/aarch64-gnu-ifunc-plt.s
lld/test/ELF/aarch64-ldprel-lo19-invalid.s
lld/test/ELF/aarch64-load-alignment.s
lld/test/ELF/aarch64-thunk-pi.s
lld/test/ELF/aarch64-tstbr14-reloc.s
lld/test/ELF/amdgpu-relocs.s
lld/test/ELF/arm-abs32-dyn.s
lld/test/ELF/arm-exidx-shared.s
lld/test/ELF/arm-fpic-got.s
lld/test/ELF/arm-gnu-ifunc-plt.s
lld/test/ELF/arm-pie-relative.s
lld/test/ELF/arm-plt-reloc.s
lld/test/ELF/arm-thumb-interwork-shared.s
lld/test/ELF/arm-thumb-plt-range-thunk-os.s
lld/test/ELF/arm-thumb-plt-reloc.s
lld/test/ELF/arm-thunk-multipass-plt.s
lld/test/ELF/arm-thunk-re-add.s
lld/test/ELF/arm-tls-norelax-gd-ie.s
lld/test/ELF/arm-tls-norelax-gd-le.s
lld/test/ELF/arm-tls-norelax-ie-le.s
lld/test/ELF/arm-tls-norelax-ld-le.s
lld/test/ELF/combrelocs.s
lld/test/ELF/copy-rel-pie.s
lld/test/ELF/dynamic-got.s
lld/test/ELF/dynamic-list-weak-archive.s
lld/test/ELF/dynamic-reloc-index.s
lld/test/ELF/dynamic-reloc.s
lld/test/ELF/emit-relocs-merge.s
lld/test/ELF/emit-relocs-shared.s
lld/test/ELF/executable-undefined-ignoreall.s
lld/test/ELF/gc-sections-linker-defined-symbol.s
lld/test/ELF/global-offset-table-position-aarch64.s
lld/test/ELF/global-offset-table-position-arm.s
lld/test/ELF/global-offset-table-position-i386.s
lld/test/ELF/global-offset-table-position.s
lld/test/ELF/global_offset_table_shared.s
lld/test/ELF/gnu-ifunc-canon.s
lld/test/ELF/gnu-ifunc-dso.s
lld/test/ELF/gnu-ifunc-dyntags.s
lld/test/ELF/gnu-ifunc-plt-i386.s
lld/test/ELF/gnu-ifunc-plt.s
lld/test/ELF/gnu-ifunc-shared.s
lld/test/ELF/got-aarch64.s
lld/test/ELF/got-plt-header.s
lld/test/ELF/got32x-i386.s
lld/test/ELF/gotpc-relax-nopic.s
lld/test/ELF/hexagon-shared.s
lld/test/ELF/i386-gotpc.s
lld/test/ELF/i386-merge.s
lld/test/ELF/i386-retpoline-nopic-linkerscript.s
lld/test/ELF/i386-retpoline-nopic.s
lld/test/ELF/i386-retpoline-pic-linkerscript.s
lld/test/ELF/i386-retpoline-pic.s
lld/test/ELF/linkerscript/align-section-offset.test
lld/test/ELF/linkerscript/emit-reloc.s
lld/test/ELF/linkerscript/orphan.s
lld/test/ELF/linkerscript/out-of-order.s
lld/test/ELF/linkerscript/overlapping-sections.s
lld/test/ELF/linkerscript/repsection-symbol.s
lld/test/ELF/linkerscript/sort-non-script.s
lld/test/ELF/linkerscript/version-linker-symbol.s
lld/test/ELF/lto/undefined-puts.ll
lld/test/ELF/lto/visibility.ll
lld/test/ELF/map-file.s
lld/test/ELF/merge-section-types.s
lld/test/ELF/mips-mgot.s
lld/test/ELF/mips-tls-64.s
lld/test/ELF/mips-tls-static-64.s
lld/test/ELF/mips-tls-static.s
lld/test/ELF/mips-tls.s
lld/test/ELF/pack-dyn-relocs-loop.s
lld/test/ELF/pack-dyn-relocs.s
lld/test/ELF/pack-dyn-relocs2.s
lld/test/ELF/plt-aarch64.s
lld/test/ELF/plt-i686.s
lld/test/ELF/plt.s
lld/test/ELF/ppc-rela.s
lld/test/ELF/ppc64-call-reach.s
lld/test/ELF/ppc64-func-entry-points.s
lld/test/ELF/ppc64-got-indirect.s
lld/test/ELF/ppc64-long-branch.s
lld/test/ELF/ppc64-shared-long_branch.s
lld/test/ELF/ppc64-toc-rel.s
lld/test/ELF/pr34660.s
lld/test/ELF/rel-offset.s
lld/test/ELF/relative-dynamic-reloc-pie.s
lld/test/ELF/relative-dynamic-reloc-ppc64.s
lld/test/ELF/relative-dynamic-reloc.s
lld/test/ELF/relocation-copy-flags.s
lld/test/ELF/relocation-i686.s
lld/test/ELF/relocation-non-alloc.s
lld/test/ELF/relocation-relative-weak.s
lld/test/ELF/relocation.s
lld/test/ELF/relro-non-contiguous.s
lld/test/ELF/section-layout.s
lld/test/ELF/section-name.s
lld/test/ELF/sort-norosegment.s
lld/test/ELF/startstop.s
lld/test/ELF/synthetic-got.s
lld/test/ELF/tls-dynamic-i686.s
lld/test/ELF/tls-dynamic.s
lld/test/ELF/undef-with-plt-addr.s
lld/test/ELF/undefined-versioned-symbol.s
lld/test/ELF/version-script-weak.s
lld/test/ELF/wrap-plt.s
lld/test/ELF/x86-64-plt-high-addr.s
lld/test/ELF/x86-64-reloc-gotoff64.s
lld/test/ELF/x86-64-reloc-gotpc64.s
lld/test/ELF/x86-64-retpoline-linkerscript.s
lld/test/ELF/x86-64-retpoline.s
lld/test/ELF/x86-64-tls-gd-local.s