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 {
556 std::optional<unsigned> Attr =
588 std::optional<unsigned> ArchProfileAttr =
631std::vector<ELFPltEntry>
638 uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;
641 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
642 GlobDatReloc = ELF::R_386_GLOB_DAT;
645 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
646 GlobDatReloc = ELF::R_X86_64_GLOB_DAT;
650 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
656 JumpSlotReloc = ELF::R_ARM_JUMP_SLOT;
659 JumpSlotReloc = ELF::R_HEX_JMP_SLOT;
660 GlobDatReloc = ELF::R_HEX_GLOB_DAT;
664 JumpSlotReloc = ELF::R_RISCV_JUMP_SLOT;
669 std::unique_ptr<const MCInstrInfo> MII(
T->createMCInstrInfo());
670 std::unique_ptr<const MCInstrAnalysis> MIA(
671 T->createMCInstrAnalysis(MII.get()));
674 std::vector<std::pair<uint64_t, uint64_t>> PltEntries;
675 std::optional<SectionRef> RelaPlt, RelaDyn;
685 if (Name ==
".rela.plt" || Name ==
".rel.plt") {
687 }
else if (Name ==
".rela.dyn" || Name ==
".rel.dyn") {
689 }
else if (Name ==
".got.plt") {
690 GotBaseVA = Section.getAddress();
691 }
else if (Name ==
".plt" || Name ==
".plt.got") {
699 MIA->findPltEntries(Section.getAddress(),
706 for (
auto [Plt, GotPlt] : PltEntries) {
712 GotPltEntry =
static_cast<int32_t
>(GotPltEntry) + GotBaseVA;
713 GotToPlt.
insert(std::make_pair(GotPltEntry, Plt));
718 std::vector<ELFPltEntry> Result;
721 for (
const auto &R : Rels) {
722 if (R.getType() != RelType)
724 auto PltEntryIter = GotToPlt.
find(R.getOffset());
725 if (PltEntryIter != GotToPlt.
end()) {
729 ELFPltEntry{PltSec, std::nullopt, PltEntryIter->second});
732 PltEntryIter->second});
738 handleRels(RelaPlt->relocations(), JumpSlotReloc,
".plt");
743 handleRels(RelaDyn->relocations(), GlobDatReloc,
".plt.got");
750 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex,
751 std::vector<PGOAnalysisMap> *PGOAnalyses) {
752 using Elf_Shdr =
typename ELFT::Shdr;
754 std::vector<BBAddrMap> BBAddrMaps;
756 PGOAnalyses->clear();
762 if (!TextSectionIndex)
766 return createError(
"unable to get the linked-to section for " +
769 assert(*TextSecOrErr >= Sections.begin() &&
770 "Text section pointer outside of bounds");
771 if (*TextSectionIndex !=
772 (
unsigned)std::distance(Sections.begin(), *TextSecOrErr))
779 if (!SectionRelocMapOrErr)
782 for (
auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
783 if (IsRelocatable && !RelocSec)
784 return createError(
"unable to get relocation section for " +
788 if (!BBAddrMapOrErr) {
790 PGOAnalyses->clear();
791 return createError(
"unable to read BB addr map section: " +
794 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
795 std::back_inserter(BBAddrMaps));
798 assert(PGOAnalyses->size() == BBAddrMaps.size() &&
799 "The same number of BBAddrMaps and PGOAnalysisMaps should be "
800 "returned when PGO information is requested");
805static Expected<std::vector<VersionEntry>>
808 using Elf_Shdr =
typename ELFT::Shdr;
809 const Elf_Shdr *VerSec =
nullptr;
810 const Elf_Shdr *VerNeedSec =
nullptr;
811 const Elf_Shdr *VerDefSec =
nullptr;
822 return std::vector<VersionEntry>();
829 std::vector<VersionEntry> Ret;
834 EF.template getEntry<typename ELFT::Versym>(*VerSec,
I);
837 " from " +
describe(EF, *VerSec) +
": " +
842 return createError(
"unable to read flags for symbol with index " +
847 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
851 " of " +
describe(EF, *VerSec) +
": " +
854 Ret.push_back({(*VerOrErr).str(), IsDefault});
860Expected<std::vector<VersionEntry>>
874 std::optional<unsigned> TextSectionIndex,
875 std::vector<PGOAnalysisMap> *PGOAnalyses)
const {
883 TextSectionIndex, PGOAnalyses);
889 return Obj->getCrelDecodeProblem(
Data);
891 return Obj->getCrelDecodeProblem(
Data);
893 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.