[lld] r264956 - [ELF][MIPS] Revert r264761 and add test case to demonstrate the problem

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 15:43:14 PDT 2016


Author: atanasyan
Date: Wed Mar 30 17:43:14 2016
New Revision: 264956

URL: http://llvm.org/viewvc/llvm-project?rev=264956&view=rev
Log:
[ELF][MIPS] Revert r264761 and add test case to demonstrate the problem

If we make R_MIPS_LO16 a relative relocation, linker:
- never creates R_MIPS_COPY relocation for it
- attempts to create R_MIPS_REL32 dynamic relocation if R_MIPS_LO16's
  target is a preemptible symbol

Differential Revision: http://reviews.llvm.org/D18607

Added:
    lld/trunk/test/ELF/mips-lo16-not-relative.s
Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=264956&r1=264955&r2=264956&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Mar 30 17:43:14 2016
@@ -1844,6 +1844,7 @@ bool MipsTargetInfo<ELFT>::isRelRelative
   case R_MIPS_32:
   case R_MIPS_64:
   case R_MIPS_HI16:
+  case R_MIPS_LO16:
   case R_MIPS_TLS_DTPREL_HI16:
   case R_MIPS_TLS_DTPREL_LO16:
   case R_MIPS_TLS_TPREL_HI16:

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=264956&r1=264955&r2=264956&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Mar 30 17:43:14 2016
@@ -434,6 +434,15 @@ void Writer<ELFT>::scanRelocs(InputSecti
     }
 
     if (Config->EMachine == EM_MIPS) {
+      if (Type == R_MIPS_LO16)
+        // Ignore R_MIPS_LO16 relocation. If it is a pair for R_MIPS_GOT16 we
+        // already completed all required action (GOT entry allocation) when
+        // handle R_MIPS_GOT16. If it is a pair for R_MIPS_HI16 against
+        // _gp_disp it does not require dynamic relocation. If its a pair for
+        // R_MIPS_HI16 against a regular symbol it does not require dynamic
+        // relocation too because that case is possible for executable file
+        // linking only.
+        continue;
       if (&Body == Config->MipsGpDisp || &Body == Config->MipsLocalGp)
         // MIPS _gp_disp designates offset between start of function and 'gp'
         // pointer into GOT. __gnu_local_gp is equal to the current value of

Added: lld/trunk/test/ELF/mips-lo16-not-relative.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-lo16-not-relative.s?rev=264956&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-lo16-not-relative.s (added)
+++ lld/trunk/test/ELF/mips-lo16-not-relative.s Wed Mar 30 17:43:14 2016
@@ -0,0 +1,23 @@
+# Check that R_MIPS_LO16 relocation is handled as non-relative,
+# and if a target symbol is a DSO data symbol, LLD create a copy
+# relocation.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN:         %S/Inputs/mips-dynamic.s -o %t.so.o
+# RUN: ld.lld %t.so.o -shared -o %t.so
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o %t.so -o %t.exe
+# RUN: llvm-readobj -r %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK:      Relocations [
+# CHECK-NEXT:   Section (7) .rel.dyn {
+# CHECK-NEXT:     0x{{[0-9A-F]+}} R_MIPS_COPY data0 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+  .text
+  .global __start
+__start:
+  addi   $t0, $t0, %lo(data0)




More information about the llvm-commits mailing list