Skip to content

Commit a34ff65

Browse files
committed
[Hexagon] Add support for decoding PLT symbols
Describes PLT entries for hexagon.
1 parent e0054e9 commit a34ff65

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ std::vector<ELFPltEntry> ELFObjectFileBase::getPltEntries() const {
802802
case Triple::aarch64_be:
803803
JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
804804
break;
805+
case Triple::hexagon:
806+
JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
807+
GlobDatReloc = ELF::R_HEX_GLOB_DAT;
808+
break;
805809
default:
806810
return {};
807811
}

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,44 @@ class HexagonMCInstrAnalysis : public MCInstrAnalysis {
734734
Target = Value;
735735
return true;
736736
}
737+
738+
uint32_t getValueFromMask(uint32_t Instruction, uint32_t Mask) const {
739+
uint32_t Result = 0;
740+
size_t Off = 0;
741+
for (uint32_t Bit = 0; Bit != sizeof(uint32_t) * CHAR_BIT; ++Bit) {
742+
const uint8_t ValBit = (Instruction >> Bit) & 1;
743+
const bool MaskBit = (Mask >> Bit) & 1;
744+
if (MaskBit) {
745+
Result |= (ValBit << Off);
746+
++Off;
747+
}
748+
}
749+
return Result;
750+
}
751+
752+
std::vector<std::pair<uint64_t, uint64_t>>
753+
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
754+
const Triple &TargetTriple) const override {
755+
// Do a lightweight parsing of PLT entries.
756+
std::vector<std::pair<uint64_t, uint64_t>> Result;
757+
for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {
758+
// Recognize immext(##gotpltn)
759+
uint32_t ImmExt = support::endian::read32le(PltContents.data() + Byte);
760+
if ((ImmExt & 0x00004000) != 0x00004000)
761+
continue;
762+
uint32_t LoadGotPlt =
763+
support::endian::read32le(PltContents.data() + Byte + 4);
764+
if ((LoadGotPlt & 0x6a49c00c) != 0x6a49c00c)
765+
continue;
766+
uint32_t Address = (getValueFromMask(ImmExt, 0xfff3fff) << 6) +
767+
getValueFromMask(LoadGotPlt, 0x1f80) + PltSectionVA +
768+
Byte;
769+
Result.push_back(std::make_pair(PltSectionVA + Byte, Address));
770+
}
771+
return Result;
772+
}
737773
};
738-
}
774+
} // namespace
739775

740776
static MCInstrAnalysis *createHexagonMCInstrAnalysis(const MCInstrInfo *Info) {
741777
return new HexagonMCInstrAnalysis(Info);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# RUN: yaml2obj %s | llvm-objdump -d - | FileCheck %s
2+
3+
# CHECK: 00000310 <printf@plt>:
4+
# CHECK-NEXT: 310: 36 40 00 00 00004036 { immext(#0xd80)
5+
# CHECK-NEXT: 314: 0e de 49 6a 6a49de0e r14 = add(pc,##0xdbc) }
6+
# CHECK-NEXT: 318: 1c c0 8e 91 918ec01c { r28 = memw(r14+#0x0) }
7+
# CHECK-NEXT: 31c: 00 c0 9c 52 529cc000 { jumpr r28 }
8+
9+
--- !ELF
10+
FileHeader:
11+
Class: ELFCLASS32
12+
Data: ELFDATA2LSB
13+
Type: ET_DYN
14+
Machine: EM_HEXAGON
15+
Sections:
16+
- Name: .rela.plt
17+
Type: SHT_RELA
18+
Flags: [ SHF_ALLOC ]
19+
Info: .got.plt
20+
Relocations:
21+
- Offset: 0x10CC
22+
Symbol: printf
23+
Type: R_HEX_JMP_SLOT
24+
- Name: .plt
25+
Type: SHT_PROGBITS
26+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
27+
Address: 0x2B0
28+
Content: 384000001CC0496A0E429CE24F409C913CC09C910E420E8C00C09C520000000000000000000000000000000000000000374000000ED0496A1CC08E9100C09C52374000000ECA496A1CC08E9100C09C52374000000EC4496A1CC08E9100C09C52364000000EDE496A1CC08E9100C09C52
29+
- Name: .text
30+
Type: SHT_PROGBITS
31+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
32+
Address: 0x320
33+
Content: 0240096AC97FFF0F01C6007802C221F3FF7FFF0F80C7007800C002F300C0809100C0007500C05F5300C0096ADAFFFF5901C09DA082FFFEBF00C0423C0140000000D4496AD6FFFF5B00C000781EC01E96
34+
- Name: .got.plt
35+
Type: SHT_PROGBITS
36+
Flags: [ SHF_WRITE, SHF_ALLOC ]
37+
Address: 0x10B0
38+
Content: 00000000000000000000000000000000B0020000B0020000B0020000B0020000
39+
Symbols:
40+
- Name: printf
41+
Binding: STB_GLOBAL
42+
...

0 commit comments

Comments
 (0)