2018-06-27 06:20:04 +08:00
|
|
|
// REQUIRES: x86
|
2015-08-28 07:15:56 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
|
2015-09-30 07:22:16 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2
|
2018-05-16 01:02:35 +08:00
|
|
|
// RUN: ld.lld %t2 -soname fixed-length-string.so -o %t2.so -shared
|
2017-10-06 17:37:44 +08:00
|
|
|
// RUN: ld.lld --hash-style=sysv %t %t2.so -o %t3
|
2019-05-01 13:49:01 +08:00
|
|
|
// RUN: llvm-readobj -S %t3 | FileCheck --check-prefix=SEC %s
|
2015-09-30 07:22:16 +08:00
|
|
|
// RUN: llvm-objdump -s -d %t3 | FileCheck %s
|
2015-08-28 07:15:56 +08:00
|
|
|
|
2015-10-02 05:15:02 +08:00
|
|
|
// SEC: Name: .plt
|
|
|
|
// SEC-NEXT: Type: SHT_PROGBITS
|
|
|
|
// SEC-NEXT: Flags [
|
|
|
|
// SEC-NEXT: SHF_ALLOC
|
|
|
|
// SEC-NEXT: SHF_EXECINSTR
|
|
|
|
// SEC-NEXT: ]
|
2019-09-16 15:05:34 +08:00
|
|
|
// SEC-NEXT: Address: 0x201340
|
|
|
|
// SEC-NEXT: Offset: 0x340
|
2016-02-25 00:37:47 +08:00
|
|
|
// SEC-NEXT: Size: 48
|
2015-10-02 05:15:02 +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
|
|
|
// SEC: Name: .got
|
2015-09-24 04:08:25 +08:00
|
|
|
// SEC-NEXT: Type: SHT_PROGBITS
|
|
|
|
// SEC-NEXT: Flags [
|
|
|
|
// SEC-NEXT: SHF_ALLOC
|
|
|
|
// SEC-NEXT: SHF_WRITE
|
|
|
|
// SEC-NEXT: ]
|
2019-09-16 15:05:34 +08:00
|
|
|
// SEC-NEXT: Address: 0x202460
|
[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
|
|
|
// SEC-NEXT: Offset:
|
|
|
|
// SEC-NEXT: Size: 8
|
2015-09-24 04:08:25 +08:00
|
|
|
// SEC-NEXT: Link: 0
|
|
|
|
// SEC-NEXT: Info: 0
|
|
|
|
// SEC-NEXT: AddressAlignment: 8
|
|
|
|
// SEC-NEXT: EntrySize: 0
|
[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
|
|
|
// SEC-NEXT: }
|
2015-08-28 07:15:56 +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
|
|
|
// SEC: Name: .got.plt
|
2015-10-20 16:54:27 +08:00
|
|
|
// SEC-NEXT: Type: SHT_PROGBITS
|
|
|
|
// SEC-NEXT: Flags [
|
|
|
|
// SEC-NEXT: SHF_ALLOC
|
|
|
|
// SEC-NEXT: SHF_WRITE
|
|
|
|
// SEC-NEXT: ]
|
2019-09-16 15:05:34 +08:00
|
|
|
// SEC-NEXT: Address: 0x203468
|
|
|
|
// SEC-NEXT: Offset: 0x468
|
[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
|
|
|
// SEC-NEXT: Size: 40
|
2015-10-20 16:54:27 +08:00
|
|
|
// SEC-NEXT: Link: 0
|
|
|
|
// SEC-NEXT: Info: 0
|
|
|
|
// SEC-NEXT: AddressAlignment: 8
|
|
|
|
// SEC-NEXT: EntrySize: 0
|
[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
|
|
|
// SEC-NEXT: }
|
2015-10-20 16:54:27 +08:00
|
|
|
|
[llvm-objdump] Further rearrange llvm-objdump sections for compatability
Summary:
rL371826 rearranged some output from llvm-objdump for GNU objdump compatability, but there still seem to be some more.
I think this rearrangement is a little closer. Overview of the ordering which matches GNU objdump:
* Archive headers
* File headers
* Section headers
* Symbol table
* Dwarf debugging
* Relocations (if `--disassemble` is not used)
* Section contents
* Disassembly
Reviewers: jhenderson, justice_adams, grimar, ychen, espindola
Reviewed By: jhenderson
Subscribers: aprantl, emaste, arichardson, jrtc27, atanasyan, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68066
llvm-svn: 373671
2019-10-04 06:01:08 +08:00
|
|
|
.section .R_X86_64_64,"a",@progbits
|
|
|
|
.global R_X86_64_64
|
|
|
|
R_X86_64_64:
|
|
|
|
.quad R_X86_64_64
|
|
|
|
|
|
|
|
// CHECK: Contents of section .R_X86_64_64:
|
|
|
|
// CHECK-NEXT: 2002f8 f8022000 00000000
|
|
|
|
|
|
|
|
.section .R_X86_64_GOTPCREL,"a",@progbits
|
|
|
|
.global R_X86_64_GOTPCREL
|
|
|
|
R_X86_64_GOTPCREL:
|
|
|
|
.long zed@gotpcrel
|
|
|
|
|
|
|
|
// 0x202460(.got) - 0x200300(.R_X86_64_GOTPCREL) = 0x2160
|
|
|
|
// CHECK: Contents of section .R_X86_64_GOTPCREL
|
|
|
|
// CHECK-NEXT: 200300 60210000
|
|
|
|
|
|
|
|
.section .R_X86_64_GOT32,"a",@progbits
|
|
|
|
.global R_X86_64_GOT32
|
|
|
|
R_X86_64_GOT32:
|
|
|
|
.long zed@got
|
|
|
|
|
|
|
|
// CHECK: Contents of section .R_X86_64_GOT32:
|
|
|
|
// CHECK-NEXT: f8efffff
|
|
|
|
|
|
|
|
|
|
|
|
// CHECK: Contents of section .R_X86_64_GOT64:
|
|
|
|
// CHECK-NEXT: f8efffff ffffffff
|
|
|
|
.section .R_X86_64_GOT64,"a",@progbits
|
|
|
|
.global R_X86_64_GOT64
|
|
|
|
R_X86_64_GOT64:
|
|
|
|
.quad zed@got
|
|
|
|
|
2015-08-28 07:15:56 +08:00
|
|
|
.section .text,"ax",@progbits,unique,1
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
call lulz
|
|
|
|
|
|
|
|
.section .text,"ax",@progbits,unique,2
|
|
|
|
.zero 4
|
|
|
|
.global lulz
|
|
|
|
lulz:
|
2015-09-15 21:30:08 +08:00
|
|
|
nop
|
|
|
|
|
|
|
|
// CHECK: Disassembly of section .text:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK-NEXT: <_start>:
|
2020-03-23 06:03:10 +08:00
|
|
|
// CHECK-NEXT: 201310: e8 04 00 00 00 callq 0x201319
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201315:
|
2015-09-15 21:30:08 +08:00
|
|
|
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK: <lulz>:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201319: 90 nop
|
2015-09-15 21:30:08 +08:00
|
|
|
|
2015-08-28 07:15:56 +08:00
|
|
|
|
2015-09-15 21:30:08 +08:00
|
|
|
.section .text2,"ax",@progbits
|
2015-09-15 21:52:06 +08:00
|
|
|
.global R_X86_64_32
|
|
|
|
R_X86_64_32:
|
|
|
|
movl $R_X86_64_32, %edx
|
2015-08-29 21:15:42 +08:00
|
|
|
|
2015-09-15 21:30:08 +08:00
|
|
|
// FIXME: this would be far more self evident if llvm-objdump printed
|
|
|
|
// constants in hex.
|
|
|
|
// CHECK: Disassembly of section .text2:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK-NEXT: <R_X86_64_32>:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 20131a: {{.*}} movl $2102042, %edx
|
2015-09-15 21:52:06 +08:00
|
|
|
|
2015-09-16 08:24:19 +08:00
|
|
|
.section .R_X86_64_32S,"ax",@progbits
|
|
|
|
.global R_X86_64_32S
|
|
|
|
R_X86_64_32S:
|
|
|
|
movq lulz - 0x100000, %rdx
|
|
|
|
|
|
|
|
// CHECK: Disassembly of section .R_X86_64_32S:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK-NEXT: <R_X86_64_32S>:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: {{.*}}: {{.*}} movq 1053465, %rdx
|
2015-09-16 08:24:19 +08:00
|
|
|
|
2015-09-30 07:22:16 +08:00
|
|
|
.section .R_X86_64_PC32,"ax",@progbits
|
|
|
|
.global R_X86_64_PC32
|
|
|
|
R_X86_64_PC32:
|
|
|
|
call bar
|
2015-10-15 00:15:46 +08:00
|
|
|
movl $bar, %eax
|
2015-10-20 16:54:27 +08:00
|
|
|
//16 is a size of PLT[0]
|
2019-09-16 15:05:34 +08:00
|
|
|
// 0x201340 + 16 - (0x201327 + 5) = 36
|
2015-09-30 07:22:16 +08:00
|
|
|
// CHECK: Disassembly of section .R_X86_64_PC32:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK-NEXT: <R_X86_64_PC32>:
|
2020-03-23 06:03:10 +08:00
|
|
|
// CHECK-NEXT: 201327: {{.*}} callq 0x201350
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 20132c: {{.*}} movl $2102096, %eax
|
2015-09-30 07:22:16 +08:00
|
|
|
|
2016-02-25 00:37:47 +08:00
|
|
|
.section .R_X86_64_32S_2,"ax",@progbits
|
|
|
|
.global R_X86_64_32S_2
|
|
|
|
R_X86_64_32S_2:
|
|
|
|
mov bar2, %eax
|
2019-09-16 15:05:34 +08:00
|
|
|
// plt is at 0x201340. The second plt entry is at 0x201360 == 2102112
|
2016-02-25 00:37:47 +08:00
|
|
|
// CHECK: Disassembly of section .R_X86_64_32S_2:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
// CHECK-NEXT: <R_X86_64_32S_2>:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201331: {{.*}} movl 2102112, %eax
|