48 {
"Unknown",
"<unknown>: 7", 7},
49 {
"Unknown",
"<unknown>: 8", 8},
50 {
"Unknown",
"<unknown>: 9", 9},
52 {
"OS Specific",
"<OS specific>: 11", 11},
53 {
"OS Specific",
"<OS specific>: 12", 12},
54 {
"Proc Specific",
"<processor specific>: 13", 13},
55 {
"Proc Specific",
"<processor specific>: 14", 14},
56 {
"Proc Specific",
"<processor specific>: 15", 15}
66 if (
Error E = Ret.takeError())
68 return std::make_unique<ELFObjectFile<ELFT>>(std::move(*Ret));
71Expected<std::unique_ptr<ObjectFile>>
73 std::pair<unsigned char, unsigned char> Ident =
75 std::size_t MaxAlignment =
77 reinterpret_cast<uintptr_t
>(Obj.getBufferStart()));
160SubtargetFeatures ELFObjectFileBase::getARMFeatures()
const {
161 SubtargetFeatures Features;
165 return SubtargetFeatures();
170 std::optional<unsigned> Attr =
323SubtargetFeatures ELFObjectFileBase::getHexagonFeatures()
const {
324 SubtargetFeatures Features;
325 HexagonAttributeParser Parser;
332 std::optional<unsigned> Attr;
335 if (std::optional<std::string> FeatureString =
341 std::optional<std::string> FeatureString =
344 if (FeatureString && *Attr >= 60)
371Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures()
const {
372 SubtargetFeatures Features;
384 std::optional<StringRef> Attr =
389 return ParseResult.takeError();
390 auto &ISAInfo = *ParseResult;
392 if (ISAInfo->getXLen() == 32)
394 else if (ISAInfo->getXLen() == 64)
405SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures()
const {
406 SubtargetFeatures Features;
426 return getMIPSFeatures();
428 return getARMFeatures();
430 return getRISCVFeatures();
432 return getLoongArchFeatures();
434 return getHexagonFeatures();
443 return getAMDGPUCPUName();
445 return getNVPTXCPUName();
456StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
461#define X(NUM, ENUM, NAME) \
472StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
586 std::optional<unsigned> Attr =
618 std::optional<unsigned> ArchProfileAttr =
661std::vector<ELFPltEntry>
668 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
671 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
672 GlobDatReloc = ELF::R_386_GLOB_DAT;
675 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
676 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
680 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
686 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
689 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
690 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
694 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
699 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
700 std::unique_ptr<const MCInstrAnalysis> MIA(
701 T->createMCInstrAnalysis(MII.get()));
704 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
705 std::optional<SectionRef> RelaPlt, RelaDyn;
715 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
717 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
719 }
else if (Name ==
".got.plt") {
720 GotBaseVA = Section.getAddress();
721 }
else if (Name ==
".plt" || Name ==
".plt.got") {
729 MIA->findPltEntries(Section.getAddress(),
736 for (
auto [Plt, GotPlt] : PltEntries) {
742 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
743 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
748 std::vector<ELFPltEntry> Result;
751 for (
const auto &R : Rels) {
752 if (R.getType() != RelType)
754 auto PltEntryIter = GotToPlt.
find(R.getOffset());
755 if (PltEntryIter != GotToPlt.
end()) {
759 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
762 PltEntryIter->second});
768 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
773 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
780 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
781 std::vector<PGOAnalysisMap> *PGOAnalyses) {
782 using Elf_Shdr =
typename ELFT::Shdr;
784 std::vector<BBAddrMap> BBAddrMaps;
786 PGOAnalyses->clear();
792 if (!TextSectionIndex)
796 return createError(
"unable to get the linked-to section for " +
799 assert(*TextSecOrErr >= Sections.begin() &&
800 "Text section pointer outside of bounds");
801 if (*TextSectionIndex !=
802 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
809 if (!SectionRelocMapOrErr)
812 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
813 if (IsRelocatable && !RelocSec)
814 return createError(
"unable to get relocation section for " +
818 if (!BBAddrMapOrErr) {
820 PGOAnalyses->clear();
824 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
825 std::back_inserter(BBAddrMaps));
828 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
829 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
830 "returned when PGO information is requested");
835static Expected<std::vector<VersionEntry>>
838 using Elf_Shdr =
typename ELFT::Shdr;
839 const Elf_Shdr *VerSec =
nullptr;
840 const Elf_Shdr *VerNeedSec =
nullptr;
841 const Elf_Shdr *VerDefSec =
nullptr;
852 return std::vector<VersionEntry>();
859 std::vector<VersionEntry> Ret;
864 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
867 " from " +
describe(EF, *VerSec) +
": " +
872 return createError(
"unable to read flags for symbol with index " +
877 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
881 " of " +
describe(EF, *VerSec) +
": " +
884 Ret.push_back({(*VerOrErr).str(), IsDefault});
890Expected<std::vector<VersionEntry>>
904 std::optional<unsigned> TextSectionIndex,
905 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
913 TextSectionIndex, PGOAnalyses);
919 return Obj->getCrelDecodeProblem(
Data);
921 return Obj->getCrelDecodeProblem(
Data);
923 return Obj->getCrelDecodeProblem(
Data);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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)
static constexpr unsigned SM(unsigned Version)
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::optional< unsigned > getAttributeValue(unsigned tag) const override
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.
Generic base class for all target subtargets.
static LLVM_ABI 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.
LLVM_ABI void AddFeature(StringRef String, bool Enable=true)
Adds Features.
LLVM_ABI void addFeaturesVector(const ArrayRef< std::string > OtherFeatures)
Triple - Helper class for working with autoconf configuration names.
LLVM_ABI 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.
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.
DataRefImpl getRawDataRefImpl() const
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 uint8_t getEIdentABIVersion() const =0
virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const =0
std::vector< ELFPltEntry > getPltEntries(const MCSubtargetInfo &STI) const
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
Expected< SubtargetFeatures > getFeatures() const override
std::optional< StringRef > tryGetCPUName() const override
iterator_range< elf_symbol_iterator > elf_symbol_iterator_range
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)
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
ObjectFile(unsigned int Type, MemoryBufferRef Source)
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_LOONGARCH_ABI_SINGLE_FLOAT
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
@ EF_LOONGARCH_ABI_SOFT_FLOAT
@ EF_LOONGARCH_ABI_MODIFIER_MASK
@ EF_CUDA_ACCELERATORS_V1
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)
LLVM_ABI const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void consumeError(Error Err)
Consume a Error without doing anything.
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.