Skip to content

Commit 90c2f8b

Browse files
dzhidzhoevKornevNikita
authored andcommitted
[llvm-objdump] Pass MCSubtargetInfo to findPltEntries (NFC) (#131773)
It allows access to subtarget features, collected in llvm-objdump.cpp, from findPltEntries, which will be used in llvm/llvm-project#130764.
1 parent 59915b6 commit 90c2f8b

File tree

8 files changed

+15
-12
lines changed

8 files changed

+15
-12
lines changed

llvm/include/llvm/MC/MCInstrAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class MCInstrAnalysis {
195195
/// Returns (PLT virtual address, GOT virtual address) pairs for PLT entries.
196196
virtual std::vector<std::pair<uint64_t, uint64_t>>
197197
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
198-
const Triple &TargetTriple) const {
198+
const MCSubtargetInfo &STI) const {
199199
return {};
200200
}
201201
};

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ADT/iterator_range.h"
2020
#include "llvm/BinaryFormat/ELF.h"
21+
#include "llvm/MC/MCSubtargetInfo.h"
2122
#include "llvm/Object/Binary.h"
2223
#include "llvm/Object/ELF.h"
2324
#include "llvm/Object/ELFTypes.h"
@@ -107,7 +108,7 @@ class ELFObjectFileBase : public ObjectFile {
107108

108109
virtual uint8_t getEIdentABIVersion() const = 0;
109110

110-
std::vector<ELFPltEntry> getPltEntries() const;
111+
std::vector<ELFPltEntry> getPltEntries(const MCSubtargetInfo &STI) const;
111112

112113
/// Returns a vector containing a symbol version for each dynamic symbol.
113114
/// Returns an empty vector if version sections do not exist.

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
782782
TheTriple.setArchName(Triple);
783783
}
784784

785-
std::vector<ELFPltEntry> ELFObjectFileBase::getPltEntries() const {
785+
std::vector<ELFPltEntry>
786+
ELFObjectFileBase::getPltEntries(const MCSubtargetInfo &STI) const {
786787
std::string Err;
787788
const auto Triple = makeTriple();
788789
const auto *T = TargetRegistry::lookupTarget(Triple.str(), Err);
@@ -840,7 +841,7 @@ std::vector<ELFPltEntry> ELFObjectFileBase::getPltEntries() const {
840841
llvm::append_range(
841842
PltEntries,
842843
MIA->findPltEntries(Section.getAddress(),
843-
arrayRefFromStringRef(*PltContents), Triple));
844+
arrayRefFromStringRef(*PltContents), STI));
844845
}
845846
}
846847

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ class AArch64MCInstrAnalysis : public MCInstrAnalysis {
481481

482482
std::vector<std::pair<uint64_t, uint64_t>>
483483
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
484-
const Triple &TargetTriple) const override {
484+
const MCSubtargetInfo &STI) const override {
485485
// Do a lightweight parsing of PLT entries.
486486
std::vector<std::pair<uint64_t, uint64_t>> Result;
487487
for (uint64_t Byte = 0, End = PltContents.size(); Byte + 7 < End;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class HexagonMCInstrAnalysis : public MCInstrAnalysis {
749749

750750
std::vector<std::pair<uint64_t, uint64_t>>
751751
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
752-
const Triple &TargetTriple) const override {
752+
const MCSubtargetInfo &STI) const override {
753753
// Do a lightweight parsing of PLT entries.
754754
std::vector<std::pair<uint64_t, uint64_t>> Result;
755755
for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {

llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class X86MCInstrAnalysis : public MCInstrAnalysis {
514514
APInt &Mask) const override;
515515
std::vector<std::pair<uint64_t, uint64_t>>
516516
findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
517-
const Triple &TargetTriple) const override;
517+
const MCSubtargetInfo &STI) const override;
518518

519519
bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
520520
uint64_t &Target) const override;
@@ -630,7 +630,8 @@ findX86_64PltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents) {
630630
std::vector<std::pair<uint64_t, uint64_t>>
631631
X86MCInstrAnalysis::findPltEntries(uint64_t PltSectionVA,
632632
ArrayRef<uint8_t> PltContents,
633-
const Triple &TargetTriple) const {
633+
const MCSubtargetInfo &STI) const {
634+
const auto TargetTriple = STI.getTargetTriple();
634635
switch (TargetTriple.getArch()) {
635636
case Triple::x86:
636637
return findX86PltEntries(PltSectionVA, PltContents);

llvm/tools/llvm-cfi-verify/lib/FileAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ Error FileAnalysis::parseSymbolTable() {
574574
}
575575
}
576576
if (auto *ElfObject = dyn_cast<object::ELFObjectFileBase>(Object)) {
577-
for (const auto &Plt : ElfObject->getPltEntries()) {
577+
for (const auto &Plt : ElfObject->getPltEntries(*SubtargetInfo)) {
578578
if (!Plt.Symbol)
579579
continue;
580580
object::SymbolRef Sym(*Plt.Symbol, Object);

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ addMissingWasmCodeSymbols(const WasmObjectFile &Obj,
12331233
}
12341234
}
12351235

1236-
static void addPltEntries(const ObjectFile &Obj,
1236+
static void addPltEntries(const MCSubtargetInfo &STI, const ObjectFile &Obj,
12371237
std::map<SectionRef, SectionSymbolsTy> &AllSymbols,
12381238
StringSaver &Saver) {
12391239
auto *ElfObj = dyn_cast<ELFObjectFileBase>(&Obj);
@@ -1248,7 +1248,7 @@ static void addPltEntries(const ObjectFile &Obj,
12481248
}
12491249
Sections[*SecNameOrErr] = Section;
12501250
}
1251-
for (auto Plt : ElfObj->getPltEntries()) {
1251+
for (auto Plt : ElfObj->getPltEntries(STI)) {
12521252
if (Plt.Symbol) {
12531253
SymbolRef Symbol(*Plt.Symbol, ElfObj);
12541254
uint8_t SymbolType = getElfSymbolType(Obj, Symbol);
@@ -1772,7 +1772,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
17721772

17731773
BumpPtrAllocator A;
17741774
StringSaver Saver(A);
1775-
addPltEntries(Obj, AllSymbols, Saver);
1775+
addPltEntries(*DT->SubtargetInfo, Obj, AllSymbols, Saver);
17761776

17771777
// Create a mapping from virtual address to section. An empty section can
17781778
// cause more than one section at the same address. Sort such sections to be

0 commit comments

Comments
 (0)