Skip to content

Commit 056190c

Browse files
committed
Don't make _gp absolute.
_gp points to a position in the file, so it is not really absolute. It is also simpler to not force it to be absolute, so if there is no strong ABI requirement we should not do it. llvm-svn: 313333
1 parent 325b6c1 commit 056190c

12 files changed

+13
-24
lines changed

lld/ELF/Writer.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ template <class ELFT> class Writer {
6363
void assignFileOffsetsBinary();
6464
void setPhdrs();
6565
void fixSectionAlignments();
66-
void makeMipsGpAbs();
6766
void openFile();
6867
void writeTrapInstr();
6968
void writeHeader();
@@ -216,8 +215,6 @@ template <class ELFT> void Writer<ELFT>::run() {
216215
if (Config->Relocatable) {
217216
for (OutputSection *Sec : OutputSections)
218217
Sec->Addr = 0;
219-
} else {
220-
makeMipsGpAbs();
221218
}
222219

223220
// It does not make sense try to open the file if we have error already.
@@ -1774,14 +1771,6 @@ static uint16_t getELFType() {
17741771
return ET_EXEC;
17751772
}
17761773

1777-
// For some reason we have to make the mips gp symbol absolute.
1778-
template <class ELFT> void Writer<ELFT>::makeMipsGpAbs() {
1779-
if (ElfSym::MipsGp && ElfSym::MipsGp->Section) {
1780-
ElfSym::MipsGp->Value += cast<OutputSection>(ElfSym::MipsGp->Section)->Addr;
1781-
ElfSym::MipsGp->Section = nullptr;
1782-
}
1783-
}
1784-
17851774
template <class ELFT> void Writer<ELFT>::writeHeader() {
17861775
uint8_t *Buf = Buffer->getBufferStart();
17871776
memcpy(Buf, "\177ELF", 4);

lld/test/ELF/basic-mips.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ __start:
228228
# CHECK-NEXT: Other [ (0x2)
229229
# CHECK-NEXT: STV_HIDDEN (0x2)
230230
# CHECK-NEXT: ]
231-
# CHECK-NEXT: Section: Absolute
231+
# CHECK-NEXT: Section: .got
232232
# CHECK-NEXT: }
233233
# CHECK-NEXT: Symbol {
234234
# CHECK-NEXT: Name: __start

lld/test/ELF/mips-64-gprel-so.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# CHECK-NEXT: 10004: 03 99 e0 2d daddu $gp, $gp, $25
1313
# CHECK-NEXT: 10008: 67 9c 7f f0 daddiu $gp, $gp, 32752
1414

15-
# CHECK: 0000000000027ff0 *ABS* 00000000 .hidden _gp
15+
# CHECK: 0000000000027ff0 .got 00000000 .hidden _gp
1616
# CHECK: 0000000000010000 .text 00000000 foo
1717

1818
.text

lld/test/ELF/mips-64-rels.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# ^-- 0x20004 - 0x37ff0 = 0xfffffffffffe8014
2525

2626
# CHECK: 0000000000020004 .text 00000000 loc
27-
# CHECK: 0000000000037ff0 *ABS* 00000000 .hidden _gp
27+
# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp
2828
# CHECK: 0000000000020000 .text 00000000 __start
2929

3030
# REL: Relocations [

lld/test/ELF/mips-got-relocs.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ v1:
4747
# EXE_SYM: Sections:
4848
# EXE_SYM: .got 0000000c 0000000000030010 DATA
4949
# EXE_SYM: SYMBOL TABLE:
50-
# EXE_SYM: 00038000 *ABS* 00000000 .hidden _gp
50+
# EXE_SYM: 00038000 .got 00000000 .hidden _gp
5151
# ^-- .got + GP offset (0x7ff0)
5252
# EXE_SYM: 00030000 g .data 00000004 v1
5353

@@ -71,7 +71,7 @@ v1:
7171
# DSO_SYM: Sections:
7272
# DSO_SYM: .got 0000000c 0000000000020010 DATA
7373
# DSO_SYM: SYMBOL TABLE:
74-
# DSO_SYM: 00028000 *ABS* 00000000 .hidden _gp
74+
# DSO_SYM: 00028000 .got 00000000 .hidden _gp
7575
# ^-- .got + GP offset (0x7ff0)
7676
# DSO_SYM: 00020000 g .data 00000004 v1
7777

lld/test/ELF/mips-gp-disp.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# DIS-NEXT: 10000: 3c 08 00 01 lui $8, 1
2525
# DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752
2626
# ^-- 0x37ff0 & 0xffff
27-
# DIS: 00027ff0 *ABS* 00000000 .hidden _gp
27+
# DIS: 00027ff0 .got 00000000 .hidden _gp
2828

2929
# REL: Relocations [
3030
# REL-NEXT: ]

lld/test/ELF/mips-gp-local.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# CHECK-NEXT: 20000: 3c 08 00 03 lui $8, 3
1212
# CHECK-NEXT: 20004: 21 08 7f f0 addi $8, $8, 32752
1313

14-
# CHECK: 00037ff0 *ABS* 00000000 .hidden _gp
14+
# CHECK: 00037ff0 .got 00000000 .hidden _gp
1515

1616
.text
1717
.globl __start

lld/test/ELF/mips-gprel32-relocs-gp0.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# DUMP: SYMBOL TABLE:
3030
# DUMP: 00010008 .text 00000000 bar
3131
# DUMP: 00010004 .text 00000000 foo
32-
# DUMP: 00027ff0 *ABS* 00000000 .hidden _gp
32+
# DUMP: 00027ff0 .got 00000000 .hidden _gp
3333

3434
# ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value
3535

lld/test/ELF/mips-gprel32-relocs.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ v1:
2828
# CHECK: SYMBOL TABLE:
2929
# CHECK: 00010008 .text 00000000 bar
3030
# CHECK: 00010004 .text 00000000 foo
31-
# CHECK: 00027ff0 *ABS* 00000000 .hidden _gp
31+
# CHECK: 00027ff0 .got 00000000 .hidden _gp

lld/test/ELF/mips-hilo-gp-disp.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bar:
3434

3535
# EXE: SYMBOL TABLE:
3636
# EXE: 0002000c .text 00000000 bar
37-
# EXE: 00038000 *ABS* 00000000 .hidden _gp
37+
# EXE: 00038000 .got 00000000 .hidden _gp
3838
# EXE: 00020000 .text 00000000 __start
3939

4040
# SO: Disassembly of section .text:
@@ -51,5 +51,5 @@ bar:
5151

5252
# SO: SYMBOL TABLE:
5353
# SO: 0001000c .text 00000000 bar
54-
# SO: 00028000 *ABS* 00000000 .hidden _gp
54+
# SO: 00028000 .got 00000000 .hidden _gp
5555
# SO: 00010000 .text 00000000 __start

0 commit comments

Comments
 (0)