Devide _gp in the same spot as other mips symbols. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Apr 2016 02:24:43 +0000 (02:24 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Apr 2016 02:24:43 +0000 (02:24 +0000)
The test changes are just because of the symbol order.

llvm-svn: 266037

lld/ELF/Driver.cpp
lld/ELF/Writer.cpp
lld/test/ELF/duplicate-internal.s
lld/test/ELF/mips-dynamic.s
lld/test/ELF/mips-got-relocs.s
lld/test/ELF/mips-hilo-gp-disp.s

index 1d15f14..b5dcc87 100644 (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)
index 483c069..31cf319 100644 (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");
index 2395a6c..d1ccf53 100644 (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
 
index cc5f233..bcb8e10 100644 (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
index 27180fb..408a085 100644 (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
index ba05a5d..41d09b2 100644 (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