2016-11-25 16:05:41 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
|
|
|
# RUN: echo "SECTIONS { }" > %t0.script
|
2017-10-06 17:37:44 +08:00
|
|
|
# RUN: ld.lld --hash-style=sysv -shared %t.o -o %t0.out --script %t0.script
|
2020-03-16 08:47:44 +08:00
|
|
|
# RUN: llvm-objdump --section-headers %t0.out | FileCheck %s --check-prefix=GOT
|
|
|
|
# RUN: llvm-objdump -s --section=.got --section=.got.plt %t0.out \
|
2016-11-25 16:05:41 +08:00
|
|
|
# RUN: | FileCheck %s --check-prefix=GOTDATA
|
|
|
|
|
|
|
|
# GOT: Sections:
|
[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
2019-03-14 11:47:45 +08:00
|
|
|
# GOT: 9 .got 00000008 00000000000001b0 DATA
|
|
|
|
# GOT: 10 .got.plt 00000020 00000000000001b8 DATA
|
|
|
|
# GOTDATA: Contents of section .got:
|
|
|
|
# GOTDATA-NEXT: 01b0 00000000 00000000
|
|
|
|
# GOTDATA-NEXT: Contents of section .got.plt:
|
|
|
|
# GOTDATA-NEXT: 01b8 e0000000 00000000 00000000 00000000
|
|
|
|
# GOTDATA-NEXT: 01c8 00000000 00000000 d6000000 00000000
|
2016-11-25 16:05:41 +08:00
|
|
|
|
|
|
|
# RUN: echo "SECTIONS { .mygot : { *(.got) *(.got.plt) } }" > %t1.script
|
2017-10-06 17:37:44 +08:00
|
|
|
# RUN: ld.lld --hash-style=sysv -shared %t.o -o %t1.out --script %t1.script
|
2020-03-16 08:47:44 +08:00
|
|
|
# RUN: llvm-objdump --section-headers %t1.out | FileCheck %s --check-prefix=MYGOT
|
|
|
|
# RUN: llvm-objdump -s --section=.mygot %t1.out | FileCheck %s --check-prefix=MYGOTDATA
|
2016-11-25 16:05:41 +08:00
|
|
|
|
|
|
|
# MYGOT: Sections:
|
2018-06-27 01:04:47 +08:00
|
|
|
# MYGOT: 8 .mygot 00000028 00000000000000e0 DATA
|
2016-11-25 16:05:41 +08:00
|
|
|
# MYGOT-NOT: .got
|
|
|
|
# MYGOT-NOT: .got.plt
|
2018-06-27 01:04:47 +08:00
|
|
|
# MYGOTDATA: 00e0 00000000 00000000 08010000 00000000
|
|
|
|
# MYGOTDATA-NEXT: 00f0 00000000 00000000 00000000 00000000
|
|
|
|
# MYGOTDATA-NEXT: 0100 d6000000 00000000
|
2016-11-25 16:05:41 +08:00
|
|
|
|
|
|
|
mov bar@gotpcrel(%rip), %rax
|
|
|
|
call foo@plt
|