[lld] r209153 - [Mips] Show warning if the linker cannot find a pair for a R_MIPS_HI16

Simon Atanasyan simon at atanasyan.com
Mon May 19 11:48:57 PDT 2014


Author: atanasyan
Date: Mon May 19 13:48:57 2014
New Revision: 209153

URL: http://llvm.org/viewvc/llvm-project?rev=209153&view=rev
Log:
[Mips] Show warning if the linker cannot find a pair for a R_MIPS_HI16
relocation. In fact this case violates ABI but sometimes compilers might
produce such code.

Added:
    lld/trunk/test/elf/Mips/hilo16-5.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=209153&r1=209152&r2=209153&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Mon May 19 13:48:57 2014
@@ -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);
     }

Added: lld/trunk/test/elf/Mips/hilo16-5.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/hilo16-5.test?rev=209153&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/hilo16-5.test (added)
+++ lld/trunk/test/elf/Mips/hilo16-5.test Mon May 19 13:48:57 2014
@@ -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  @.... .. at ...
+
+!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





More information about the llvm-commits mailing list