2016-12-08 20:58:55 +08:00
|
|
|
// REQUIRES: x86
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
2017-10-06 17:37:44 +08:00
|
|
|
// RUN: ld.lld --hash-style=sysv --shared -o %t.so %t.o
|
2016-12-08 20:58:55 +08:00
|
|
|
// RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=DISASM
|
|
|
|
// RUN: llvm-readobj -r %t.so | FileCheck %s
|
|
|
|
|
|
|
|
// Check that an IRELATIVE relocation is used for a non-preemptible ifunc
|
|
|
|
// handler and a JUMP_SLOT is used for a preemptible ifunc
|
|
|
|
// DISASM: Disassembly of section .text:
|
2019-05-01 18:40:48 +08:00
|
|
|
// DISASM-EMPTY:
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: fct:
|
|
|
|
// DISASM-NEXT: 1000: c3 retq
|
|
|
|
// DISASM: fct2:
|
|
|
|
// DISASM-NEXT: 1001: c3 retq
|
|
|
|
// DISASM: f1:
|
|
|
|
// DISASM-NEXT: 1002: e8 49 00 00 00 callq 73
|
|
|
|
// DISASM-NEXT: 1007: e8 24 00 00 00 callq 36
|
|
|
|
// DISASM-NEXT: 100c: e8 2f 00 00 00 callq 47
|
|
|
|
// DISASM-NEXT: 1011: c3 retq
|
|
|
|
// DISASM: f2:
|
|
|
|
// DISASM-NEXT: 1012: c3 retq
|
2019-05-01 18:40:48 +08:00
|
|
|
// DISASM-EMPTY:
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: Disassembly of section .plt:
|
2019-05-01 18:40:48 +08:00
|
|
|
// DISASM-EMPTY:
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: .plt:
|
[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
|
|
|
// DISASM-NEXT: 1020: ff 35 e2 1f 00 00 pushq 8162(%rip)
|
|
|
|
// DISASM-NEXT: 1026: ff 25 e4 1f 00 00 jmpq *8164(%rip)
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: 102c: 0f 1f 40 00 nopl (%rax)
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-EMPTY:
|
|
|
|
// DISASM-NEXT: fct2@plt:
|
[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
|
|
|
// DISASM-NEXT: 1030: ff 25 e2 1f 00 00 jmpq *8162(%rip)
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: 1036: 68 00 00 00 00 pushq $0
|
|
|
|
// DISASM-NEXT: 103b: e9 e0 ff ff ff jmp -32 <.plt>
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-EMPTY:
|
|
|
|
// DISASM-NEXT: f2@plt:
|
[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
|
|
|
// DISASM-NEXT: 1040: ff 25 da 1f 00 00 jmpq *8154(%rip)
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: 1046: 68 01 00 00 00 pushq $1
|
|
|
|
// DISASM-NEXT: 104b: e9 d0 ff ff ff jmp -48 <.plt>
|
[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
|
|
|
// DISASM-NEXT: 1050: ff 25 d2 1f 00 00 jmpq *8146(%rip)
|
2016-12-08 20:58:55 +08:00
|
|
|
// DISASM-NEXT: 1056: 68 00 00 00 00 pushq $0
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-NEXT: 105b: e9 e0 ff ff ff jmp -32 <f2@plt>
|
2016-12-08 20:58:55 +08:00
|
|
|
|
|
|
|
// CHECK: Relocations [
|
|
|
|
// CHECK-NEXT: Section (4) .rela.plt {
|
[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
|
|
|
// CHECK-NEXT: 0x3018 R_X86_64_JUMP_SLOT fct2 0x0
|
|
|
|
// CHECK-NEXT: 0x3020 R_X86_64_JUMP_SLOT f2 0x0
|
|
|
|
// CHECK-NEXT: 0x3028 R_X86_64_IRELATIVE - 0x1000
|
2016-12-08 20:58:55 +08:00
|
|
|
|
|
|
|
// Hidden expect IRELATIVE
|
|
|
|
.globl fct
|
|
|
|
.hidden fct
|
|
|
|
.type fct, STT_GNU_IFUNC
|
|
|
|
fct:
|
|
|
|
ret
|
|
|
|
|
|
|
|
// Not hidden expect JUMP_SLOT
|
|
|
|
.globl fct2
|
|
|
|
.type fct2, STT_GNU_IFUNC
|
|
|
|
fct2:
|
|
|
|
ret
|
|
|
|
|
|
|
|
.globl f1
|
|
|
|
.type f1, @function
|
|
|
|
f1:
|
|
|
|
call fct
|
|
|
|
call fct2
|
|
|
|
call f2@PLT
|
|
|
|
ret
|
|
|
|
|
|
|
|
.globl f2
|
|
|
|
.type f2, @function
|
|
|
|
f2:
|
|
|
|
ret
|