2018-03-29 22:03:01 +08:00
|
|
|
// REQUIRES: x86
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux -position-independent %s -o %t1.o
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux -position-independent %p/Inputs/shared.s -o %t2.o
|
|
|
|
// RUN: ld.lld -shared %t2.o -o %t2.so
|
|
|
|
|
|
|
|
// RUN: echo "SECTIONS { \
|
|
|
|
// RUN: .text : { *(.text) } \
|
|
|
|
// RUN: .plt : { *(.plt) } \
|
|
|
|
// RUN: .got.plt : { *(.got.plt) } \
|
|
|
|
// RUN: .dynstr : { *(.dynstr) } \
|
|
|
|
// RUN: }" > %t.script
|
|
|
|
// RUN: ld.lld %t1.o %t2.so -o %t.exe -z retpolineplt -pie --script %t.script
|
|
|
|
// RUN: llvm-objdump -d -s %t.exe | FileCheck %s
|
|
|
|
|
|
|
|
// CHECK: Disassembly of section .plt:
|
2019-05-01 18:40:48 +08:00
|
|
|
// CHECK-EMPTY:
|
2018-03-29 22:03:01 +08:00
|
|
|
// CHECK-NEXT: .plt:
|
[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
|
|
|
// CHECK-NEXT: 10: ff b3 04 00 00 00 pushl 4(%ebx)
|
2018-03-29 22:03:01 +08:00
|
|
|
// CHECK-NEXT: 16: 50 pushl %eax
|
[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
|
|
|
// CHECK-NEXT: 17: 8b 83 08 00 00 00 movl 8(%ebx), %eax
|
2018-03-29 22:03:01 +08:00
|
|
|
// CHECK-NEXT: 1d: e8 0e 00 00 00 calll 14 <.plt+0x20>
|
|
|
|
// CHECK-NEXT: 22: f3 90 pause
|
|
|
|
// CHECK-NEXT: 24: 0f ae e8 lfence
|
|
|
|
// CHECK-NEXT: 27: eb f9 jmp -7 <.plt+0x12>
|
|
|
|
// CHECK-NEXT: 29: cc int3
|
|
|
|
// CHECK-NEXT: 2a: cc int3
|
|
|
|
// CHECK-NEXT: 2b: cc int3
|
|
|
|
// CHECK-NEXT: 2c: cc int3
|
|
|
|
// CHECK-NEXT: 2d: cc int3
|
|
|
|
// CHECK-NEXT: 2e: cc int3
|
|
|
|
// CHECK-NEXT: 2f: cc int3
|
|
|
|
// CHECK-NEXT: 30: 89 0c 24 movl %ecx, (%esp)
|
|
|
|
// CHECK-NEXT: 33: 8b 4c 24 04 movl 4(%esp), %ecx
|
|
|
|
// CHECK-NEXT: 37: 89 44 24 04 movl %eax, 4(%esp)
|
|
|
|
// CHECK-NEXT: 3b: 89 c8 movl %ecx, %eax
|
|
|
|
// CHECK-NEXT: 3d: 59 popl %ecx
|
|
|
|
// CHECK-NEXT: 3e: c3 retl
|
|
|
|
// CHECK-NEXT: 3f: cc int3
|
|
|
|
// CHECK-NEXT: 40: 50 pushl %eax
|
[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
|
|
|
// CHECK-NEXT: 41: 8b 83 0c 00 00 00 movl 12(%ebx), %eax
|
2018-03-29 22:03:01 +08:00
|
|
|
// CHECK-NEXT: 47: e8 e4 ff ff ff calll -28 <.plt+0x20>
|
|
|
|
// CHECK-NEXT: 4c: e9 d1 ff ff ff jmp -47 <.plt+0x12>
|
|
|
|
// CHECK-NEXT: 51: 68 00 00 00 00 pushl $0
|
|
|
|
// CHECK-NEXT: 56: e9 b5 ff ff ff jmp -75 <.plt>
|
|
|
|
// CHECK-NEXT: 5b: cc int3
|
|
|
|
// CHECK-NEXT: 5c: cc int3
|
|
|
|
// CHECK-NEXT: 5d: cc int3
|
|
|
|
// CHECK-NEXT: 5e: cc int3
|
|
|
|
// CHECK-NEXT: 5f: cc int3
|
|
|
|
// CHECK-NEXT: 60: 50 pushl %eax
|
[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
|
|
|
// CHECK-NEXT: 61: 8b 83 10 00 00 00 movl 16(%ebx), %eax
|
2018-03-29 22:03:01 +08:00
|
|
|
// CHECK-NEXT: 67: e8 c4 ff ff ff calll -60 <.plt+0x20>
|
|
|
|
// CHECK-NEXT: 6c: e9 b1 ff ff ff jmp -79 <.plt+0x12>
|
|
|
|
// CHECK-NEXT: 71: 68 08 00 00 00 pushl $8
|
|
|
|
// CHECK-NEXT: 76: e9 95 ff ff ff jmp -107 <.plt>
|
|
|
|
// CHECK-NEXT: 7b: cc int3
|
|
|
|
// CHECK-NEXT: 7c: cc int3
|
|
|
|
// CHECK-NEXT: 7d: cc int3
|
|
|
|
// CHECK-NEXT: 7e: cc int3
|
|
|
|
// CHECK-NEXT: 7f: cc int3
|
|
|
|
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
jmp bar@PLT
|
|
|
|
jmp zed@PLT
|