summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2014-05-19 18:48:57 +0000
committerSimon Atanasyan <simon@atanasyan.com>2014-05-19 18:48:57 +0000
commitc2ec8c5281d1feb7dd447d413a35bbd4d87cc4b6 (patch)
tree376a880d4f2a42fe7e4822474e81e075318e5655
parente32187970901e27dcf04497e67c66efa618a078d (diff)
downloadbcm5719-llvm-c2ec8c5281d1feb7dd447d413a35bbd4d87cc4b6.tar.gz
bcm5719-llvm-c2ec8c5281d1feb7dd447d413a35bbd4d87cc4b6.zip
[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. llvm-svn: 209153
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h10
-rw-r--r--lld/test/elf/Mips/hilo16-5.test69
2 files changed, 75 insertions, 4 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
index 6819f44f2ad..08f6879ba71 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
@@ -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
index 00000000000..9e6e846986d
--- /dev/null
+++ b/lld/test/elf/Mips/hilo16-5.test
@@ -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
OpenPOWER on IntegriCloud