[PATCH] D19294: Simplify gp0 handling

Rafael Ávila de Espíndola via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 15:45:15 PDT 2016


rafael created this revision.
rafael added a reviewer: atanasyan.
rafael added a subscriber: llvm-commits.

If gp0 cannot point to merge sections (or if -r takes care of it) this is a simplification.

If gp0 can point to a merge section this is either a fix or a regression. In either case it would be awesome if you could provide a testcase :-)
Currently all tests pass with this.

http://reviews.llvm.org/D19294

Files:
  ELF/InputSection.cpp
  ELF/InputSection.h
  ELF/Writer.cpp

Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -620,8 +620,10 @@
     if (!Config->Pic || Target->isRelRelative(Type) || Expr == R_PC ||
         Expr == R_SIZE || isAbsolute<ELFT>(Body)) {
       if (Config->EMachine == EM_MIPS && Body.isLocal() &&
-          (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
-        Expr = R_MIPS_GP0;
+          (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32)) {
+        Expr = R_ABS;
+        Addend += File.getMipsGp0();
+      }
       C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
       continue;
     }
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -36,7 +36,6 @@
   R_GOT_PC,
   R_MIPS_GOT,
   R_MIPS_GOT_LOCAL,
-  R_MIPS_GP0,
   R_NEG_TLS,
   R_PAGE_PC,
   R_PC,
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -206,11 +206,6 @@
   case R_RELAX_TLS_IE_TO_LE:
   case R_RELAX_TLS_LD_TO_LE:
     return Body.getVA<ELFT>(A);
-  case R_MIPS_GP0:
-    // We need to adjust SymVA value in case of R_MIPS_GPREL16/32
-    // relocations because they use the following expression to calculate
-    // the relocation's result for local symbol: S + A + GP0 - G.
-    return Body.getVA<ELFT>(A) + File.getMipsGp0();
   case R_MIPS_GOT_LOCAL:
     // If relocation against MIPS local symbol requires GOT entry, this entry
     // should be initialized by 'page address'. This address is high 16-bits


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19294.54284.patch
Type: text/x-patch
Size: 1637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160419/260fa8e9/attachment.bin>


More information about the llvm-commits mailing list