mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-18 08:49:55 +00:00
[Mips] Support grouping of multiple consecutive relocations in case of N32 and 64-bit MIPS ABIs
llvm-svn: 246337
This commit is contained in:
parent
9638d7d162
commit
e235d45026
@ -226,12 +226,26 @@ void MipsELFFile<ELFT>::createRelocationReferences(
|
||||
const Elf_Sym *symbol, ArrayRef<uint8_t> content,
|
||||
range<const Elf_Rela *> rels) {
|
||||
const auto value = this->getSymbolValue(symbol);
|
||||
unsigned numInGroup = 0;
|
||||
for (const auto &rel : rels) {
|
||||
if (rel.r_offset < value || value + content.size() <= rel.r_offset)
|
||||
if (rel.r_offset < value || value + content.size() <= rel.r_offset) {
|
||||
numInGroup = 0;
|
||||
continue;
|
||||
}
|
||||
if (numInGroup > 0) {
|
||||
auto &last =
|
||||
*static_cast<MipsELFReference<ELFT> *>(this->_references.back());
|
||||
if (last.offsetInAtom() + value == rel.r_offset) {
|
||||
last.setTag(last.tag() |
|
||||
(rel.getType(isMips64EL<ELFT>()) << 8 * (numInGroup - 1)));
|
||||
++numInGroup;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
auto r = new (this->_readerStorage) MipsELFReference<ELFT>(value, rel);
|
||||
this->addReferenceToSymbol(r, symbol);
|
||||
this->_references.push_back(r);
|
||||
numInGroup = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
68
lld/test/elf/Mips/n32-rela-chain.test
Normal file
68
lld/test/elf/Mips/n32-rela-chain.test
Normal file
@ -0,0 +1,68 @@
|
||||
# Check grouping of multiple consecutive relocations in case of N32
|
||||
# and 64-bit MIPS ABIs.
|
||||
|
||||
# RUN: yaml2obj -format=elf %s > %t.o
|
||||
# RUN: lld -flavor gnu -target mips -o %t.exe %t.o
|
||||
# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
|
||||
|
||||
# CHECK: Contents of section .text:
|
||||
# CHECK-NEXT: 10000130 00001001 00002004
|
||||
|
||||
# CHECK: 10002000 l .data 00000004 D0
|
||||
|
||||
---
|
||||
FileHeader:
|
||||
Class: ELFCLASS32
|
||||
Data: ELFDATA2MSB
|
||||
Type: ET_REL
|
||||
Machine: EM_MIPS
|
||||
Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_ABI2]
|
||||
|
||||
Sections:
|
||||
- Name: .text
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
||||
AddressAlign: 16
|
||||
Size: 8
|
||||
|
||||
- Name: .rel.text
|
||||
Type: SHT_RELA
|
||||
Link: .symtab
|
||||
AddressAlign: 4
|
||||
Info: .text
|
||||
Relocations:
|
||||
- Offset: 0
|
||||
Symbol: D0
|
||||
Type: R_MIPS_32
|
||||
Addend: 0x10000
|
||||
- Offset: 0
|
||||
Symbol: D0
|
||||
Type: R_MIPS_HI16
|
||||
- Offset: 4
|
||||
Symbol: D0
|
||||
Type: R_MIPS_32
|
||||
Addend: 4
|
||||
- Offset: 4
|
||||
Symbol: D0
|
||||
Type: R_MIPS_LO16
|
||||
|
||||
- Name: .data
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
||||
AddressAlign: 16
|
||||
Size: 4
|
||||
|
||||
Symbols:
|
||||
Local:
|
||||
- Name: D0
|
||||
Type: STT_FUNC
|
||||
Section: .data
|
||||
Value: 0
|
||||
Size: 4
|
||||
Global:
|
||||
- Name: __start
|
||||
Type: STT_FUNC
|
||||
Section: .text
|
||||
Value: 0
|
||||
Size: 8
|
||||
...
|
Loading…
x
Reference in New Issue
Block a user