39using namespace object;
49 {
"Unknown",
"<unknown>: 7", 7},
50 {
"Unknown",
"<unknown>: 8", 8},
51 {
"Unknown",
"<unknown>: 9", 9},
53 {
"OS Specific",
"<OS specific>: 11", 11},
54 {
"OS Specific",
"<OS specific>: 12", 12},
55 {
"Proc Specific",
"<processor specific>: 13", 13},
56 {
"Proc Specific",
"<processor specific>: 14", 14},
57 {
"Proc Specific",
"<processor specific>: 15", 15}
67 if (
Error E = Ret.takeError())
69 return std::make_unique<ELFObjectFile<ELFT>>(std::move(*Ret));
74 std::pair<unsigned char, unsigned char> Ident =
76 std::size_t MaxAlignment =
85 return createPtr<ELF32LE>(Obj, InitContent);
87 return createPtr<ELF32BE>(Obj, InitContent);
92 return createPtr<ELF64LE>(Obj, InitContent);
94 return createPtr<ELF64BE>(Obj, InitContent);
171 std::optional<unsigned> Attr =
327 std::optional<unsigned> Attr;
330 if (std::optional<std::string> FeatureString =
336 std::optional<std::string> FeatureString =
339 if (FeatureString && *Attr >= 60)
379 std::optional<StringRef> Attr =
387 if (ISAInfo->getXLen() == 32)
389 else if (ISAInfo->getXLen() == 64)
421 return getMIPSFeatures();
423 return getARMFeatures();
425 return getRISCVFeatures();
427 return getLoongArchFeatures();
429 return getHexagonFeatures();
438 return getAMDGPUCPUName();
440 return getNVPTXCPUName();
451StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
602 return "gfx9-generic";
604 return "gfx10-1-generic";
606 return "gfx10-3-generic";
608 return "gfx11-generic";
610 return "gfx12-generic";
616StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
702 std::optional<unsigned> Attr =
734 std::optional<unsigned> ArchProfileAttr =
736 if (ArchProfileAttr &&
784 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
787 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
788 GlobDatReloc = ELF::R_386_GLOB_DAT;
791 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
792 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
796 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
801 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
802 std::unique_ptr<const MCInstrAnalysis> MIA(
803 T->createMCInstrAnalysis(MII.get()));
806 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
807 std::optional<SectionRef> RelaPlt, RelaDyn;
817 if (
Name ==
".rela.plt" ||
Name ==
".rel.plt") {
819 }
else if (
Name ==
".rela.dyn" ||
Name ==
".rel.dyn") {
821 }
else if (
Name ==
".got.plt") {
822 GotBaseVA = Section.getAddress();
823 }
else if (
Name ==
".plt" ||
Name ==
".plt.got") {
831 MIA->findPltEntries(Section.getAddress(),
832 arrayRefFromStringRef(*PltContents),
Triple));
838 for (
auto [Plt, GotPlt] : PltEntries) {
844 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
845 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
850 std::vector<ELFPltEntry> Result;
853 for (
const auto &R : Rels) {
854 if (R.getType() != RelType)
856 auto PltEntryIter = GotToPlt.
find(R.getOffset());
857 if (PltEntryIter != GotToPlt.
end()) {
861 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
864 PltEntryIter->second});
870 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
875 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
882 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
883 std::vector<PGOAnalysisMap> *PGOAnalyses) {
884 using Elf_Shdr =
typename ELFT::Shdr;
886 std::vector<BBAddrMap> BBAddrMaps;
888 PGOAnalyses->clear();
895 if (!TextSectionIndex)
899 return createError(
"unable to get the linked-to section for " +
902 assert(*TextSecOrErr >= Sections.begin() &&
903 "Text section pointer outside of bounds");
904 if (*TextSectionIndex !=
905 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
912 if (!SectionRelocMapOrErr)
915 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
916 if (IsRelocatable && !RelocSec)
917 return createError(
"unable to get relocation section for " +
921 if (!BBAddrMapOrErr) {
923 PGOAnalyses->clear();
927 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
928 std::back_inserter(BBAddrMaps));
931 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
932 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
933 "returned when PGO information is requested");
941 using Elf_Shdr =
typename ELFT::Shdr;
942 const Elf_Shdr *VerSec =
nullptr;
943 const Elf_Shdr *VerNeedSec =
nullptr;
944 const Elf_Shdr *VerDefSec =
nullptr;
955 return std::vector<VersionEntry>();
962 std::vector<VersionEntry> Ret;
967 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
970 " from " +
describe(EF, *VerSec) +
": " +
975 return createError(
"unable to read flags for symbol with index " +
980 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
984 " of " +
describe(EF, *VerSec) +
": " +
987 Ret.push_back({(*VerOrErr).str(), IsDefault});
996 if (
const auto *Obj = dyn_cast<ELF32LEObjectFile>(
this))
998 if (
const auto *Obj = dyn_cast<ELF32BEObjectFile>(
this))
1000 if (
const auto *Obj = dyn_cast<ELF64LEObjectFile>(
this))
1007 std::optional<unsigned> TextSectionIndex,
1008 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
1009 if (
const auto *Obj = dyn_cast<ELF32LEObjectFile>(
this))
1011 if (
const auto *Obj = dyn_cast<ELF64LEObjectFile>(
this))
1013 if (
const auto *Obj = dyn_cast<ELF32BEObjectFile>(
this))
1016 TextSectionIndex, PGOAnalyses);
1021 if (
const auto *Obj = dyn_cast<ELF32LEObjectFile>(
this))
1022 return Obj->getCrelDecodeProblem(
Data);
1023 if (
const auto *Obj = dyn_cast<ELF32BEObjectFile>(
this))
1024 return Obj->getCrelDecodeProblem(
Data);
1025 if (
const auto *Obj = dyn_cast<ELF64LEObjectFile>(
this))
1026 return Obj->getCrelDecodeProblem(
Data);
1027 return cast<ELF64BEObjectFile>(
this)->getCrelDecodeProblem(
Data);
static Expected< std::unique_ptr< ELFObjectFile< ELFT > > > createPtr(MemoryBufferRef Object, bool InitContent)
static Expected< std::vector< BBAddrMap > > readBBAddrMapImpl(const ELFFile< ELFT > &EF, std::optional< unsigned > TextSectionIndex, std::vector< PGOAnalysisMap > *PGOAnalyses)
static std::optional< std::string > hexagonAttrToFeatureString(unsigned Attr)
static Expected< std::vector< VersionEntry > > readDynsymVersionsImpl(const ELFFile< ELFT > &EF, ELFObjectFileBase::elf_symbol_iterator_range Symbols)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
const char * getBufferStart() const
StringRef getBuffer() const
This class represents success/failure for parsing-like operations that find it important to chain tog...
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseNormalizedArchString(StringRef Arch)
Parse RISC-V ISA info from an arch string that is already in normalized form (as defined in the psABI...
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
void addFeaturesVector(const ArrayRef< std::string > OtherFeatures)
Triple - Helper class for working with autoconf configuration names.
void setArchName(StringRef Str)
Set the architecture (first) component of the triple by name.
bool isThumb() const
Tests whether the target is Thumb (little and big endian).
SubArchType getSubArch() const
get the parsed subarchitecture type for this triple.
ArchType getArch() const
Get the parsed architecture type of this triple.
const std::string & str() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
A range adaptor for a pair of iterators.
bool isLittleEndian() const
const Elf_Ehdr & getHeader() const
Expected< std::vector< BBAddrMap > > decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec=nullptr, std::vector< PGOAnalysisMap > *PGOAnalyses=nullptr) const
Returns a vector of BBAddrMap structs corresponding to each function within the text section that the...
Expected< StringRef > getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, SmallVector< std::optional< VersionEntry >, 0 > &VersionMap, std::optional< bool > IsSymHidden) const
Expected< Elf_Shdr_Range > sections() const
Expected< MapVector< const Elf_Shdr *, const Elf_Shdr * > > getSectionAndRelocations(std::function< Expected< bool >(const Elf_Shdr &)> IsMatch) const
Returns a map from every section matching IsMatch to its relocation section, or nullptr if it has no ...
Expected< SmallVector< std::optional< VersionEntry >, 0 > > loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, DataRegion< Elf_Word > ShndxTable) const
virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const =0
Expected< std::vector< VersionEntry > > readDynsymVersions() const
Returns a vector containing a symbol version for each dynamic symbol.
virtual elf_symbol_iterator_range getDynamicSymbolIterators() const =0
StringRef getCrelDecodeProblem(SectionRef Sec) const
std::vector< ELFPltEntry > getPltEntries() const
Expected< SubtargetFeatures > getFeatures() const override
std::optional< StringRef > tryGetCPUName() const override
virtual uint16_t getEMachine() const =0
virtual unsigned getPlatformFlags() const =0
Returns platform-specific object flags, if any.
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
void setARMSubArch(Triple &TheTriple) const override
Expected< std::vector< BBAddrMap > > readBBAddrMap(std::optional< unsigned > TextSectionIndex=std::nullopt, std::vector< PGOAnalysisMap > *PGOAnalyses=nullptr) const
Returns a vector of all BB address maps in the object file.
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
This class is the base class for all object file types.
static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)
Triple makeTriple() const
Create a triple from the data in this object file.
section_iterator_range sections() const
This is a value type class that represents a single section in the list of sections in the object fil...
DataRefImpl getRawDataRefImpl() const
virtual basic_symbol_iterator symbol_end() const =0
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ AllowMVEIntegerAndFloat
@ EF_AMDGPU_MACH_AMDGCN_GFX703
@ EF_AMDGPU_MACH_AMDGCN_GFX1035
@ EF_AMDGPU_MACH_AMDGCN_GFX1031
@ EF_AMDGPU_MACH_R600_CAYMAN
@ EF_AMDGPU_MACH_AMDGCN_GFX704
@ EF_AMDGPU_MACH_AMDGCN_GFX902
@ EF_AMDGPU_MACH_AMDGCN_GFX810
@ EF_AMDGPU_MACH_AMDGCN_GFX1036
@ EF_AMDGPU_MACH_AMDGCN_GFX1102
@ EF_AMDGPU_MACH_R600_RV730
@ EF_AMDGPU_MACH_R600_RV710
@ EF_AMDGPU_MACH_AMDGCN_GFX908
@ EF_AMDGPU_MACH_AMDGCN_GFX1011
@ EF_AMDGPU_MACH_R600_CYPRESS
@ EF_AMDGPU_MACH_AMDGCN_GFX1032
@ EF_AMDGPU_MACH_R600_R600
@ EF_AMDGPU_MACH_AMDGCN_GFX940
@ EF_AMDGPU_MACH_AMDGCN_GFX941
@ EF_AMDGPU_MACH_R600_TURKS
@ EF_AMDGPU_MACH_R600_JUNIPER
@ EF_AMDGPU_MACH_AMDGCN_GFX601
@ EF_AMDGPU_MACH_AMDGCN_GFX942
@ EF_AMDGPU_MACH_AMDGCN_GFX1152
@ EF_AMDGPU_MACH_R600_R630
@ EF_AMDGPU_MACH_R600_REDWOOD
@ EF_AMDGPU_MACH_R600_RV770
@ EF_AMDGPU_MACH_AMDGCN_GFX600
@ EF_AMDGPU_MACH_AMDGCN_GFX602
@ EF_AMDGPU_MACH_AMDGCN_GFX1101
@ EF_AMDGPU_MACH_AMDGCN_GFX1100
@ EF_AMDGPU_MACH_AMDGCN_GFX1033
@ EF_AMDGPU_MACH_AMDGCN_GFX801
@ EF_AMDGPU_MACH_AMDGCN_GFX705
@ EF_AMDGPU_MACH_AMDGCN_GFX1010
@ EF_AMDGPU_MACH_R600_RV670
@ EF_AMDGPU_MACH_AMDGCN_GFX701
@ EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC
@ EF_AMDGPU_MACH_AMDGCN_GFX1012
@ EF_AMDGPU_MACH_AMDGCN_GFX1151
@ EF_AMDGPU_MACH_AMDGCN_GFX1030
@ EF_AMDGPU_MACH_R600_CEDAR
@ EF_AMDGPU_MACH_AMDGCN_GFX1200
@ EF_AMDGPU_MACH_AMDGCN_GFX700
@ EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC
@ EF_AMDGPU_MACH_AMDGCN_GFX803
@ EF_AMDGPU_MACH_AMDGCN_GFX802
@ EF_AMDGPU_MACH_AMDGCN_GFX90C
@ EF_AMDGPU_MACH_AMDGCN_GFX900
@ EF_AMDGPU_MACH_AMDGCN_GFX909
@ EF_AMDGPU_MACH_AMDGCN_GFX906
@ EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC
@ EF_AMDGPU_MACH_AMDGCN_GFX1103
@ EF_AMDGPU_MACH_R600_CAICOS
@ EF_AMDGPU_MACH_AMDGCN_GFX90A
@ EF_AMDGPU_MACH_AMDGCN_GFX1034
@ EF_AMDGPU_MACH_AMDGCN_GFX1013
@ EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC
@ EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC
@ EF_AMDGPU_MACH_AMDGCN_GFX904
@ EF_AMDGPU_MACH_R600_RS880
@ EF_AMDGPU_MACH_AMDGCN_GFX805
@ EF_AMDGPU_MACH_AMDGCN_GFX1201
@ EF_AMDGPU_MACH_AMDGCN_GFX1150
@ EF_AMDGPU_MACH_R600_SUMO
@ EF_AMDGPU_MACH_R600_BARTS
@ EF_AMDGPU_MACH_AMDGCN_GFX702
@ SHT_LLVM_BB_ADDR_MAP_V0
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
@ EF_LOONGARCH_ABI_SOFT_FLOAT
@ EF_LOONGARCH_ABI_MODIFIER_MASK
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Error createError(const Twine &Err)
constexpr int NumElfSymbolTypes
static std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void consumeError(Error Err)
Consume a Error without doing anything.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.