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
|
|
|
|
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:
|
2015-09-15 21:30:08 +08:00
|
|
|
// CHECK-NEXT: _start:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201310: e8 04 00 00 00 callq 4
|
|
|
|
// CHECK-NEXT: 201315:
|
2015-09-15 21:30:08 +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:
|
2015-09-15 21:52:06 +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:
|
2015-09-16 08:24:19 +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:
|
2015-09-30 07:22:16 +08:00
|
|
|
// CHECK-NEXT: R_X86_64_PC32:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201327: {{.*}} callq 36
|
|
|
|
// 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:
|
2016-02-25 00:37:47 +08:00
|
|
|
// CHECK-NEXT: R_X86_64_32S_2:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 201331: {{.*}} movl 2102112, %eax
|
2016-02-25 00:37:47 +08:00
|
|
|
|
2015-09-15 21:52:06 +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:
|
[ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.
Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)
The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.
.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.
Reviewers: espindola, ruiu, pcc
Reviewed By: ruiu
Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58892
llvm-svn: 356226
2019-03-15 09:29:57 +08:00
|
|
|
// CHECK-NEXT: 2002f8 f8022000 00000000
|
2015-09-24 04:08:25 +08:00
|
|
|
|
|
|
|
.section .R_X86_64_GOTPCREL,"a",@progbits
|
|
|
|
.global R_X86_64_GOTPCREL
|
|
|
|
R_X86_64_GOTPCREL:
|
2015-10-07 05:52:48 +08:00
|
|
|
.long zed@gotpcrel
|
2015-09-24 04:08:25 +08:00
|
|
|
|
2019-09-16 15:05:34 +08:00
|
|
|
// 0x202460(.got) - 0x200300(.R_X86_64_GOTPCREL) = 0x2160
|
2015-09-24 04:08:25 +08:00
|
|
|
// CHECK: Contents of section .R_X86_64_GOTPCREL
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: 200300 60210000
|
2016-04-18 20:58:59 +08:00
|
|
|
|
|
|
|
.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:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: f8efffff
|
2016-12-10 05:46:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
// CHECK: Contents of section .R_X86_64_GOT64:
|
2019-09-16 15:05:34 +08:00
|
|
|
// CHECK-NEXT: f8efffff ffffffff
|
2016-12-10 05:46:39 +08:00
|
|
|
.section .R_X86_64_GOT64,"a",@progbits
|
|
|
|
.global R_X86_64_GOT64
|
|
|
|
R_X86_64_GOT64:
|
|
|
|
.quad zed@got
|