Fix handling of ELF::R_MIPS_32 on Mips64.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 6 Jul 2015 12:18:44 +0000 (12:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 6 Jul 2015 12:18:44 +0000 (12:18 +0000)
Thanks to Aboud, Amjad for reporting the regression and providing the testcase.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241440 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/RelocVisitor.h
test/Object/Inputs/elf-mip64-reloc.o [new file with mode: 0644]
test/Object/Mips/reloc-visit.test [new file with mode: 0644]

index 950e2ed0e3389010e25aefc05b3784a6af507490..d5e4258cb0a7629631ea58a2af51ecaf7e806aa9 100644 (file)
@@ -100,9 +100,9 @@ private:
       case Triple::mips64:
         switch (RelocType) {
         case llvm::ELF::R_MIPS_32:
-          return visitELF_MIPS_32(R, Value);
+          return visitELF_MIPS64_32(R, Value);
         case llvm::ELF::R_MIPS_64:
-          return visitELF_MIPS_64(R, Value);
+          return visitELF_MIPS64_64(R, Value);
         default:
           HasError = true;
           return RelocToApply();
@@ -313,11 +313,18 @@ private:
 
   /// MIPS ELF
   RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
-    uint32_t Res = (Value)&0xFFFFFFFF;
+    uint32_t Res = Value & 0xFFFFFFFF;
+    return RelocToApply(Res, 4);
+  }
+
+  /// MIPS64 ELF
+  RelocToApply visitELF_MIPS64_32(RelocationRef R, uint64_t Value) {
+    int64_t Addend = getELFAddend(R);
+    uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
     return RelocToApply(Res, 4);
   }
 
-  RelocToApply visitELF_MIPS_64(RelocationRef R, uint64_t Value) {
+  RelocToApply visitELF_MIPS64_64(RelocationRef R, uint64_t Value) {
     int64_t Addend = getELFAddend(R);
     uint64_t Res = (Value + Addend);
     return RelocToApply(Res, 8);
diff --git a/test/Object/Inputs/elf-mip64-reloc.o b/test/Object/Inputs/elf-mip64-reloc.o
new file mode 100644 (file)
index 0000000..5e68925
Binary files /dev/null and b/test/Object/Inputs/elf-mip64-reloc.o differ
diff --git a/test/Object/Mips/reloc-visit.test b/test/Object/Mips/reloc-visit.test
new file mode 100644 (file)
index 0000000..d75551a
--- /dev/null
@@ -0,0 +1,6 @@
+RUN: llvm-dwarfdump -debug-dump=info %p/../Inputs/elf-mip64-reloc.o 2>&1 | \
+RUN:   FileCheck %s
+
+CHECK: DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000037] = "<stdin>")
+CHECK: DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000054] = "foo")
+CHECK: DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000058] = "int")