Skip to content

Commit 61ea63b

Browse files
authored
[Hexagon] Add support for decoding PLT symbols (#123425)
Describes PLT entries for hexagon.
1 parent ab1ee91 commit 61ea63b

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

lld/test/ELF/hexagon-plt.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@
7171
# DIS-NEXT: 20054: { r14 = asr(r14,#2)
7272
# DIS-NEXT: 20058: jumpr r28 }
7373
# DIS-NEXT: 2005c: { trap0(#219) }
74-
## bar's plt slot
74+
# DIS-EMPTY:
75+
# DIS-NEXT: 00020060 <bar@plt>:
7576
# DIS-NEXT: 20060: { immext(#131072)
7677
# DIS-NEXT: 20064: r14 = add(pc,##131096) }
7778
# DIS-NEXT: 20068: { r28 = memw(r14+#0) }
7879
# DIS-NEXT: 2006c: { jumpr r28 }
79-
## weak's plt slot
80+
# DIS-EMPTY:
81+
# DIS-NEXT: 00020070 <weak@plt>:
8082
# DIS-NEXT: 20070: { immext(#131072)
8183
# DIS-NEXT: 20074: r14 = add(pc,##131084) }
8284
# DIS-NEXT: 20078: { r28 = memw(r14+#0) }

lld/test/ELF/hexagon-shared.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pvar:
8080
# PLT-NEXT: { r14 = asr(r14,#2)
8181
# PLT-NEXT: jumpr r28 }
8282
# PLT-NEXT: { trap0(#219) }
83+
# PLT-EMPTY:
84+
# PLT-NEXT: 000102f0 <foo@plt>:
8385
# PLT-NEXT: immext(#131200)
8486
# PLT-NEXT: r14 = add(pc,##131252) }
8587
# PLT-NEXT: r28 = memw(r14+#0) }

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: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,42 @@ 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+
uint32_t Offset = 0;
741+
while (Mask) {
742+
if (Instruction & (Mask & -Mask))
743+
Result |= (1 << Offset);
744+
Mask &= (Mask - 1);
745+
++Offset;
746+
}
747+
return Result;
748+
}
749+
750+
std::vector<std::pair<uint64_t, uint64_t>>
751+
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
752+
const Triple &TargetTriple) const override {
753+
// Do a lightweight parsing of PLT entries.
754+
std::vector<std::pair<uint64_t, uint64_t>> Result;
755+
for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {
756+
// Recognize immext(##gotpltn)
757+
uint32_t ImmExt = support::endian::read32le(PltContents.data() + Byte);
758+
if ((ImmExt & 0x00004000) != 0x00004000)
759+
continue;
760+
uint32_t LoadGotPlt =
761+
support::endian::read32le(PltContents.data() + Byte + 4);
762+
if ((LoadGotPlt & 0x6a49c00c) != 0x6a49c00c)
763+
continue;
764+
uint32_t Address = (getValueFromMask(ImmExt, 0xfff3fff) << 6) +
765+
getValueFromMask(LoadGotPlt, 0x1f80) + PltSectionVA +
766+
Byte;
767+
Result.emplace_back(PltSectionVA + Byte, Address);
768+
}
769+
return Result;
770+
}
737771
};
738-
}
772+
} // namespace
739773

740774
static MCInstrAnalysis *createHexagonMCInstrAnalysis(const MCInstrInfo *Info) {
741775
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)