[lld] r257806 - [ELF][MIPS] Create dynamic relocations for R_MIPS_32/64 relocations

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 13:34:50 PST 2016


Author: atanasyan
Date: Thu Jan 14 15:34:50 2016
New Revision: 257806

URL: http://llvm.org/viewvc/llvm-project?rev=257806&view=rev
Log:
[ELF][MIPS] Create dynamic relocations for R_MIPS_32/64 relocations

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/test/ELF/mips-relocs.s

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=257806&r1=257805&r2=257806&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Jan 14 15:34:50 2016
@@ -227,6 +227,7 @@ public:
 template <class ELFT> class MipsTargetInfo final : public TargetInfo {
 public:
   MipsTargetInfo();
+  unsigned getDynReloc(unsigned Type) const override;
   void writeGotHeaderEntries(uint8_t *Buf) const override;
   void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
   void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
@@ -1453,6 +1454,16 @@ void AMDGPUTargetInfo::relocateOne(uint8
 template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
   PageSize = 65536;
   GotHeaderEntriesNum = 2;
+  RelativeReloc = R_MIPS_REL32;
+}
+
+template <class ELFT>
+unsigned MipsTargetInfo<ELFT>::getDynReloc(unsigned Type) const {
+  if (Type == R_MIPS_32 || Type == R_MIPS_64)
+    return R_MIPS_REL32;
+  StringRef S = getELFRelocationTypeName(EM_MIPS, Type);
+  error("Relocation " + S + " cannot be used when making a shared object; "
+                            "recompile with -fPIC.");
 }
 
 template <class ELFT>

Modified: lld/trunk/test/ELF/mips-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-relocs.s?rev=257806&r1=257805&r2=257806&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-relocs.s (original)
+++ lld/trunk/test/ELF/mips-relocs.s Thu Jan 14 15:34:50 2016
@@ -1,14 +1,16 @@
 # Check R_MIPS_32 relocation calculation.
 
 # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-be.o
-# RUN: ld.lld %t-be.o -o %t-be.exe
-# RUN: llvm-objdump -t %t-be.exe | FileCheck %s
-# RUN: llvm-objdump -s %t-be.exe | FileCheck -check-prefix=BE %s
+# RUN: ld.lld -shared %t-be.o -o %t-be.so
+# RUN: llvm-objdump -t %t-be.so | FileCheck %s
+# RUN: llvm-objdump -s %t-be.so | FileCheck -check-prefix=BE %s
+# RUN: llvm-readobj -relocations %t-be.so | FileCheck -check-prefix=REL %s
 
 # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux %s -o %t-el.o
-# RUN: ld.lld %t-el.o -o %t-el.exe
-# RUN: llvm-objdump -t %t-el.exe | FileCheck %s
-# RUN: llvm-objdump -s %t-el.exe | FileCheck -check-prefix=EL %s
+# RUN: ld.lld -shared %t-el.o -o %t-el.so
+# RUN: llvm-objdump -t %t-el.so | FileCheck %s
+# RUN: llvm-objdump -s %t-el.so | FileCheck -check-prefix=EL %s
+# RUN: llvm-readobj -relocations %t-el.so | FileCheck -check-prefix=REL %s
 
 # REQUIRES: mips
 
@@ -40,3 +42,10 @@ v2:
 # EL: Contents of section .data:
 # EL-NEXT: 30000 00000000 08000300 00000300
 #                         ^-- v2+4 ^-- v1
+
+# REL:      Relocations [
+# REL-NEXT:   Section (7) .rel.dyn {
+# REL-NEXT:     0x30004 R_MIPS_REL32 v2 0x0
+# REL-NEXT:     0x30008 R_MIPS_REL32 - 0x0
+# REL-NEXT:   }
+# REL-NEXT: ]




More information about the llvm-commits mailing list