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},
60 return ElfSymbolTypes;
70 if (
Error E = Ret.takeError())
72 return std::make_unique<ELFObjectFile<ELFT>>(std::move(*Ret));
75Expected<std::unique_ptr<ObjectFile>>
77 std::pair<unsigned char, unsigned char> Ident =
79 std::size_t MaxAlignment =
81 reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
166SubtargetFeatures ELFObjectFileBase::getARMFeatures()
const {
167 SubtargetFeatures Features;
171 return SubtargetFeatures();
176 std::optional<unsigned> Attr =
297 return "v" +
utostr(Attr);
300SubtargetFeatures ELFObjectFileBase::getHexagonFeatures()
const {
301 SubtargetFeatures Features;
302 HexagonAttributeParser Parser;
309 std::optional<unsigned> Attr;
340Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures()
const {
341 SubtargetFeatures Features;
353 std::optional<StringRef> Attr =
358 return ParseResult.takeError();
359 auto &ISAInfo = *ParseResult;
361 if (ISAInfo->getXLen() == 32)
363 else if (ISAInfo->getXLen() == 64)
374SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures()
const {
375 SubtargetFeatures Features;
392SubtargetFeatures ELFObjectFileBase::getSparcFeatures()
const {
393 SubtargetFeatures Features;
410 return getMIPSFeatures();
412 return getARMFeatures();
414 return getRISCVFeatures();
415 case ELF::EM_LOONGARCH:
416 return getLoongArchFeatures();
417 case ELF::EM_HEXAGON:
418 return getHexagonFeatures();
420 case ELF::EM_SPARC32PLUS:
421 case ELF::EM_SPARCV9:
422 return getSparcFeatures();
431 return getAMDGPUCPUName();
433 return getNVPTXCPUName();
444StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
449#define X(NUM, ENUM, NAME) \
460StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
577 std::optional<unsigned> Attr =
609 std::optional<unsigned> ArchProfileAttr =
652std::vector<ELFPltEntry>
659 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
662 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
663 GlobDatReloc = ELF::R_386_GLOB_DAT;
666 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
667 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
671 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
677 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
680 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
681 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
685 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
689 JumpSlotReloc = ELF::R_LARCH_JUMP_SLOT;
694 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
695 std::unique_ptr<const MCInstrAnalysis> MIA(
696 T->createMCInstrAnalysis(MII.get()));
699 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
700 std::optional<SectionRef> RelaPlt, RelaDyn;
701 uint64_t GotBaseVA = 0;
710 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
712 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
714 }
else if (Name ==
".got.plt") {
715 GotBaseVA = Section.getAddress();
716 }
else if (Name ==
".plt" || Name ==
".plt.got") {
724 MIA->findPltEntries(Section.getAddress(),
731 for (
auto [Plt, GotPlt] : PltEntries) {
732 uint64_t GotPltEntry = GotPlt;
737 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
738 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
743 std::vector<ELFPltEntry> Result;
746 for (
const auto &R : Rels) {
747 if (R.getType() != RelType)
749 auto PltEntryIter = GotToPlt.
find(R.getOffset());
750 if (PltEntryIter != GotToPlt.
end()) {
754 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
757 PltEntryIter->second});
763 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
768 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
775 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
776 std::vector<PGOAnalysisMap> *PGOAnalyses) {
777 using Elf_Shdr =
typename ELFT::Shdr;
779 std::vector<BBAddrMap> BBAddrMaps;
781 PGOAnalyses->clear();
787 if (!TextSectionIndex)
791 return createError(
"unable to get the linked-to section for " +
794 assert(*TextSecOrErr >= Sections.begin() &&
795 "Text section pointer outside of bounds");
796 if (*TextSectionIndex !=
797 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
804 if (!SectionRelocMapOrErr)
807 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
808 if (IsRelocatable && !RelocSec)
809 return createError(
"unable to get relocation section for " +
813 if (!BBAddrMapOrErr) {
815 PGOAnalyses->clear();
816 return createError(
"unable to read BB addr map section: " +
819 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
820 std::back_inserter(BBAddrMaps));
823 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
824 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
825 "returned when PGO information is requested");
830static Expected<std::vector<VersionEntry>>
833 using Elf_Shdr =
typename ELFT::Shdr;
834 const Elf_Shdr *VerSec =
nullptr;
835 const Elf_Shdr *VerNeedSec =
nullptr;
836 const Elf_Shdr *VerDefSec =
nullptr;
847 return std::vector<VersionEntry>();
854 std::vector<VersionEntry> Ret;
859 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
862 " from " +
describe(EF, *VerSec) +
": " +
867 return createError(
"unable to read flags for symbol with index " +
872 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
876 " of " +
describe(EF, *VerSec) +
": " +
879 Ret.push_back({(*VerOrErr).str(), IsDefault});
885Expected<std::vector<VersionEntry>>
899 std::optional<unsigned> TextSectionIndex,
900 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
908 TextSectionIndex, PGOAnalyses);
914 return Obj->getCrelDecodeProblem(
Data);
916 return Obj->getCrelDecodeProblem(
Data);
918 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::string hexagonAttrToFeatureString(unsigned Attr)
static Expected< std::vector< VersionEntry > > readDynsymVersionsImpl(const ELFFile< ELFT > &EF, ELFObjectFileBase::elf_symbol_iterator_range Symbols)
#define BUILD_ENUM_STRINGS(Tab)
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::optional< uint64_t > 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...
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
LLVM_ABI EnumStrings< uint8_t, 2 > getElfSymbolTypes()
Error createError(const Twine &Err)
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct an array ref of bytes from a string ref.
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.
std::string utostr(uint64_t X, bool isNeg=false)
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.
Compile-time data representation of enum entries.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.