Return R_GOTREL for R_MIPS_GPREL*.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 Apr 2016 22:00:04 +0000 (22:00 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 Apr 2016 22:00:04 +0000 (22:00 +0000)
This lets Writer.cpp know that they are got relative, which will allow
further simplifications.

llvm-svn: 267613

lld/ELF/Target.cpp
lld/ELF/Writer.cpp

index bc846a0..0bf86c2 100644 (file)
@@ -1310,6 +1310,9 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr(uint32_t Type,
   switch (Type) {
   default:
     return R_ABS;
+  case R_MIPS_GPREL16:
+  case R_MIPS_GPREL32:
+    return R_GOTREL;
   case R_MIPS_26:
     return R_PLT;
   case R_MIPS_HI16:
@@ -1520,13 +1523,13 @@ void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type,
     writeMipsLo16<E>(Loc, Val);
     break;
   case R_MIPS_GPREL16: {
-    int64_t V = Val - getMipsGpAddr<ELFT>();
+    int64_t V = Val - MipsGPOffset;
     checkInt<16>(V, Type);
     writeMipsLo16<E>(Loc, V);
     break;
   }
   case R_MIPS_GPREL32:
-    write32<E>(Loc, Val - getMipsGpAddr<ELFT>());
+    write32<E>(Loc, Val - MipsGPOffset);
     break;
   case R_MIPS_HI16:
     writeMipsHi16<E>(Loc, Val);
index eec0536..fbf173c 100644 (file)
@@ -706,10 +706,8 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
     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_ABS;
+          (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
         Addend += File.getMipsGp0();
-      }
       C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
       continue;
     }