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 assignFileOffsetsBinary();
void setPhdrs(); void setPhdrs();
void fixSectionAlignments(); void fixSectionAlignments();
void makeMipsGpAbs();
void openFile(); void openFile();
void writeTrapInstr(); void writeTrapInstr();
void writeHeader(); void writeHeader();
@ -216,8 +215,6 @@ template <class ELFT> void Writer<ELFT>::run() {
if (Config->Relocatable) { if (Config->Relocatable) {
for (OutputSection *Sec : OutputSections) for (OutputSection *Sec : OutputSections)
Sec->Addr = 0; Sec->Addr = 0;
} else {
makeMipsGpAbs();
} }
// It does not make sense try to open the file if we have error already. // 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; 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() { template <class ELFT> void Writer<ELFT>::writeHeader() {
uint8_t *Buf = Buffer->getBufferStart(); uint8_t *Buf = Buffer->getBufferStart();
memcpy(Buf, "\177ELF", 4); memcpy(Buf, "\177ELF", 4);

View File

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

View File

@ -12,7 +12,7 @@
# CHECK-NEXT: 10004: 03 99 e0 2d daddu $gp, $gp, $25 # CHECK-NEXT: 10004: 03 99 e0 2d daddu $gp, $gp, $25
# CHECK-NEXT: 10008: 67 9c 7f f0 daddiu $gp, $gp, 32752 # 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 # CHECK: 0000000000010000 .text 00000000 foo
.text .text

View File

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

View File

@ -47,7 +47,7 @@ v1:
# EXE_SYM: Sections: # EXE_SYM: Sections:
# EXE_SYM: .got 0000000c 0000000000030010 DATA # EXE_SYM: .got 0000000c 0000000000030010 DATA
# EXE_SYM: SYMBOL TABLE: # EXE_SYM: SYMBOL TABLE:
# EXE_SYM: 00038000 *ABS* 00000000 .hidden _gp # EXE_SYM: 00038000 .got 00000000 .hidden _gp
# ^-- .got + GP offset (0x7ff0) # ^-- .got + GP offset (0x7ff0)
# EXE_SYM: 00030000 g .data 00000004 v1 # EXE_SYM: 00030000 g .data 00000004 v1
@ -71,7 +71,7 @@ v1:
# DSO_SYM: Sections: # DSO_SYM: Sections:
# DSO_SYM: .got 0000000c 0000000000020010 DATA # DSO_SYM: .got 0000000c 0000000000020010 DATA
# DSO_SYM: SYMBOL TABLE: # DSO_SYM: SYMBOL TABLE:
# DSO_SYM: 00028000 *ABS* 00000000 .hidden _gp # DSO_SYM: 00028000 .got 00000000 .hidden _gp
# ^-- .got + GP offset (0x7ff0) # ^-- .got + GP offset (0x7ff0)
# DSO_SYM: 00020000 g .data 00000004 v1 # 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: 10000: 3c 08 00 01 lui $8, 1
# DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752 # DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752
# ^-- 0x37ff0 & 0xffff # ^-- 0x37ff0 & 0xffff
# DIS: 00027ff0 *ABS* 00000000 .hidden _gp # DIS: 00027ff0 .got 00000000 .hidden _gp
# REL: Relocations [ # REL: Relocations [
# REL-NEXT: ] # REL-NEXT: ]

View File

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

View File

@ -29,7 +29,7 @@
# DUMP: SYMBOL TABLE: # DUMP: SYMBOL TABLE:
# DUMP: 00010008 .text 00000000 bar # DUMP: 00010008 .text 00000000 bar
# DUMP: 00010004 .text 00000000 foo # 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 # ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value

View File

@ -28,4 +28,4 @@ v1:
# CHECK: SYMBOL TABLE: # CHECK: SYMBOL TABLE:
# CHECK: 00010008 .text 00000000 bar # CHECK: 00010008 .text 00000000 bar
# CHECK: 00010004 .text 00000000 foo # 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: SYMBOL TABLE:
# EXE: 0002000c .text 00000000 bar # EXE: 0002000c .text 00000000 bar
# EXE: 00038000 *ABS* 00000000 .hidden _gp # EXE: 00038000 .got 00000000 .hidden _gp
# EXE: 00020000 .text 00000000 __start # EXE: 00020000 .text 00000000 __start
# SO: Disassembly of section .text: # SO: Disassembly of section .text:
@ -51,5 +51,5 @@ bar:
# SO: SYMBOL TABLE: # SO: SYMBOL TABLE:
# SO: 0001000c .text 00000000 bar # SO: 0001000c .text 00000000 bar
# SO: 00028000 *ABS* 00000000 .hidden _gp # SO: 00028000 .got 00000000 .hidden _gp
# SO: 00010000 .text 00000000 __start # SO: 00010000 .text 00000000 __start

View File

@ -54,7 +54,7 @@
# FIXME-EL-NEXT: 20028: 00 00 00 00 nop # FIXME-EL-NEXT: 20028: 00 00 00 00 nop
# FIXME-EL-NEXT: 2002c: 00 94 e8 ff b -44 # 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: 00020000 g F .text 00000000 foo
# SYM: 00020010 .text 00000000 __start # SYM: 00020010 .text 00000000 __start

View File

@ -42,7 +42,7 @@
# ^-- loc # ^-- loc
# CHECK: 00020004 .text 00000000 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 # CHECK: 00020000 g F .text 00000000 __start
# ELF: Format: ELF32-mips # ELF: Format: ELF32-mips