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;
390SubtargetFeatures ELFObjectFileBase::getSparcFeatures()
const {
391 SubtargetFeatures Features;
408 return getMIPSFeatures();
410 return getARMFeatures();
412 return getRISCVFeatures();
413 case ELF::EM_LOONGARCH:
414 return getLoongArchFeatures();
415 case ELF::EM_HEXAGON:
416 return getHexagonFeatures();
418 case ELF::EM_SPARC32PLUS:
419 case ELF::EM_SPARCV9:
420 return getSparcFeatures();
429 return getAMDGPUCPUName();
431 return getNVPTXCPUName();
442StringRef ELFObjectFileBase::getAMDGPUCPUName()
const {
447#define X(NUM, ENUM, NAME) \
458StringRef ELFObjectFileBase::getNVPTXCPUName()
const {
575 std::optional<unsigned> Attr =
607 std::optional<unsigned> ArchProfileAttr =
650std::vector<ELFPltEntry>
657 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
660 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
661 GlobDatReloc = ELF::R_386_GLOB_DAT;
664 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
665 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
669 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
675 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
678 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
679 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
683 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
687 JumpSlotReloc = ELF::R_LARCH_JUMP_SLOT;
692 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
693 std::unique_ptr<const MCInstrAnalysis> MIA(
694 T->createMCInstrAnalysis(MII.get()));
697 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
698 std::optional<SectionRef> RelaPlt, RelaDyn;
699 uint64_t GotBaseVA = 0;
708 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
710 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
712 }
else if (Name ==
".got.plt") {
713 GotBaseVA = Section.getAddress();
714 }
else if (Name ==
".plt" || Name ==
".plt.got") {
722 MIA->findPltEntries(Section.getAddress(),
729 for (
auto [Plt, GotPlt] : PltEntries) {
730 uint64_t GotPltEntry = GotPlt;
735 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
736 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
741 std::vector<ELFPltEntry> Result;
744 for (
const auto &R : Rels) {
745 if (R.getType() != RelType)
747 auto PltEntryIter = GotToPlt.
find(R.getOffset());
748 if (PltEntryIter != GotToPlt.
end()) {
752 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
755 PltEntryIter->second});
761 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
766 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
773 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
774 std::vector<PGOAnalysisMap> *PGOAnalyses) {
775 using Elf_Shdr =
typename ELFT::Shdr;
777 std::vector<BBAddrMap> BBAddrMaps;
779 PGOAnalyses->clear();
785 if (!TextSectionIndex)
789 return createError(
"unable to get the linked-to section for " +
792 assert(*TextSecOrErr >= Sections.begin() &&
793 "Text section pointer outside of bounds");
794 if (*TextSectionIndex !=
795 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
802 if (!SectionRelocMapOrErr)
805 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
806 if (IsRelocatable && !RelocSec)
807 return createError(
"unable to get relocation section for " +
811 if (!BBAddrMapOrErr) {
813 PGOAnalyses->clear();
814 return createError(
"unable to read BB addr map section: " +
817 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
818 std::back_inserter(BBAddrMaps));
821 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
822 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
823 "returned when PGO information is requested");
828static Expected<std::vector<VersionEntry>>
831 using Elf_Shdr =
typename ELFT::Shdr;
832 const Elf_Shdr *VerSec =
nullptr;
833 const Elf_Shdr *VerNeedSec =
nullptr;
834 const Elf_Shdr *VerDefSec =
nullptr;
845 return std::vector<VersionEntry>();
852 std::vector<VersionEntry> Ret;
857 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
860 " from " +
describe(EF, *VerSec) +
": " +
865 return createError(
"unable to read flags for symbol with index " +
870 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
874 " of " +
describe(EF, *VerSec) +
": " +
877 Ret.push_back({(*VerOrErr).str(), IsDefault});
883Expected<std::vector<VersionEntry>>
897 std::optional<unsigned> TextSectionIndex,
898 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
906 TextSectionIndex, PGOAnalyses);
912 return Obj->getCrelDecodeProblem(
Data);
914 return Obj->getCrelDecodeProblem(
Data);
916 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.