[lld][X86] Restore gotEntrySize.
D62727 removed GotEntrySize and GotPltEntrySize with a comment that they are always equal to wordsize(), but that is not entirely true: X32 has a word size of 4, but needs 8-byte GOT entries. This restores gotEntrySize for both, adjusted for current naming conventions, but defaults it to config->wordsize to keep things simple for architectures other than x86_64. This partially reverts D62727. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D102509
This commit is contained in:
parent
7f5d8e6559
commit
d62413452f
@ -85,6 +85,7 @@ X86_64::X86_64() {
|
||||
tlsGotRel = R_X86_64_TPOFF64;
|
||||
tlsModuleIndexRel = R_X86_64_DTPMOD64;
|
||||
tlsOffsetRel = R_X86_64_DTPOFF64;
|
||||
gotEntrySize = 8;
|
||||
pltHeaderSize = 16;
|
||||
pltEntrySize = 16;
|
||||
ipltEntrySize = 16;
|
||||
|
@ -160,7 +160,9 @@ uint64_t Symbol::getGotVA() const {
|
||||
return in.got->getVA() + getGotOffset();
|
||||
}
|
||||
|
||||
uint64_t Symbol::getGotOffset() const { return gotIndex * config->wordsize; }
|
||||
uint64_t Symbol::getGotOffset() const {
|
||||
return gotIndex * target->gotEntrySize;
|
||||
}
|
||||
|
||||
uint64_t Symbol::getGotPltVA() const {
|
||||
if (isInIplt)
|
||||
@ -170,8 +172,8 @@ uint64_t Symbol::getGotPltVA() const {
|
||||
|
||||
uint64_t Symbol::getGotPltOffset() const {
|
||||
if (isInIplt)
|
||||
return pltIndex * config->wordsize;
|
||||
return (pltIndex + target->gotPltHeaderEntriesNum) * config->wordsize;
|
||||
return pltIndex * target->gotEntrySize;
|
||||
return (pltIndex + target->gotPltHeaderEntriesNum) * target->gotEntrySize;
|
||||
}
|
||||
|
||||
uint64_t Symbol::getPltVA() const {
|
||||
|
@ -644,8 +644,8 @@ void EhFrameSection::writeTo(uint8_t *buf) {
|
||||
}
|
||||
|
||||
GotSection::GotSection()
|
||||
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, config->wordsize,
|
||||
".got") {
|
||||
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
|
||||
target->gotEntrySize, ".got") {
|
||||
numEntries = target->gotHeaderEntriesNum;
|
||||
}
|
||||
|
||||
@ -1145,15 +1145,16 @@ void GotPltSection::addEntry(Symbol &sym) {
|
||||
}
|
||||
|
||||
size_t GotPltSection::getSize() const {
|
||||
return (target->gotPltHeaderEntriesNum + entries.size()) * config->wordsize;
|
||||
return (target->gotPltHeaderEntriesNum + entries.size()) *
|
||||
target->gotEntrySize;
|
||||
}
|
||||
|
||||
void GotPltSection::writeTo(uint8_t *buf) {
|
||||
target->writeGotPltHeader(buf);
|
||||
buf += target->gotPltHeaderEntriesNum * config->wordsize;
|
||||
buf += target->gotPltHeaderEntriesNum * target->gotEntrySize;
|
||||
for (const Symbol *b : entries) {
|
||||
target->writeGotPlt(buf, *b);
|
||||
buf += config->wordsize;
|
||||
buf += target->gotEntrySize;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1181,7 +1182,7 @@ static StringRef getIgotPltName() {
|
||||
IgotPltSection::IgotPltSection()
|
||||
: SyntheticSection(SHF_ALLOC | SHF_WRITE,
|
||||
config->emachine == EM_PPC64 ? SHT_NOBITS : SHT_PROGBITS,
|
||||
config->wordsize, getIgotPltName()) {}
|
||||
target->gotEntrySize, getIgotPltName()) {}
|
||||
|
||||
void IgotPltSection::addEntry(Symbol &sym) {
|
||||
assert(sym.pltIndex == entries.size());
|
||||
@ -1189,13 +1190,13 @@ void IgotPltSection::addEntry(Symbol &sym) {
|
||||
}
|
||||
|
||||
size_t IgotPltSection::getSize() const {
|
||||
return entries.size() * config->wordsize;
|
||||
return entries.size() * target->gotEntrySize;
|
||||
}
|
||||
|
||||
void IgotPltSection::writeTo(uint8_t *buf) {
|
||||
for (const Symbol *b : entries) {
|
||||
target->writeIgotPlt(buf, *b);
|
||||
buf += config->wordsize;
|
||||
buf += target->gotEntrySize;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
RelType tlsGotRel;
|
||||
RelType tlsModuleIndexRel;
|
||||
RelType tlsOffsetRel;
|
||||
unsigned gotEntrySize = config->wordsize;
|
||||
unsigned pltEntrySize;
|
||||
unsigned pltHeaderSize;
|
||||
unsigned ipltEntrySize;
|
||||
|
52
lld/test/ELF/x86-x32-plt.s
Normal file
52
lld/test/ELF/x86-x32-plt.s
Normal file
@ -0,0 +1,52 @@
|
||||
# REQUIRES: x86
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-gnux32 %s -o %t.o
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-gnux32 %p/Inputs/shared.s -o %t2.o
|
||||
# RUN: ld.lld -shared -soname=t2 %t2.o -o %t2.so
|
||||
|
||||
# RUN: ld.lld %t.o %t2.so -o %t
|
||||
# RUN: llvm-readelf -S -r %t | FileCheck %s
|
||||
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefixes=DISASM
|
||||
|
||||
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
|
||||
# CHECK: .plt PROGBITS 002011e0 0001e0 000030 00 AX 0 0 16
|
||||
# CHECK: .got.plt PROGBITS 00203278 000278 000028 00 WA 0 0 8
|
||||
# CHECK: Relocation section '.rela.plt' at offset {{.*}} contains 2 entries:
|
||||
# CHECK: 00203290 {{.*}} R_X86_64_JUMP_SLOT 00000000 bar + 0
|
||||
# CHECK-NEXT: 00203298 {{.*}} R_X86_64_JUMP_SLOT 00000000 weak + 0
|
||||
|
||||
# DISASM: <_start>:
|
||||
# DISASM-NEXT: callq {{.*}} <local>
|
||||
# DISASM-NEXT: callq {{.*}} <bar@plt>
|
||||
# DISASM-NEXT: jmp {{.*}} <bar@plt>
|
||||
# DISASM-NEXT: jmp {{.*}} <weak@plt>
|
||||
|
||||
# DISASM: Disassembly of section .plt:
|
||||
# DISASM-EMPTY:
|
||||
# DISASM-NEXT: <.plt>:
|
||||
# DISASM-NEXT: 2011e0: pushq 8346(%rip) # 203280
|
||||
# DISASM-NEXT: jmpq *8348(%rip) # 203288
|
||||
# DISASM-NEXT: nopl (%rax)
|
||||
# DISASM-EMPTY:
|
||||
# DISASM-NEXT: <bar@plt>:
|
||||
# DISASM-NEXT: 2011f0: jmpq *8346(%rip) # 203290
|
||||
# DISASM-NEXT: pushq $0
|
||||
# DISASM-NEXT: jmp 0x2011e0 <.plt>
|
||||
# DISASM-EMPTY:
|
||||
# DISASM-NEXT: <weak@plt>:
|
||||
# DISASM-NEXT: 201200: jmpq *8338(%rip) # 203298
|
||||
# DISASM-NEXT: pushq $1
|
||||
# DISASM-NEXT: jmp 0x2011e0 <.plt>
|
||||
# DISASM-NOT: {{.}}
|
||||
|
||||
.global _start
|
||||
.weak weak
|
||||
|
||||
_start:
|
||||
call local
|
||||
call bar
|
||||
jmp bar@plt
|
||||
jmp weak
|
||||
|
||||
## foo is local and non-preemptale, no PLT is generated.
|
||||
local:
|
||||
ret
|
Loading…
x
Reference in New Issue
Block a user