[Mips] Show warning if the linker cannot find a pair for a R_MIPS_HI16
authorSimon Atanasyan <simon@atanasyan.com>
Mon, 19 May 2014 18:48:57 +0000 (18:48 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Mon, 19 May 2014 18:48:57 +0000 (18:48 +0000)
relocation. In fact this case violates ABI but sometimes compilers might
produce such code.

llvm-svn: 209153

lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
lld/test/elf/Mips/hilo16-5.test [new file with mode: 0644]

index 6819f44..08f6879 100644 (file)
@@ -170,11 +170,13 @@ private:
 
       auto addend = readAddend(*rit, secContent);
       if (needsMatchingRelocation(*rit)) {
+        addend <<= 16;
         auto mit = findMatchingRelocation(rit, eit);
-        // FIXME (simon): Handle this condition in a more user friendly way.
-        assert(mit != eit && "There is no paired R_MIPS_LO16 relocation");
-        auto matchingAddend = readAddend(*mit, secContent);
-        addend = (addend << 16) + int16_t(matchingAddend);
+        if (mit != eit)
+          addend += int16_t(readAddend(*mit, secContent));
+        else
+          // FIXME (simon): Show detailed warning.
+          llvm::errs() << "lld warning: cannot matching LO16 relocation\n";
       }
       this->_references.back()->setAddend(addend);
     }
diff --git a/lld/test/elf/Mips/hilo16-5.test b/lld/test/elf/Mips/hilo16-5.test
new file mode 100644 (file)
index 0000000..9e6e846
--- /dev/null
@@ -0,0 +1,69 @@
+# RUN: yaml2obj -format=elf -o %t1.o %s
+# RUN: yaml2obj -format=elf -o %t2.o %S/Inputs/pic-obj.yaml
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t2.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t1.o %t.so 2>&1 \
+# RUN:   | FileCheck -check-prefix=DIAG %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=DATA %s
+
+# DIAG: lld warning: cannot matching LO16 relocation
+# DIAG: lld warning: cannot matching LO16 relocation
+
+# DATA:      Contents of section .data:
+# DATA-NEXT:  402000 40000000 10200000 40000000  @.... ..@...
+
+!ELF
+FileHeader: !FileHeader
+  Class: ELFCLASS32
+  Data: ELFDATA2LSB
+  Type: ET_REL
+  Machine: EM_MIPS
+  Flags: [EF_MIPS_CPIC]
+
+Sections:
+- Name: .text
+  Type: SHT_PROGBITS
+  Content:  "00000000"
+  AddressAlign: 16
+  Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+  Type: SHT_PROGBITS
+  Content:  "000000000000000000000000"
+  AddressAlign: 16
+  Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+  Type: SHT_REL
+  Info: .data
+  AddressAlign: 4
+  Relocations:
+    - Offset: 0x00
+      Symbol: D1
+      Type: R_MIPS_HI16
+    - Offset: 0x08
+      Symbol: D2
+      Type: R_MIPS_HI16
+    - Offset: 0x04
+      Symbol: D1
+      Type: R_MIPS_LO16
+    - Offset: 0x08
+      Symbol: .text
+      Type: R_MIPS_HI16
+
+Symbols:
+  Local:
+    - Name:            .text
+      Type:            STT_SECTION
+      Section:         .text
+    - Name:            .data
+      Type:            STT_SECTION
+      Section:         .data
+
+  Global:
+    - Name: T0
+      Section: .text
+      Type: STT_FUNC
+      Value: 0x0
+      Size: 4
+    - Name: D1
+    - Name: D2