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 =
291 return "v" +
utostr(Attr);
294SubtargetFeatures ELFObjectFileBase::getHexagonFeatures()
const {
295 SubtargetFeatures Features;
296 HexagonAttributeParser Parser;
303 std::optional<unsigned> Attr;
334Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures()
const {
335 SubtargetFeatures Features;
347 std::optional<StringRef> Attr =
352 return ParseResult.takeError();
353 auto &ISAInfo = *ParseResult;
355 if (ISAInfo->getXLen() == 32)
357 else if (ISAInfo->getXLen() == 64)
368SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures()
const {
369 SubtargetFeatures Features;
389 return getMIPSFeatures();
391 return getARMFeatures();
393 return getRISCVFeatures();
395 return getLoongArchFeatures();
397 return getHexagonFeatures();
406 return getAMDGPUCPUName();
408 return getNVPTXCPUName();
419StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
424#define X(NUM, ENUM, NAME) \
435StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
549 std::optional<unsigned> Attr =
581 std::optional<unsigned> ArchProfileAttr =
624std::vector<ELFPltEntry>
631 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
634 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
635 GlobDatReloc = ELF::R_386_GLOB_DAT;
638 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
639 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
643 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
649 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
652 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
653 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
657 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
662 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
663 std::unique_ptr<const MCInstrAnalysis> MIA(
664 T->createMCInstrAnalysis(MII.get()));
667 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
668 std::optional<SectionRef> RelaPlt, RelaDyn;
678 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
680 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
682 }
else if (Name ==
".got.plt") {
683 GotBaseVA = Section.getAddress();
684 }
else if (Name ==
".plt" || Name ==
".plt.got") {
692 MIA->findPltEntries(Section.getAddress(),
699 for (
auto [Plt, GotPlt] : PltEntries) {
705 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
706 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
711 std::vector<ELFPltEntry> Result;
714 for (
const auto &R : Rels) {
715 if (R.getType() != RelType)
717 auto PltEntryIter = GotToPlt.
find(R.getOffset());
718 if (PltEntryIter != GotToPlt.
end()) {
722 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
725 PltEntryIter->second});
731 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
736 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
743 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
744 std::vector<PGOAnalysisMap> *PGOAnalyses) {
745 using Elf_Shdr =
typename ELFT::Shdr;
747 std::vector<BBAddrMap> BBAddrMaps;
749 PGOAnalyses->clear();
755 if (!TextSectionIndex)
759 return createError(
"unable to get the linked-to section for " +
762 assert(*TextSecOrErr >= Sections.begin() &&
763 "Text section pointer outside of bounds");
764 if (*TextSectionIndex !=
765 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
772 if (!SectionRelocMapOrErr)
775 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
776 if (IsRelocatable && !RelocSec)
777 return createError(
"unable to get relocation section for " +
781 if (!BBAddrMapOrErr) {
783 PGOAnalyses->clear();
784 return createError(
"unable to read BB addr map section: " +
787 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
788 std::back_inserter(BBAddrMaps));
791 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
792 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
793 "returned when PGO information is requested");
798static Expected<std::vector<VersionEntry>>
801 using Elf_Shdr =
typename ELFT::Shdr;
802 const Elf_Shdr *VerSec =
nullptr;
803 const Elf_Shdr *VerNeedSec =
nullptr;
804 const Elf_Shdr *VerDefSec =
nullptr;
815 return std::vector<VersionEntry>();
822 std::vector<VersionEntry> Ret;
827 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
830 " from " +
describe(EF, *VerSec) +
": " +
835 return createError(
"unable to read flags for symbol with index " +
840 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
844 " of " +
describe(EF, *VerSec) +
": " +
847 Ret.push_back({(*VerOrErr).str(), IsDefault});
853Expected<std::vector<VersionEntry>>
867 std::optional<unsigned> TextSectionIndex,
868 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
876 TextSectionIndex, PGOAnalyses);
882 return Obj->getCrelDecodeProblem(
Data);
884 return Obj->getCrelDecodeProblem(
Data);
886 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)
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
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.
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.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.