2018-06-27 06:20:04 +08:00
|
|
|
// REQUIRES: x86
|
2015-09-21 23:11:29 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
|
2019-09-11 14:20:14 +08:00
|
|
|
// RUN: ld.lld -shared -soname=so %t2.o -o %t2.so
|
2015-11-18 14:11:01 +08:00
|
|
|
// RUN: ld.lld -shared %t.o %t2.so -o %t
|
|
|
|
// RUN: ld.lld %t.o %t2.so -o %t3
|
2019-05-01 13:49:01 +08:00
|
|
|
// RUN: llvm-readobj -S -r %t | FileCheck %s
|
2019-09-11 14:20:14 +08:00
|
|
|
// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASM %s
|
2019-05-01 13:49:01 +08:00
|
|
|
// RUN: llvm-readobj -S -r %t3 | FileCheck --check-prefix=CHECK2 %s
|
2019-09-11 14:20:14 +08:00
|
|
|
// RUN: llvm-objdump -d --no-show-raw-insn %t3 | FileCheck --check-prefix=DISASM2 %s
|
2015-10-17 07:52:24 +08:00
|
|
|
|
2015-09-21 23:11:29 +08:00
|
|
|
// CHECK: Name: .plt
|
|
|
|
// CHECK-NEXT: Type: SHT_PROGBITS
|
|
|
|
// CHECK-NEXT: Flags [
|
|
|
|
// CHECK-NEXT: SHF_ALLOC
|
|
|
|
// CHECK-NEXT: SHF_EXECINSTR
|
|
|
|
// CHECK-NEXT: ]
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: Address: 0x1320
|
2015-09-21 23:11:29 +08:00
|
|
|
// CHECK-NEXT: Offset:
|
2015-10-20 16:54:27 +08:00
|
|
|
// CHECK-NEXT: Size: 64
|
2015-09-21 23:11:29 +08:00
|
|
|
// CHECK-NEXT: Link: 0
|
|
|
|
// CHECK-NEXT: Info: 0
|
|
|
|
// CHECK-NEXT: AddressAlignment: 16
|
|
|
|
|
|
|
|
// CHECK: Relocations [
|
2015-10-20 16:54:27 +08:00
|
|
|
// CHECK-NEXT: Section ({{.*}}) .rela.plt {
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 0x3438 R_X86_64_JUMP_SLOT bar 0x0
|
|
|
|
// CHECK-NEXT: 0x3440 R_X86_64_JUMP_SLOT zed 0x0
|
|
|
|
// CHECK-NEXT: 0x3448 R_X86_64_JUMP_SLOT _start 0x0
|
2015-09-21 23:11:29 +08:00
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: ]
|
|
|
|
|
2015-10-17 07:52:24 +08:00
|
|
|
// CHECK2: Name: .plt
|
|
|
|
// CHECK2-NEXT: Type: SHT_PROGBITS
|
|
|
|
// CHECK2-NEXT: Flags [
|
|
|
|
// CHECK2-NEXT: SHF_ALLOC
|
|
|
|
// CHECK2-NEXT: SHF_EXECINSTR
|
|
|
|
// CHECK2-NEXT: ]
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK2-NEXT: Address: 0x2012E0
|
2015-10-17 07:52:24 +08:00
|
|
|
// CHECK2-NEXT: Offset:
|
2015-10-20 16:54:27 +08:00
|
|
|
// CHECK2-NEXT: Size: 48
|
2015-10-17 07:52:24 +08:00
|
|
|
// CHECK2-NEXT: Link: 0
|
|
|
|
// CHECK2-NEXT: Info: 0
|
|
|
|
// CHECK2-NEXT: AddressAlignment: 16
|
|
|
|
|
|
|
|
// CHECK2: Relocations [
|
2015-10-20 16:54:27 +08:00
|
|
|
// CHECK2-NEXT: Section ({{.*}}) .rela.plt {
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK2-NEXT: 0x2033F8 R_X86_64_JUMP_SLOT bar 0x0
|
|
|
|
// CHECK2-NEXT: 0x203400 R_X86_64_JUMP_SLOT zed 0x0
|
2015-10-17 07:52:24 +08:00
|
|
|
// CHECK2-NEXT: }
|
|
|
|
// CHECK2-NEXT: ]
|
|
|
|
|
2015-09-21 23:11:29 +08:00
|
|
|
// DISASM: _start:
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM-NEXT: jmp {{.*}} <bar@plt>
|
|
|
|
// DISASM-NEXT: jmp {{.*}} <bar@plt>
|
|
|
|
// DISASM-NEXT: jmp {{.*}} <zed@plt>
|
|
|
|
// DISASM-NEXT: jmp {{.*}} <_start@plt>
|
2015-09-21 23:11:29 +08:00
|
|
|
|
[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
|
|
|
// 0x3018 - 0x1036 = 8162
|
|
|
|
// 0x3020 - 0x1046 = 8154
|
|
|
|
// 0x3028 - 0x1056 = 8146
|
2015-09-21 23:11:29 +08:00
|
|
|
|
|
|
|
// DISASM: Disassembly of section .plt:
|
2019-05-01 18:40:48 +08:00
|
|
|
// DISASM-EMPTY:
|
2015-09-21 23:11:29 +08:00
|
|
|
// DISASM-NEXT: .plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM-NEXT: 1320: pushq 8450(%rip)
|
|
|
|
// DISASM-NEXT: jmpq *8452(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM-NEXT: nopl (%rax)
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-EMPTY:
|
|
|
|
// DISASM-NEXT: bar@plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM-NEXT: 1330: jmpq *8450(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM-NEXT: pushq $0
|
|
|
|
// DISASM-NEXT: jmp -32 <.plt>
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-EMPTY:
|
|
|
|
// DISASM-NEXT: zed@plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM-NEXT: 1340: jmpq *8442(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM-NEXT: pushq $1
|
|
|
|
// DISASM-NEXT: jmp -48 <.plt>
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM-EMPTY:
|
|
|
|
// DISASM-NEXT: _start@plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM-NEXT: 1350: jmpq *8434(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM-NEXT: pushq $2
|
|
|
|
// DISASM-NEXT: jmp -64 <.plt>
|
2015-10-17 07:52:24 +08:00
|
|
|
|
2016-11-24 01:44:02 +08:00
|
|
|
// 0x201030 - (0x201000 + 1) - 4 = 43
|
|
|
|
// 0x201030 - (0x201005 + 1) - 4 = 38
|
|
|
|
// 0x201040 - (0x20100a + 1) - 4 = 49
|
|
|
|
// 0x201000 - (0x20100f + 1) - 4 = -20
|
2015-10-17 07:52:24 +08:00
|
|
|
|
|
|
|
// DISASM2: _start:
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: jmp 43 <bar@plt>
|
|
|
|
// DISASM2-NEXT: jmp 38 <bar@plt>
|
|
|
|
// DISASM2-NEXT: jmp 49 <zed@plt>
|
|
|
|
// DISASM2-NEXT: jmp -20 <_start>
|
2015-10-17 07:52:24 +08:00
|
|
|
|
2017-01-10 09:21:30 +08:00
|
|
|
// 0x202018 - 0x201036 = 4066
|
|
|
|
// 0x202020 - 0x201046 = 4058
|
2015-10-20 16:54:27 +08:00
|
|
|
|
2015-10-17 07:52:24 +08:00
|
|
|
// DISASM2: Disassembly of section .plt:
|
2019-05-01 18:40:48 +08:00
|
|
|
// DISASM2-EMPTY:
|
2015-10-17 07:52:24 +08:00
|
|
|
// DISASM2-NEXT: .plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM2-NEXT: 2012e0: pushq 8450(%rip)
|
|
|
|
// DISASM2-NEXT: jmpq *8452(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: nopl (%rax)
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM2-EMPTY:
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: bar@plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM2-NEXT: 2012f0: jmpq *8450(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: pushq $0
|
|
|
|
// DISASM2-NEXT: jmp -32 <.plt>
|
2018-08-25 00:22:42 +08:00
|
|
|
// DISASM2-EMPTY:
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: zed@plt:
|
2019-09-16 15:05:34 +08:00
|
|
|
// DISASM2-NEXT: 201300: jmpq *8442(%rip)
|
2019-09-11 14:20:14 +08:00
|
|
|
// DISASM2-NEXT: pushq $1
|
|
|
|
// DISASM2-NEXT: jmp -48 <.plt>
|
|
|
|
// DISASM2-NOT: {{.}}
|
2015-09-21 23:11:29 +08:00
|
|
|
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
jmp bar@PLT
|
|
|
|
jmp bar@PLT
|
|
|
|
jmp zed@PLT
|
2015-09-29 03:48:34 +08:00
|
|
|
jmp _start@plt
|