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
This commit is contained in:
Rafael Espindola 2017-09-15 01:49:01 +00:00
parent 325b6c1efe
commit 056190c348
12 changed files with 13 additions and 24 deletions

View File

@ -63,7 +63,6 @@ private:
void assignFileOffsetsBinary();
void setPhdrs();
void fixSectionAlignments();
void makeMipsGpAbs();
void openFile();
void writeTrapInstr();
void writeHeader();
@ -216,8 +215,6 @@ template <class ELFT> void Writer<ELFT>::run() {
if (Config->Relocatable) {
for (OutputSection *Sec : OutputSections)
Sec->Addr = 0;
} else {
makeMipsGpAbs();
}
// It does not make sense try to open the file if we have error already.
@ -1774,14 +1771,6 @@ static uint16_t getELFType() {
return ET_EXEC;
}
// For some reason we have to make the mips gp symbol absolute.
template <class ELFT> void Writer<ELFT>::makeMipsGpAbs() {
if (ElfSym::MipsGp && ElfSym::MipsGp->Section) {
ElfSym::MipsGp->Value += cast<OutputSection>(ElfSym::MipsGp->Section)->Addr;
ElfSym::MipsGp->Section = nullptr;
}
}
template <class ELFT> void Writer<ELFT>::writeHeader() {
uint8_t *Buf = Buffer->getBufferStart();
memcpy(Buf, "\177ELF", 4);

View File

@ -228,7 +228,7 @@ __start:
# CHECK-NEXT: Other [ (0x2)
# CHECK-NEXT: STV_HIDDEN (0x2)
# CHECK-NEXT: ]
# CHECK-NEXT: Section: Absolute
# CHECK-NEXT: Section: .got
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: __start

View File

@ -12,7 +12,7 @@
# CHECK-NEXT: 10004: 03 99 e0 2d daddu $gp, $gp, $25
# CHECK-NEXT: 10008: 67 9c 7f f0 daddiu $gp, $gp, 32752
# CHECK: 0000000000027ff0 *ABS* 00000000 .hidden _gp
# CHECK: 0000000000027ff0 .got 00000000 .hidden _gp
# CHECK: 0000000000010000 .text 00000000 foo
.text

View File

@ -24,7 +24,7 @@
# ^-- 0x20004 - 0x37ff0 = 0xfffffffffffe8014
# CHECK: 0000000000020004 .text 00000000 loc
# CHECK: 0000000000037ff0 *ABS* 00000000 .hidden _gp
# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp
# CHECK: 0000000000020000 .text 00000000 __start
# REL: Relocations [

View File

@ -47,7 +47,7 @@ v1:
# EXE_SYM: Sections:
# EXE_SYM: .got 0000000c 0000000000030010 DATA
# EXE_SYM: SYMBOL TABLE:
# EXE_SYM: 00038000 *ABS* 00000000 .hidden _gp
# EXE_SYM: 00038000 .got 00000000 .hidden _gp
# ^-- .got + GP offset (0x7ff0)
# EXE_SYM: 00030000 g .data 00000004 v1
@ -71,7 +71,7 @@ v1:
# DSO_SYM: Sections:
# DSO_SYM: .got 0000000c 0000000000020010 DATA
# DSO_SYM: SYMBOL TABLE:
# DSO_SYM: 00028000 *ABS* 00000000 .hidden _gp
# DSO_SYM: 00028000 .got 00000000 .hidden _gp
# ^-- .got + GP offset (0x7ff0)
# DSO_SYM: 00020000 g .data 00000004 v1

View File

@ -24,7 +24,7 @@
# DIS-NEXT: 10000: 3c 08 00 01 lui $8, 1
# DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752
# ^-- 0x37ff0 & 0xffff
# DIS: 00027ff0 *ABS* 00000000 .hidden _gp
# DIS: 00027ff0 .got 00000000 .hidden _gp
# REL: Relocations [
# REL-NEXT: ]

View File

@ -11,7 +11,7 @@
# CHECK-NEXT: 20000: 3c 08 00 03 lui $8, 3
# CHECK-NEXT: 20004: 21 08 7f f0 addi $8, $8, 32752
# CHECK: 00037ff0 *ABS* 00000000 .hidden _gp
# CHECK: 00037ff0 .got 00000000 .hidden _gp
.text
.globl __start

View File

@ -29,7 +29,7 @@
# DUMP: SYMBOL TABLE:
# DUMP: 00010008 .text 00000000 bar
# DUMP: 00010004 .text 00000000 foo
# DUMP: 00027ff0 *ABS* 00000000 .hidden _gp
# DUMP: 00027ff0 .got 00000000 .hidden _gp
# ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value

View File

@ -28,4 +28,4 @@ v1:
# CHECK: SYMBOL TABLE:
# CHECK: 00010008 .text 00000000 bar
# CHECK: 00010004 .text 00000000 foo
# CHECK: 00027ff0 *ABS* 00000000 .hidden _gp
# CHECK: 00027ff0 .got 00000000 .hidden _gp

View File

@ -34,7 +34,7 @@ bar:
# EXE: SYMBOL TABLE:
# EXE: 0002000c .text 00000000 bar
# EXE: 00038000 *ABS* 00000000 .hidden _gp
# EXE: 00038000 .got 00000000 .hidden _gp
# EXE: 00020000 .text 00000000 __start
# SO: Disassembly of section .text:
@ -51,5 +51,5 @@ bar:
# SO: SYMBOL TABLE:
# SO: 0001000c .text 00000000 bar
# SO: 00028000 *ABS* 00000000 .hidden _gp
# SO: 00028000 .got 00000000 .hidden _gp
# SO: 00010000 .text 00000000 __start

View File

@ -54,7 +54,7 @@
# FIXME-EL-NEXT: 20028: 00 00 00 00 nop
# FIXME-EL-NEXT: 2002c: 00 94 e8 ff b -44
# SYM: 00037ff0 *ABS* 00000000 .hidden _gp
# SYM: 00037ff0 .got 00000000 .hidden _gp
# SYM: 00020000 g F .text 00000000 foo
# SYM: 00020010 .text 00000000 __start

View File

@ -42,7 +42,7 @@
# ^-- loc
# CHECK: 00020004 .text 00000000 loc
# CHECK: 00037ff0 *ABS* 00000000 .hidden _gp
# CHECK: 00037ff0 .got 00000000 .hidden _gp
# CHECK: 00020000 g F .text 00000000 __start
# ELF: Format: ELF32-mips