[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
This commit is contained in:
Simon Atanasyan 2014-05-19 18:48:57 +00:00
parent e321879709
commit c2ec8c5281
2 changed files with 75 additions and 4 deletions

View 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);
}

View File

@ -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