Devide _gp in the same spot as other mips symbols. NFC.

The test changes are just because of the symbol order.

llvm-svn: 266037
This commit is contained in:
Rafael Espindola 2016-04-12 02:24:43 +00:00
parent 58e3269aa5
commit 9b3f99e50f
6 changed files with 13 additions and 14 deletions

View File

@ -415,14 +415,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
Config->EntrySym = Symtab.addUndefined(S);
}
if (Config->EMachine == EM_MIPS) {
// Define _gp for MIPS. st_value of _gp symbol will be updated by Writer
// so that it points to an absolute address which is relative to GOT.
// See "Global Data Symbols" in Chapter 6 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
ElfSym<ELFT>::MipsGp = Symtab.addAbsolute("_gp", STV_DEFAULT);
}
for (std::unique_ptr<InputFile> &F : Files)
Symtab.addFile(std::move(F));
if (HasError)

View File

@ -928,6 +928,12 @@ OutputSectionFactory<ELFT>::createKey(InputSectionBase<ELFT> *C,
// the linking result. This function defines such symbols.
template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
if (Config->EMachine == EM_MIPS) {
// Define _gp for MIPS. st_value of _gp symbol will be updated by Writer
// so that it points to an absolute address which is relative to GOT.
// See "Global Data Symbols" in Chapter 6 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
ElfSym<ELFT>::MipsGp = Symtab.addAbsolute("_gp", STV_DEFAULT);
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
ElfSym<ELFT>::MipsGpDisp = Symtab.addIgnored("_gp_disp");

View File

@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
# CHECK: duplicate symbol: _gp in (internal) and {{.*}}
# CHECK: duplicate symbol: _gp in {{.*}} and (internal)
# REQUIRES: mips

View File

@ -71,9 +71,9 @@
# DSO: ]
# DSO: DynamicSymbols [
# DSO: Name: @
# DSO: Name: _gp@
# DSO: Name: __start@
# DSO: Name: _foo@
# DSO: Name: _gp@
# DSO: ]
# DSO: DynamicSection [
# DSO-NEXT: Tag Type Name/Value

View File

@ -47,9 +47,10 @@ v1:
# EXE_SYM: Sections:
# EXE_SYM: .got 0000000c 0000000000030000 DATA
# EXE_SYM: SYMBOL TABLE:
# EXE_SYM: 00040000 g .data 00000004 v1
# EXE_SYM: 00037ff0 *ABS* 00000000 _gp
# ^-- .got + GP offset (0x7ff0)
# EXE_SYM: 00040000 g .data 00000004 v1
# EXE_GOT_BE: Contents of section .got:
# EXE_GOT_BE: 30000 00000000 80000000 00040000
@ -70,9 +71,9 @@ v1:
# DSO_SYM: Sections:
# DSO_SYM: .got 0000000c 0000000000020000 DATA
# DSO_SYM: SYMBOL TABLE:
# DSO_SYM: 00030000 g .data 00000004 v1
# DSO_SYM: 00027ff0 *ABS* 00000000 _gp
# ^-- .got + GP offset (0x7ff0)
# DSO_SYM: 00030000 g .data 00000004 v1
# DSO_GOT_BE: Contents of section .got:
# DSO_GOT_BE: 20000 00000000 80000000 00030000

View File

@ -26,8 +26,8 @@ __start:
# EXE: SYMBOL TABLE:
# EXE: 00020000 .text 00000000 __start
# EXE: 00037ff0 *ABS* 00000000 _gp
# EXE: 00020010 .text 00000000 _foo
# EXE: 00037ff0 *ABS* 00000000 _gp
# SO: Disassembly of section .text:
# SO-NEXT: __start:
@ -37,6 +37,6 @@ __start:
# ^-- %lo(0x27ff0-0x10004+4)
# SO: SYMBOL TABLE:
# SO: 00027ff0 *ABS* 00000000 _gp
# SO: 00010000 .text 00000000 __start
# SO: 00010010 .text 00000000 _foo
# SO: 00027ff0 *ABS* 00000000 _gp