GotSection::GotSection()
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, config->wordsize,
".got") {
- // If ElfSym::globalOffsetTable is relative to .got and is referenced,
- // increase numEntries by the number of entries used to emit
- // ElfSym::globalOffsetTable.
- // On PP64 we always add the header at the start.
- if ((ElfSym::globalOffsetTable && !target->gotBaseSymInGotPlt) ||
- config->emachine == EM_PPC64)
- numEntries += target->gotHeaderEntriesNum;
+ numEntries = target->gotHeaderEntriesNum;
}
void GotSection::addEntry(Symbol &sym) {
}
bool GotSection::isNeeded() const {
- // We need to emit a GOT even if it's empty if there's a relocation that is
- // relative to GOT(such as GOTOFFREL).
-
- // On PPC64 we need to check that the number of entries is more than just the
- // size of the header since the header is always added. A GOT with just the
- // header may not actually be needed.
- if (config->emachine == EM_PPC64)
- return numEntries > target->gotHeaderEntriesNum || hasGotOffRel;
-
- return numEntries || hasGotOffRel;
+ // Needed if the GOT symbol is used or the number of entries is more than just
+ // the header. A GOT with just the header may not be needed.
+ return hasGotOffRel || numEntries > target->gotHeaderEntriesNum;
}
void GotSection::writeTo(uint8_t *buf) {
# GD-DYN: PPC_GOT 0x20358
# GD-REL: .rela.dyn {
-# GD-REL-NEXT: 0x20358 R_PPC_DTPMOD32 a 0x0
-# GD-REL-NEXT: 0x2035C R_PPC_DTPREL32 a 0x0
-# GD-REL-NEXT: 0x20360 R_PPC_DTPMOD32 b 0x0
-# GD-REL-NEXT: 0x20364 R_PPC_DTPREL32 b 0x0
-# GD-REL-NEXT: 0x20368 R_PPC_DTPMOD32 c 0x0
-# GD-REL-NEXT: 0x2036C R_PPC_DTPREL32 c 0x0
+# GD-REL-NEXT: 0x20364 R_PPC_DTPMOD32 a 0x0
+# GD-REL-NEXT: 0x20368 R_PPC_DTPREL32 a 0x0
+# GD-REL-NEXT: 0x2036C R_PPC_DTPMOD32 b 0x0
+# GD-REL-NEXT: 0x20370 R_PPC_DTPREL32 b 0x0
+# GD-REL-NEXT: 0x20374 R_PPC_DTPMOD32 c 0x0
+# GD-REL-NEXT: 0x20378 R_PPC_DTPREL32 c 0x0
# GD-REL-NEXT: }
-## &DTPMOD(a) - _GLOBAL_OFFSET_TABLE_ = 0x20078 - 0x20078 = 0
-# GD: addi 3, 31, 0
+## &DTPMOD(a) - _GLOBAL_OFFSET_TABLE_ = 12
+# GD: addi 3, 31, 12
# GD-NEXT: bl 0x1028c
# GD-NEXT: lwz 3, 0(3)
-## &DTPMOD(b) - _GLOBAL_OFFSET_TABLE_ = 0x20080 - 0x20078 = 8
-# GD-NEXT: addi 3, 31, 8
+## &DTPMOD(b) - _GLOBAL_OFFSET_TABLE_ = 20
+# GD-NEXT: addi 3, 31, 20
# GD-NEXT: bl 0x1028c
# GD-NEXT: lwz 3, 0(3)
-## &DTPMOD(c) - _GLOBAL_OFFSET_TABLE_ = 0x20088 - 0x20078 = 16
-# GD-NEXT: addi 3, 9, 16
+## &DTPMOD(c) - _GLOBAL_OFFSET_TABLE_ = 28
+# GD-NEXT: addi 3, 9, 28
# GD-NEXT: bl 0x1028c
# GD-NEXT: lwz 3, 0(3)
# LE-NEXT: lwz 3, 0(3)
# IE-REL: .rela.dyn {
-# IE-REL-NEXT: 0x10020274 R_PPC_TPREL32 b 0x0
-# IE-REL-NEXT: 0x10020278 R_PPC_TPREL32 c 0x0
+# IE-REL-NEXT: 0x10020280 R_PPC_TPREL32 b 0x0
+# IE-REL-NEXT: 0x10020284 R_PPC_TPREL32 c 0x0
# IE-REL-NEXT: }
## a is relaxed to use LE.
# IE: addis 3, 2, 0
# IE-NEXT: addi 3, 3, -28664
# IE-NEXT: lwz 3, 0(3)
-## &.got[0] - _GLOBAL_OFFSET_TABLE_ = 0
-# IE-NEXT: lwz 3, 0(31)
+## &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12
+# IE-NEXT: lwz 3, 12(31)
# IE-NEXT: add 3, 3, 2
# IE-NEXT: lwz 3, 0(3)
-## &.got[1] - _GLOBAL_OFFSET_TABLE_ = 4
-# IE-NEXT: lwz 3, 4(9)
+## &.got[4] - _GLOBAL_OFFSET_TABLE_ = 16
+# IE-NEXT: lwz 3, 16(9)
# IE-NEXT: add 3, 3, 2
# IE-NEXT: lwz 3, 0(3)
## A non-preemptable symbol (b) has 0 st_shndx.
# IE-REL: .rela.dyn {
-# IE-REL-NEXT: 0x20224 R_PPC_TPREL32 - 0xC
-# IE-REL-NEXT: 0x20220 R_PPC_TPREL32 a 0x0
+# IE-REL-NEXT: 0x20230 R_PPC_TPREL32 - 0xC
+# IE-REL-NEXT: 0x2022C R_PPC_TPREL32 a 0x0
# IE-REL-NEXT: }
-## &.got[0] - _GLOBAL_OFFSET_TABLE_ = 0
-# IE: lwz 10, 0(9)
+## &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12
+# IE: lwz 10, 12(9)
# IE-NEXT: add 10, 10, 2
-## &.got[1] - _GLOBAL_OFFSET_TABLE_ = 4
-# IE-NEXT: lwz 8, 4(7)
+## &.got[4] - _GLOBAL_OFFSET_TABLE_ = 16
+# IE-NEXT: lwz 8, 16(7)
# IE-NEXT: lbzx 10, 8, 2
# NOREL: no relocations
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
# LD-REL: .rela.dyn {
-# LD-REL-NEXT: 0x202C4 R_PPC_DTPMOD32 - 0x0
+# LD-REL-NEXT: 0x202D0 R_PPC_DTPMOD32 - 0x0
# LD-REL-NEXT: }
-## .got - _GLOBAL_OFFSET_TABLE_ = 0
-# LD: addi 3, 30, 0
+## &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12
+# LD: addi 3, 30, 12
# LD-NEXT: bl 0x101f8
## a@dtprel = st_value(a)-0x8000 = 65540-0x8000 = 65536*1-32764
## b@dtprel = st_value(a)-0x8000 = 131080-0x8000 = 65536*2-32760
## Check that b@got@tlsld does not allocate another GOT entry.
## It shares In.Got->TlsIndexOff allocated when processing a@got@tlsld.
-## .got - _GLOBAL_OFFSET_TABLE_ = 0
-# LD-NEXT: addi 3, 9, 0
+## &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12
+# LD-NEXT: addi 3, 9, 12
# LD-NEXT: bl 0x101f8
## b@dtprel = st_value(a)-0x8000 = 131080-0x8000 = 65536*2-32760
# LD-NEXT: addis 29, 3, 2
# RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=IE64-GOT %s
# GD32-REL: .rela.dyn {
-# GD32-REL-NEXT: 0x2310 R_RISCV_TLS_DTPMOD32 a 0x0
-# GD32-REL-NEXT: 0x2314 R_RISCV_TLS_DTPREL32 a 0x0
-# GD32-REL-NEXT: 0x2318 R_RISCV_TLS_DTPMOD32 b 0x0
-# GD32-REL-NEXT: 0x231C R_RISCV_TLS_DTPREL32 b 0x0
+# GD32-REL-NEXT: 0x2314 R_RISCV_TLS_DTPMOD32 a 0x0
+# GD32-REL-NEXT: 0x2318 R_RISCV_TLS_DTPREL32 a 0x0
+# GD32-REL-NEXT: 0x231C R_RISCV_TLS_DTPMOD32 b 0x0
+# GD32-REL-NEXT: 0x2320 R_RISCV_TLS_DTPREL32 b 0x0
# GD32-REL-NEXT: }
-## &DTPMOD(a) - . = 0x2310 - 0x1250 = 4096*1+192
+## &DTPMOD(a) - . = 0x2314 - 0x1250 = 4096*1+196
# GD32: 1250: auipc a0, 1
-# GD32-NEXT: addi a0, a0, 192
+# GD32-NEXT: addi a0, a0, 196
# GD32-NEXT: auipc ra, 0
# GD32-NEXT: jalr 56(ra)
-## &DTPMOD(b) - . = 0x2318 - 0x1260 = 4096*1+184
+## &DTPMOD(b) - . = 0x231C - 0x1260 = 4096*1+188
# GD32: 1260: auipc a0, 1
-# GD32-NEXT: addi a0, a0, 184
+# GD32-NEXT: addi a0, a0, 188
# GD32-NEXT: auipc ra, 0
# GD32-NEXT: jalr 40(ra)
# GD64-REL: .rela.dyn {
-# GD64-REL-NEXT: 0x24D0 R_RISCV_TLS_DTPMOD64 a 0x0
-# GD64-REL-NEXT: 0x24D8 R_RISCV_TLS_DTPREL64 a 0x0
-# GD64-REL-NEXT: 0x24E0 R_RISCV_TLS_DTPMOD64 b 0x0
-# GD64-REL-NEXT: 0x24E8 R_RISCV_TLS_DTPREL64 b 0x0
+# GD64-REL-NEXT: 0x24D8 R_RISCV_TLS_DTPMOD64 a 0x0
+# GD64-REL-NEXT: 0x24E0 R_RISCV_TLS_DTPREL64 a 0x0
+# GD64-REL-NEXT: 0x24E8 R_RISCV_TLS_DTPMOD64 b 0x0
+# GD64-REL-NEXT: 0x24F0 R_RISCV_TLS_DTPREL64 b 0x0
# GD64-REL-NEXT: }
-## &DTPMOD(a) - . = 0x24d0 - 0x1398 = 4096*1+312
+## &DTPMOD(a) - . = 0x24d8 - 0x1398 = 4096*1+320
# GD64: 1398: auipc a0, 1
-# GD64-NEXT: addi a0, a0, 312
+# GD64-NEXT: addi a0, a0, 320
# GD64-NEXT: auipc ra, 0
# GD64-NEXT: jalr 64(ra)
-## &DTPMOD(b) - . = 0x24e0 - 0x13a8 = 4096*1+312
+## &DTPMOD(b) - . = 0x24e8 - 0x13a8 = 4096*1+320
# GD64: 13a8: auipc a0, 1
-# GD64-NEXT: addi a0, a0, 312
+# GD64-NEXT: addi a0, a0, 320
# GD64-NEXT: auipc ra, 0
# GD64-NEXT: jalr 48(ra)
## a@dtprel = st_value(a)-0x800 = 0xfffff808
## b@dtprel = st_value(b)-0x800 = 0xfffff80c
# LE32-GOT: section '.got':
-# LE32-GOT-NEXT: 0x{{[0-9a-f]+}} 01000000 08f8ffff 01000000 0cf8ffff
+# LE32-GOT-NEXT: 0x[[#%x,A:]] [[#%x,GOT:]] 01000000 08f8ffff 01000000
+# LE32-GOT-NEXT: 0x[[#%x,A:]] 0cf8ffff
# LE64-GOT: section '.got':
-# LE64-GOT-NEXT: 0x{{[0-9a-f]+}} 01000000 00000000 08f8ffff ffffffff
-# LE64-GOT-NEXT: 0x{{[0-9a-f]+}} 01000000 00000000 0cf8ffff ffffffff
+# LE64-GOT-NEXT: 0x[[#%x,A:]] [[#%x,GOT:]] [[#%x,GOT:]] 01000000 00000000
+# LE64-GOT-NEXT: 0x[[#%x,A:]] 08f8ffff ffffffff 01000000 00000000
+# LE64-GOT-NEXT: 0x[[#%x,A:]] 0cf8ffff ffffffff
## a is local - relaxed to LE - its DTPMOD/DTPREL slots are link-time constants.
## b is external - DTPMOD/DTPREL dynamic relocations are required.
# IE32-REL: .rela.dyn {
-# IE32-REL-NEXT: 0x12230 R_RISCV_TLS_DTPMOD32 b 0x0
-# IE32-REL-NEXT: 0x12234 R_RISCV_TLS_DTPREL32 b 0x0
+# IE32-REL-NEXT: 0x12234 R_RISCV_TLS_DTPMOD32 b 0x0
+# IE32-REL-NEXT: 0x12238 R_RISCV_TLS_DTPREL32 b 0x0
# IE32-REL-NEXT: }
# IE32-GOT: section '.got':
-# IE32-GOT-NEXT: 0x00012228 01000000 08f8ffff 00000000 00000000
+# IE32-GOT-NEXT: 0x00012228 c8210100 01000000 08f8ffff 00000000
+# IE32-GOT-NEXT: 0x00012238 00000000
# IE64-REL: .rela.dyn {
-# IE64-REL-NEXT: 0x12390 R_RISCV_TLS_DTPMOD64 b 0x0
-# IE64-REL-NEXT: 0x12398 R_RISCV_TLS_DTPREL64 b 0x0
+# IE64-REL-NEXT: 0x12398 R_RISCV_TLS_DTPMOD64 b 0x0
+# IE64-REL-NEXT: 0x123A0 R_RISCV_TLS_DTPREL64 b 0x0
# IE64-REL-NEXT: }
# IE64-GOT: section '.got':
-# IE64-GOT-NEXT: 0x00012380 01000000 00000000 08f8ffff ffffffff
-# IE64-GOT-NEXT: 0x00012390 00000000 00000000 00000000 00000000
+# IE64-GOT-NEXT: 0x00012380 c0220100 00000000 01000000 00000000
+# IE64-GOT-NEXT: 0x00012390 08f8ffff ffffffff 00000000 00000000
+# IE64-GOT-NEXT: 0x000123a0 00000000 00000000
la.tls.gd a0,a
call __tls_get_addr@plt
# IE32-REL: FLAGS STATIC_TLS
# IE32-REL: .rela.dyn {
-# IE32-REL-NEXT: 0x2218 R_RISCV_TLS_TPREL32 - 0xC
-# IE32-REL-NEXT: 0x2214 R_RISCV_TLS_TPREL32 a 0x0
+# IE32-REL-NEXT: 0x221C R_RISCV_TLS_TPREL32 - 0xC
+# IE32-REL-NEXT: 0x2218 R_RISCV_TLS_TPREL32 a 0x0
# IE32-REL-NEXT: }
# IE64-REL: FLAGS STATIC_TLS
# IE64-REL: .rela.dyn {
-# IE64-REL-NEXT: 0x2370 R_RISCV_TLS_TPREL64 - 0xC
-# IE64-REL-NEXT: 0x2368 R_RISCV_TLS_TPREL64 a 0x0
+# IE64-REL-NEXT: 0x2378 R_RISCV_TLS_TPREL64 - 0xC
+# IE64-REL-NEXT: 0x2370 R_RISCV_TLS_TPREL64 a 0x0
# IE64-REL-NEXT: }
-## rv32: &.got[0] - . = 0x2214 - . = 4096*1+112
-## rv64: &.got[0] - . = 0x2368 - . = 4096*1+200
+## rv32: &.got[0] - . = 0x2218 - . = 4096*1+116
+## rv64: &.got[0] - . = 0x2378 - . = 4096*1+208
# IE: auipc a4, 1
-# IE32-NEXT: lw a4, 112(a4)
-# IE64-NEXT: ld a4, 200(a4)
+# IE32-NEXT: lw a4, 116(a4)
+# IE64-NEXT: ld a4, 208(a4)
# IE-NEXT: add a4, a4, tp
-## rv32: &.got[1] - . = 0x2218 - . = 4096*1+104
-## rv64: &.got[1] - . = 0x2370 - . = 4096*1+196
+## rv32: &.got[1] - . = 0x221c - . = 4096*1+108
+## rv64: &.got[1] - . = 0x2378 - . = 4096*1+204
# IE: auipc a5, 1
-# IE32-NEXT: lw a5, 104(a5)
-# IE64-NEXT: ld a5, 196(a5)
+# IE32-NEXT: lw a5, 108(a5)
+# IE64-NEXT: ld a5, 204(a5)
# IE-NEXT: add a5, a5, tp
# NOREL: no relocations
# a@tprel = st_value(a) = 0x8
# b@tprel = st_value(a) = 0xc
# LE32-GOT: section '.got':
-# LE32-GOT-NEXT: 0x0001212c 08000000 0c000000
+# LE32-GOT-NEXT: 0x0001212c 00000000 08000000 0c000000
# LE64-GOT: section '.got':
-# LE64-GOT-NEXT: 0x000121e0 08000000 00000000 0c000000 00000000
+# LE64-GOT-NEXT: 0x000121e0 00000000 00000000 08000000 00000000
+# LE64-GOT-NEXT: 0x000121f0 0c000000 00000000
-## rv32: &.got[0] - . = 0x1212c - 0x11114 = 4096*1+24
-## rv64: &.got[0] - . = 0x121e0 - 0x111c8 = 4096*1+24
+## rv32: &.got[0] - . = 0x12130 - 0x11114 = 4096*1+28
+## rv64: &.got[0] - . = 0x121e8 - 0x111c8 = 4096*1+32
# LE32: 11114: auipc a4, 1
-# LE32-NEXT: lw a4, 24(a4)
+# LE32-NEXT: lw a4, 28(a4)
# LE64: 111c8: auipc a4, 1
-# LE64-NEXT: ld a4, 24(a4)
+# LE64-NEXT: ld a4, 32(a4)
# LE-NEXT: add a4, a4, tp
-## rv32: &.got[1] - . = 0x12130 - 0x11120 = 4096*1+16
-## rv64: &.got[1] - . = 0x121e8 - 0x111d4 = 4096*1+20
+## rv32: &.got[1] - . = 0x12134 - 0x11120 = 4096*1+20
+## rv64: &.got[1] - . = 0x121f0 - 0x111d4 = 4096*1+28
# LE32: 11120: auipc a5, 1
-# LE32-NEXT: lw a5, 16(a5)
+# LE32-NEXT: lw a5, 20(a5)
# LE64: 111d4: auipc a5, 1
-# LE64-NEXT: ld a5, 20(a5)
+# LE64-NEXT: ld a5, 28(a5)
# LE-NEXT: add a5, a5, tp
la.tls.ie a4,a