2018-06-27 06:20:04 +08:00
|
|
|
// REQUIRES: x86
|
2019-08-07 17:43:54 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i686 %p/Inputs/shared.s -o %t2.o
|
|
|
|
// RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so
|
|
|
|
// RUN: ld.lld --hash-style=sysv %t.o %t2.so -o %t
|
|
|
|
// RUN: llvm-readobj -S %t | FileCheck --check-prefix=ADDR %s
|
|
|
|
// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
|
2015-09-17 05:57:07 +08:00
|
|
|
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
|
|
|
|
.section .R_386_32,"ax",@progbits
|
|
|
|
.global R_386_32
|
|
|
|
R_386_32:
|
2015-09-22 21:35:00 +08:00
|
|
|
movl $R_386_32 + 1, %edx
|
2015-09-17 05:57:07 +08:00
|
|
|
|
2015-09-22 21:47:45 +08:00
|
|
|
|
|
|
|
.section .R_386_PC32,"ax",@progbits,unique,1
|
|
|
|
.global R_386_PC32
|
|
|
|
R_386_PC32:
|
|
|
|
call R_386_PC32_2
|
|
|
|
|
|
|
|
.section .R_386_PC32,"ax",@progbits,unique,2
|
|
|
|
.zero 4
|
|
|
|
R_386_PC32_2:
|
|
|
|
nop
|
|
|
|
|
2015-09-17 05:57:07 +08:00
|
|
|
// CHECK: Disassembly of section .R_386_32:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2015-09-17 05:57:07 +08:00
|
|
|
// CHECK-NEXT: R_386_32:
|
2019-08-20 16:43:47 +08:00
|
|
|
// CHECK-NEXT: movl $4198829, %edx
|
2015-09-22 21:47:45 +08:00
|
|
|
|
|
|
|
// CHECK: Disassembly of section .R_386_PC32:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2015-09-22 21:47:45 +08:00
|
|
|
// CHECK-NEXT: R_386_PC32:
|
2019-08-07 17:43:54 +08:00
|
|
|
// CHECK-NEXT: calll 4
|
2015-09-22 21:47:45 +08:00
|
|
|
|
|
|
|
// CHECK: R_386_PC32_2:
|
2019-08-07 17:43:54 +08:00
|
|
|
// CHECK-NEXT: nop
|
2015-09-29 21:36:32 +08:00
|
|
|
|
|
|
|
// Create a .got
|
|
|
|
movl bar@GOT, %eax
|
|
|
|
|
2015-10-09 02:58:10 +08:00
|
|
|
// ADDR: Name: .plt
|
|
|
|
// ADDR-NEXT: Type: SHT_PROGBITS
|
|
|
|
// ADDR-NEXT: Flags [
|
|
|
|
// ADDR-NEXT: SHF_ALLOC
|
|
|
|
// ADDR-NEXT: SHF_EXECINSTR
|
|
|
|
// ADDR-NEXT: ]
|
2019-08-20 16:43:47 +08:00
|
|
|
// ADDR-NEXT: Address: 0x4011E0
|
|
|
|
// ADDR-NEXT: Offset: 0x1E0
|
2015-11-26 06:15:01 +08:00
|
|
|
// ADDR-NEXT: Size: 32
|
2015-09-29 21:36:32 +08:00
|
|
|
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
// ADDR: Name: .got.plt (
|
2015-09-29 21:36:32 +08:00
|
|
|
// ADDR-NEXT: Type: SHT_PROGBITS
|
|
|
|
// ADDR-NEXT: Flags [
|
|
|
|
// ADDR-NEXT: SHF_ALLOC
|
|
|
|
// ADDR-NEXT: SHF_WRITE
|
|
|
|
// ADDR-NEXT: ]
|
2019-08-20 16:43:47 +08:00
|
|
|
// ADDR-NEXT: Address: 0x403280
|
2016-09-01 07:24:11 +08:00
|
|
|
// ADDR-NEXT: Offset:
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
// ADDR-NEXT: Size:
|
2015-09-29 21:36:32 +08:00
|
|
|
|
|
|
|
.section .R_386_GOTPC,"ax",@progbits
|
|
|
|
R_386_GOTPC:
|
|
|
|
movl $_GLOBAL_OFFSET_TABLE_, %eax
|
|
|
|
|
2019-08-20 16:43:47 +08:00
|
|
|
// .got.plt - 0x4011c0 = 0x403280 - 0x4011c0 = 8384
|
2015-09-29 21:36:32 +08:00
|
|
|
// CHECK: Disassembly of section .R_386_GOTPC:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2015-09-29 21:36:32 +08:00
|
|
|
// CHECK-NEXT: R_386_GOTPC:
|
2019-08-20 16:43:47 +08:00
|
|
|
// CHECK-NEXT: 4011c0: movl $8384, %eax
|
2015-09-29 21:51:43 +08:00
|
|
|
|
|
|
|
.section .dynamic_reloc, "ax",@progbits
|
2015-10-09 02:58:10 +08:00
|
|
|
call bar
|
2019-08-20 16:43:47 +08:00
|
|
|
// .plt + 16 - (0x4011c5 + 5) = 0x4011e0 + 16 - 0x4011ca = 38
|
2015-09-29 21:51:43 +08:00
|
|
|
// CHECK: Disassembly of section .dynamic_reloc:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2015-09-29 21:51:43 +08:00
|
|
|
// CHECK-NEXT: .dynamic_reloc:
|
2019-08-20 16:43:47 +08:00
|
|
|
// CHECK-NEXT: 4011c5: calll 38 <bar@plt>
|
2015-09-29 22:42:37 +08:00
|
|
|
|
|
|
|
.section .R_386_GOT32,"ax",@progbits
|
|
|
|
.global R_386_GOT32
|
|
|
|
R_386_GOT32:
|
2016-01-19 19:00:48 +08:00
|
|
|
movl bar@GOT, %eax
|
|
|
|
movl zed@GOT, %eax
|
|
|
|
movl bar+8@GOT, %eax
|
|
|
|
movl zed+4@GOT, %eax
|
|
|
|
|
2019-08-20 16:43:47 +08:00
|
|
|
// &.got[0] - .got.plt = 0x402278 - 0x403280 = 4294963192
|
|
|
|
// &.got[1] - .got.plt = 0x402278 + 4 - 0x403280 = 4294963196
|
|
|
|
// &.got[2] - .got.plt = 0x402278 + 8 - 0x403280 = 4294963200
|
2015-09-29 22:42:37 +08:00
|
|
|
// CHECK: Disassembly of section .R_386_GOT32:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2015-09-29 22:42:37 +08:00
|
|
|
// CHECK-NEXT: R_386_GOT32:
|
2019-08-20 16:43:47 +08:00
|
|
|
// CHECK-NEXT: 4011ca: movl 4294963192, %eax
|
|
|
|
// CHECK-NEXT: movl 4294963196, %eax
|
|
|
|
// CHECK-NEXT: movl 4294963200, %eax
|
|
|
|
// CHECK-NEXT: movl 4294963200, %eax
|