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()));
164SubtargetFeatures ELFObjectFileBase::getARMFeatures()
const {
165 SubtargetFeatures Features;
169 return SubtargetFeatures();
174 std::optional<unsigned> Attr =
295 return "v" +
utostr(Attr);
298SubtargetFeatures ELFObjectFileBase::getHexagonFeatures()
const {
299 SubtargetFeatures Features;
300 HexagonAttributeParser Parser;
307 std::optional<unsigned> Attr;
338Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures()
const {
339 SubtargetFeatures Features;
351 std::optional<StringRef> Attr =
356 return ParseResult.takeError();
357 auto &ISAInfo = *ParseResult;
359 if (ISAInfo->getXLen() == 32)
361 else if (ISAInfo->getXLen() == 64)
372SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures()
const {
373 SubtargetFeatures Features;
393 return getMIPSFeatures();
395 return getARMFeatures();
397 return getRISCVFeatures();
399 return getLoongArchFeatures();
401 return getHexagonFeatures();
410 return getAMDGPUCPUName();
412 return getNVPTXCPUName();
423StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
428#define X(NUM, ENUM, NAME) \
439StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
553 std::optional<unsigned> Attr =
585 std::optional<unsigned> ArchProfileAttr =
628std::vector<ELFPltEntry>
635 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
638 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
639 GlobDatReloc = ELF::R_386_GLOB_DAT;
642 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
643 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
647 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
653 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
656 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
657 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
661 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
666 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
667 std::unique_ptr<const MCInstrAnalysis> MIA(
668 T->createMCInstrAnalysis(MII.get()));
671 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
672 std::optional<SectionRef> RelaPlt, RelaDyn;
682 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
684 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
686 }
else if (Name ==
".got.plt") {
687 GotBaseVA = Section.getAddress();
688 }
else if (Name ==
".plt" || Name ==
".plt.got") {
696 MIA->findPltEntries(Section.getAddress(),
703 for (
auto [Plt, GotPlt] : PltEntries) {
709 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
710 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
715 std::vector<ELFPltEntry> Result;
718 for (
const auto &R : Rels) {
719 if (R.getType() != RelType)
721 auto PltEntryIter = GotToPlt.
find(R.getOffset());
722 if (PltEntryIter != GotToPlt.
end()) {
726 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
729 PltEntryIter->second});
735 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
740 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
747 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
748 std::vector<PGOAnalysisMap> *PGOAnalyses) {
749 using Elf_Shdr =
typename ELFT::Shdr;
751 std::vector<BBAddrMap> BBAddrMaps;
753 PGOAnalyses->clear();
759 if (!TextSectionIndex)
763 return createError(
"unable to get the linked-to section for " +
766 assert(*TextSecOrErr >= Sections.begin() &&
767 "Text section pointer outside of bounds");
768 if (*TextSectionIndex !=
769 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
776 if (!SectionRelocMapOrErr)
779 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
780 if (IsRelocatable && !RelocSec)
781 return createError(
"unable to get relocation section for " +
785 if (!BBAddrMapOrErr) {
787 PGOAnalyses->clear();
788 return createError(
"unable to read BB addr map section: " +
791 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
792 std::back_inserter(BBAddrMaps));
795 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
796 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
797 "returned when PGO information is requested");
802static Expected<std::vector<VersionEntry>>
805 using Elf_Shdr =
typename ELFT::Shdr;
806 const Elf_Shdr *VerSec =
nullptr;
807 const Elf_Shdr *VerNeedSec =
nullptr;
808 const Elf_Shdr *VerDefSec =
nullptr;
819 return std::vector<VersionEntry>();
826 std::vector<VersionEntry> Ret;
831 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
834 " from " +
describe(EF, *VerSec) +
": " +
839 return createError(
"unable to read flags for symbol with index " +
844 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
848 " of " +
describe(EF, *VerSec) +
": " +
851 Ret.push_back({(*VerOrErr).str(), IsDefault});
857Expected<std::vector<VersionEntry>>
871 std::optional<unsigned> TextSectionIndex,
872 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
880 TextSectionIndex, PGOAnalyses);
886 return Obj->getCrelDecodeProblem(
Data);
888 return Obj->getCrelDecodeProblem(
Data);
890 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)
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...
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.