LLVM 17.0.0git
ELFObjectFile.cpp
Go to the documentation of this file.
1//===- ELFObjectFile.cpp - ELF object file implementation -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Part of the ELFObjectFile class implementation.
10//
11//===----------------------------------------------------------------------===//
12
18#include "llvm/Object/ELF.h"
20#include "llvm/Object/Error.h"
29#include <algorithm>
30#include <cstddef>
31#include <cstdint>
32#include <memory>
33#include <optional>
34#include <string>
35#include <utility>
36
37using namespace llvm;
38using namespace object;
39
41 {"None", "NOTYPE", ELF::STT_NOTYPE},
42 {"Object", "OBJECT", ELF::STT_OBJECT},
43 {"Function", "FUNC", ELF::STT_FUNC},
44 {"Section", "SECTION", ELF::STT_SECTION},
45 {"File", "FILE", ELF::STT_FILE},
46 {"Common", "COMMON", ELF::STT_COMMON},
47 {"TLS", "TLS", ELF::STT_TLS},
48 {"Unknown", "<unknown>: 7", 7},
49 {"Unknown", "<unknown>: 8", 8},
50 {"Unknown", "<unknown>: 9", 9},
51 {"GNU_IFunc", "IFUNC", ELF::STT_GNU_IFUNC},
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}
57};
58
60 : ObjectFile(Type, Source) {}
61
62template <class ELFT>
64createPtr(MemoryBufferRef Object, bool InitContent) {
65 auto Ret = ELFObjectFile<ELFT>::create(Object, InitContent);
66 if (Error E = Ret.takeError())
67 return std::move(E);
68 return std::make_unique<ELFObjectFile<ELFT>>(std::move(*Ret));
69}
70
73 std::pair<unsigned char, unsigned char> Ident =
75 std::size_t MaxAlignment =
76 1ULL << llvm::countr_zero(
77 reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
78
79 if (MaxAlignment < 2)
80 return createError("Insufficient alignment");
81
82 if (Ident.first == ELF::ELFCLASS32) {
83 if (Ident.second == ELF::ELFDATA2LSB)
84 return createPtr<ELF32LE>(Obj, InitContent);
85 else if (Ident.second == ELF::ELFDATA2MSB)
86 return createPtr<ELF32BE>(Obj, InitContent);
87 else
88 return createError("Invalid ELF data");
89 } else if (Ident.first == ELF::ELFCLASS64) {
90 if (Ident.second == ELF::ELFDATA2LSB)
91 return createPtr<ELF64LE>(Obj, InitContent);
92 else if (Ident.second == ELF::ELFDATA2MSB)
93 return createPtr<ELF64BE>(Obj, InitContent);
94 else
95 return createError("Invalid ELF data");
96 }
97 return createError("Invalid ELF class");
98}
99
100SubtargetFeatures ELFObjectFileBase::getMIPSFeatures() const {
101 SubtargetFeatures Features;
102 unsigned PlatformFlags = getPlatformFlags();
103
104 switch (PlatformFlags & ELF::EF_MIPS_ARCH) {
106 break;
108 Features.AddFeature("mips2");
109 break;
111 Features.AddFeature("mips3");
112 break;
114 Features.AddFeature("mips4");
115 break;
117 Features.AddFeature("mips5");
118 break;
120 Features.AddFeature("mips32");
121 break;
123 Features.AddFeature("mips64");
124 break;
126 Features.AddFeature("mips32r2");
127 break;
129 Features.AddFeature("mips64r2");
130 break;
132 Features.AddFeature("mips32r6");
133 break;
135 Features.AddFeature("mips64r6");
136 break;
137 default:
138 llvm_unreachable("Unknown EF_MIPS_ARCH value");
139 }
140
141 switch (PlatformFlags & ELF::EF_MIPS_MACH) {
143 // No feature associated with this value.
144 break;
146 Features.AddFeature("cnmips");
147 break;
148 default:
149 llvm_unreachable("Unknown EF_MIPS_ARCH value");
150 }
151
152 if (PlatformFlags & ELF::EF_MIPS_ARCH_ASE_M16)
153 Features.AddFeature("mips16");
154 if (PlatformFlags & ELF::EF_MIPS_MICROMIPS)
155 Features.AddFeature("micromips");
156
157 return Features;
158}
159
160SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
161 SubtargetFeatures Features;
163 if (Error E = getBuildAttributes(Attributes)) {
164 consumeError(std::move(E));
165 return SubtargetFeatures();
166 }
167
168 // both ARMv7-M and R have to support thumb hardware div
169 bool isV7 = false;
170 std::optional<unsigned> Attr =
171 Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
172 if (Attr)
173 isV7 = *Attr == ARMBuildAttrs::v7;
174
175 Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
176 if (Attr) {
177 switch (*Attr) {
179 Features.AddFeature("aclass");
180 break;
182 Features.AddFeature("rclass");
183 if (isV7)
184 Features.AddFeature("hwdiv");
185 break;
187 Features.AddFeature("mclass");
188 if (isV7)
189 Features.AddFeature("hwdiv");
190 break;
191 }
192 }
193
194 Attr = Attributes.getAttributeValue(ARMBuildAttrs::THUMB_ISA_use);
195 if (Attr) {
196 switch (*Attr) {
197 default:
198 break;
200 Features.AddFeature("thumb", false);
201 Features.AddFeature("thumb2", false);
202 break;
204 Features.AddFeature("thumb2");
205 break;
206 }
207 }
208
209 Attr = Attributes.getAttributeValue(ARMBuildAttrs::FP_arch);
210 if (Attr) {
211 switch (*Attr) {
212 default:
213 break;
215 Features.AddFeature("vfp2sp", false);
216 Features.AddFeature("vfp3d16sp", false);
217 Features.AddFeature("vfp4d16sp", false);
218 break;
220 Features.AddFeature("vfp2");
221 break;
224 Features.AddFeature("vfp3");
225 break;
228 Features.AddFeature("vfp4");
229 break;
230 }
231 }
232
233 Attr = Attributes.getAttributeValue(ARMBuildAttrs::Advanced_SIMD_arch);
234 if (Attr) {
235 switch (*Attr) {
236 default:
237 break;
239 Features.AddFeature("neon", false);
240 Features.AddFeature("fp16", false);
241 break;
243 Features.AddFeature("neon");
244 break;
246 Features.AddFeature("neon");
247 Features.AddFeature("fp16");
248 break;
249 }
250 }
251
252 Attr = Attributes.getAttributeValue(ARMBuildAttrs::MVE_arch);
253 if (Attr) {
254 switch (*Attr) {
255 default:
256 break;
258 Features.AddFeature("mve", false);
259 Features.AddFeature("mve.fp", false);
260 break;
262 Features.AddFeature("mve.fp", false);
263 Features.AddFeature("mve");
264 break;
266 Features.AddFeature("mve.fp");
267 break;
268 }
269 }
270
271 Attr = Attributes.getAttributeValue(ARMBuildAttrs::DIV_use);
272 if (Attr) {
273 switch (*Attr) {
274 default:
275 break;
277 Features.AddFeature("hwdiv", false);
278 Features.AddFeature("hwdiv-arm", false);
279 break;
281 Features.AddFeature("hwdiv");
282 Features.AddFeature("hwdiv-arm");
283 break;
284 }
285 }
286
287 return Features;
288}
289
290Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures() const {
291 SubtargetFeatures Features;
292 unsigned PlatformFlags = getPlatformFlags();
293
294 if (PlatformFlags & ELF::EF_RISCV_RVC) {
295 Features.AddFeature("c");
296 }
297
299 if (Error E = getBuildAttributes(Attributes)) {
300 return std::move(E);
301 }
302
303 std::optional<StringRef> Attr =
304 Attributes.getAttributeString(RISCVAttrs::ARCH);
305 if (Attr) {
306 // Suppress version checking for experimental extensions to prevent erroring
307 // when getting any unknown version of experimental extension.
308 auto ParseResult = RISCVISAInfo::parseArchString(
309 *Attr, /*EnableExperimentalExtension=*/true,
310 /*ExperimentalExtensionVersionCheck=*/false,
311 /*IgnoreUnknown=*/true);
312 if (!ParseResult)
313 return ParseResult.takeError();
314 auto &ISAInfo = *ParseResult;
315
316 if (ISAInfo->getXLen() == 32)
317 Features.AddFeature("64bit", false);
318 else if (ISAInfo->getXLen() == 64)
319 Features.AddFeature("64bit");
320 else
321 llvm_unreachable("XLEN should be 32 or 64.");
322
323 Features.addFeaturesVector(ISAInfo->toFeatureVector());
324 }
325
326 return Features;
327}
328
329SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures() const {
330 SubtargetFeatures Features;
331
334 break;
336 Features.AddFeature("d");
337 // D implies F according to LoongArch ISA spec.
338 [[fallthrough]];
340 Features.AddFeature("f");
341 break;
342 }
343
344 return Features;
345}
346
348 switch (getEMachine()) {
349 case ELF::EM_MIPS:
350 return getMIPSFeatures();
351 case ELF::EM_ARM:
352 return getARMFeatures();
353 case ELF::EM_RISCV:
354 return getRISCVFeatures();
356 return getLoongArchFeatures();
357 default:
358 return SubtargetFeatures();
359 }
360}
361
362std::optional<StringRef> ELFObjectFileBase::tryGetCPUName() const {
363 switch (getEMachine()) {
364 case ELF::EM_AMDGPU:
365 return getAMDGPUCPUName();
366 case ELF::EM_PPC64:
367 return StringRef("future");
368 default:
369 return std::nullopt;
370 }
371}
372
373StringRef ELFObjectFileBase::getAMDGPUCPUName() const {
375 unsigned CPU = getPlatformFlags() & ELF::EF_AMDGPU_MACH;
376
377 switch (CPU) {
378 // Radeon HD 2000/3000 Series (R600).
380 return "r600";
382 return "r630";
384 return "rs880";
386 return "rv670";
387
388 // Radeon HD 4000 Series (R700).
390 return "rv710";
392 return "rv730";
394 return "rv770";
395
396 // Radeon HD 5000 Series (Evergreen).
398 return "cedar";
400 return "cypress";
402 return "juniper";
404 return "redwood";
406 return "sumo";
407
408 // Radeon HD 6000 Series (Northern Islands).
410 return "barts";
412 return "caicos";
414 return "cayman";
416 return "turks";
417
418 // AMDGCN GFX6.
420 return "gfx600";
422 return "gfx601";
424 return "gfx602";
425
426 // AMDGCN GFX7.
428 return "gfx700";
430 return "gfx701";
432 return "gfx702";
434 return "gfx703";
436 return "gfx704";
438 return "gfx705";
439
440 // AMDGCN GFX8.
442 return "gfx801";
444 return "gfx802";
446 return "gfx803";
448 return "gfx805";
450 return "gfx810";
451
452 // AMDGCN GFX9.
454 return "gfx900";
456 return "gfx902";
458 return "gfx904";
460 return "gfx906";
462 return "gfx908";
464 return "gfx909";
466 return "gfx90a";
468 return "gfx90c";
470 return "gfx940";
471
472 // AMDGCN GFX10.
474 return "gfx1010";
476 return "gfx1011";
478 return "gfx1012";
480 return "gfx1013";
482 return "gfx1030";
484 return "gfx1031";
486 return "gfx1032";
488 return "gfx1033";
490 return "gfx1034";
492 return "gfx1035";
494 return "gfx1036";
495
496 // AMDGCN GFX11.
498 return "gfx1100";
500 return "gfx1101";
502 return "gfx1102";
504 return "gfx1103";
505 default:
506 llvm_unreachable("Unknown EF_AMDGPU_MACH value");
507 }
508}
509
510// FIXME Encode from a tablegen description or target parser.
512 if (TheTriple.getSubArch() != Triple::NoSubArch)
513 return;
514
517 // TODO Propagate Error.
518 consumeError(std::move(E));
519 return;
520 }
521
522 std::string Triple;
523 // Default to ARM, but use the triple if it's been set.
524 if (TheTriple.isThumb())
525 Triple = "thumb";
526 else
527 Triple = "arm";
528
529 std::optional<unsigned> Attr =
530 Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
531 if (Attr) {
532 switch (*Attr) {
534 Triple += "v4";
535 break;
537 Triple += "v4t";
538 break;
540 Triple += "v5t";
541 break;
543 Triple += "v5te";
544 break;
546 Triple += "v5tej";
547 break;
549 Triple += "v6";
550 break;
552 Triple += "v6kz";
553 break;
555 Triple += "v6t2";
556 break;
558 Triple += "v6k";
559 break;
560 case ARMBuildAttrs::v7: {
561 std::optional<unsigned> ArchProfileAttr =
563 if (ArchProfileAttr &&
564 *ArchProfileAttr == ARMBuildAttrs::MicroControllerProfile)
565 Triple += "v7m";
566 else
567 Triple += "v7";
568 break;
569 }
571 Triple += "v6m";
572 break;
574 Triple += "v6sm";
575 break;
577 Triple += "v7em";
578 break;
580 Triple += "v8a";
581 break;
583 Triple += "v8r";
584 break;
586 Triple += "v8m.base";
587 break;
589 Triple += "v8m.main";
590 break;
592 Triple += "v8.1m.main";
593 break;
595 Triple += "v9a";
596 break;
597 }
598 }
599 if (!isLittleEndian())
600 Triple += "eb";
601
602 TheTriple.setArchName(Triple);
603}
604
605std::vector<std::pair<std::optional<DataRefImpl>, uint64_t>>
607 std::string Err;
608 const auto Triple = makeTriple();
609 const auto *T = TargetRegistry::lookupTarget(Triple.str(), Err);
610 if (!T)
611 return {};
612 uint64_t JumpSlotReloc = 0;
613 switch (Triple.getArch()) {
614 case Triple::x86:
615 JumpSlotReloc = ELF::R_386_JUMP_SLOT;
616 break;
617 case Triple::x86_64:
618 JumpSlotReloc = ELF::R_X86_64_JUMP_SLOT;
619 break;
620 case Triple::aarch64:
622 JumpSlotReloc = ELF::R_AARCH64_JUMP_SLOT;
623 break;
624 default:
625 return {};
626 }
627 std::unique_ptr<const MCInstrInfo> MII(T->createMCInstrInfo());
628 std::unique_ptr<const MCInstrAnalysis> MIA(
629 T->createMCInstrAnalysis(MII.get()));
630 if (!MIA)
631 return {};
632 std::optional<SectionRef> Plt, RelaPlt, GotPlt;
633 for (const SectionRef &Section : sections()) {
634 Expected<StringRef> NameOrErr = Section.getName();
635 if (!NameOrErr) {
636 consumeError(NameOrErr.takeError());
637 continue;
638 }
639 StringRef Name = *NameOrErr;
640
641 if (Name == ".plt")
642 Plt = Section;
643 else if (Name == ".rela.plt" || Name == ".rel.plt")
644 RelaPlt = Section;
645 else if (Name == ".got.plt")
646 GotPlt = Section;
647 }
648 if (!Plt || !RelaPlt || !GotPlt)
649 return {};
650 Expected<StringRef> PltContents = Plt->getContents();
651 if (!PltContents) {
652 consumeError(PltContents.takeError());
653 return {};
654 }
655 auto PltEntries = MIA->findPltEntries(Plt->getAddress(),
656 arrayRefFromStringRef(*PltContents),
657 GotPlt->getAddress(), Triple);
658 // Build a map from GOT entry virtual address to PLT entry virtual address.
660 for (const auto &Entry : PltEntries)
661 GotToPlt.insert(std::make_pair(Entry.second, Entry.first));
662 // Find the relocations in the dynamic relocation table that point to
663 // locations in the GOT for which we know the corresponding PLT entry.
664 std::vector<std::pair<std::optional<DataRefImpl>, uint64_t>> Result;
665 for (const auto &Relocation : RelaPlt->relocations()) {
666 if (Relocation.getType() != JumpSlotReloc)
667 continue;
668 auto PltEntryIter = GotToPlt.find(Relocation.getOffset());
669 if (PltEntryIter != GotToPlt.end()) {
670 symbol_iterator Sym = Relocation.getSymbol();
671 if (Sym == symbol_end())
672 Result.emplace_back(std::nullopt, PltEntryIter->second);
673 else
674 Result.emplace_back(Sym->getRawDataRefImpl(), PltEntryIter->second);
675 }
676 }
677 return Result;
678}
679
680template <class ELFT>
682 const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex) {
683 using Elf_Shdr = typename ELFT::Shdr;
684 bool IsRelocatable = EF.getHeader().e_type == ELF::ET_REL;
685 std::vector<BBAddrMap> BBAddrMaps;
686
687 const auto &Sections = cantFail(EF.sections());
688 auto IsMatch = [&](const Elf_Shdr &Sec) -> Expected<bool> {
689 if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP &&
690 Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP_V0)
691 return false;
692 if (!TextSectionIndex)
693 return true;
694 Expected<const Elf_Shdr *> TextSecOrErr = EF.getSection(Sec.sh_link);
695 if (!TextSecOrErr)
696 return createError("unable to get the linked-to section for " +
697 describe(EF, Sec) + ": " +
698 toString(TextSecOrErr.takeError()));
699 if (*TextSectionIndex != std::distance(Sections.begin(), *TextSecOrErr))
700 return false;
701 return true;
702 };
703
705 EF.getSectionAndRelocations(IsMatch);
706 if (!SectionRelocMapOrErr)
707 return SectionRelocMapOrErr.takeError();
708
709 for (auto const &[Sec, RelocSec] : *SectionRelocMapOrErr) {
710 if (IsRelocatable && !RelocSec)
711 return createError("unable to get relocation section for " +
712 describe(EF, *Sec));
713 Expected<std::vector<BBAddrMap>> BBAddrMapOrErr =
714 EF.decodeBBAddrMap(*Sec, RelocSec);
715 if (!BBAddrMapOrErr)
716 return createError("unable to read " + describe(EF, *Sec) + ": " +
717 toString(BBAddrMapOrErr.takeError()));
718 std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
719 std::back_inserter(BBAddrMaps));
720 }
721 return BBAddrMaps;
722}
723
724template <class ELFT>
728 using Elf_Shdr = typename ELFT::Shdr;
729 const Elf_Shdr *VerSec = nullptr;
730 const Elf_Shdr *VerNeedSec = nullptr;
731 const Elf_Shdr *VerDefSec = nullptr;
732 // The user should ensure sections() can't fail here.
733 for (const Elf_Shdr &Sec : cantFail(EF.sections())) {
734 if (Sec.sh_type == ELF::SHT_GNU_versym)
735 VerSec = &Sec;
736 else if (Sec.sh_type == ELF::SHT_GNU_verdef)
737 VerDefSec = &Sec;
738 else if (Sec.sh_type == ELF::SHT_GNU_verneed)
739 VerNeedSec = &Sec;
740 }
741 if (!VerSec)
742 return std::vector<VersionEntry>();
743
745 EF.loadVersionMap(VerNeedSec, VerDefSec);
746 if (!MapOrErr)
747 return MapOrErr.takeError();
748
749 std::vector<VersionEntry> Ret;
750 size_t I = 0;
751 for (const ELFSymbolRef &Sym : Symbols) {
752 ++I;
754 EF.template getEntry<typename ELFT::Versym>(*VerSec, I);
755 if (!VerEntryOrErr)
756 return createError("unable to read an entry with index " + Twine(I) +
757 " from " + describe(EF, *VerSec) + ": " +
758 toString(VerEntryOrErr.takeError()));
759
760 Expected<uint32_t> FlagsOrErr = Sym.getFlags();
761 if (!FlagsOrErr)
762 return createError("unable to read flags for symbol with index " +
763 Twine(I) + ": " + toString(FlagsOrErr.takeError()));
764
765 bool IsDefault;
767 (*VerEntryOrErr)->vs_index, IsDefault, *MapOrErr,
768 (*FlagsOrErr) & SymbolRef::SF_Undefined);
769 if (!VerOrErr)
770 return createError("unable to get a version for entry " + Twine(I) +
771 " of " + describe(EF, *VerSec) + ": " +
772 toString(VerOrErr.takeError()));
773
774 Ret.push_back({(*VerOrErr).str(), IsDefault});
775 }
776
777 return Ret;
778}
779
783 if (const auto *Obj = dyn_cast<ELF32LEObjectFile>(this))
784 return readDynsymVersionsImpl(Obj->getELFFile(), Symbols);
785 if (const auto *Obj = dyn_cast<ELF32BEObjectFile>(this))
786 return readDynsymVersionsImpl(Obj->getELFFile(), Symbols);
787 if (const auto *Obj = dyn_cast<ELF64LEObjectFile>(this))
788 return readDynsymVersionsImpl(Obj->getELFFile(), Symbols);
789 return readDynsymVersionsImpl(cast<ELF64BEObjectFile>(this)->getELFFile(),
790 Symbols);
791}
792
794 std::optional<unsigned> TextSectionIndex) const {
795 if (const auto *Obj = dyn_cast<ELF32LEObjectFile>(this))
796 return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
797 if (const auto *Obj = dyn_cast<ELF64LEObjectFile>(this))
798 return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
799 if (const auto *Obj = dyn_cast<ELF32BEObjectFile>(this))
800 return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
801 return readBBAddrMapImpl(cast<ELF64BEObjectFile>(this)->getELFFile(),
802 TextSectionIndex);
803}
AMDGPU Kernel Attributes
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::string Name
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)
static Expected< std::vector< VersionEntry > > readDynsymVersionsImpl(const ELFFile< ELFT > &EF, ELFObjectFileBase::elf_symbol_iterator_range Symbols)
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
const char * getBufferStart() const
StringRef getBuffer() const
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true, bool IgnoreUnknown=false)
Parse RISCV ISA info from arch string.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Manages the enabling and disabling of subtarget specific features.
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
void addFeaturesVector(const ArrayRef< std::string > OtherFeatures)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void setArchName(StringRef Str)
Set the architecture (first) component of the triple by name.
Definition: Triple.cpp:1367
bool isThumb() const
Tests whether the target is Thumb (little and big endian).
Definition: Triple.h:784
SubArchType getSubArch() const
get the parsed subarchitecture type for this triple.
Definition: Triple.h:359
@ aarch64_be
Definition: Triple.h:52
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:356
const std::string & str() const
Definition: Triple.h:415
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A range adaptor for a pair of iterators.
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:210
bool isLittleEndian() const
Definition: Binary.h:152
const Elf_Ehdr & getHeader() const
Definition: ELF.h:192
Expected< std::vector< BBAddrMap > > decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec=nullptr) const
Returns a vector of BBAddrMap structs corresponding to each function within the text section that the...
Definition: ELF.cpp:643
Expected< StringRef > getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, SmallVector< std::optional< VersionEntry >, 0 > &VersionMap, std::optional< bool > IsSymHidden) const
Definition: ELF.h:892
Expected< Elf_Shdr_Range > sections() const
Definition: ELF.h:812
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 ...
Definition: ELF.cpp:744
Expected< SmallVector< std::optional< VersionEntry >, 0 > > loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const
Definition: ELF.h:606
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, DataRegion< Elf_Word > ShndxTable) const
Definition: ELF.h:464
std::vector< std::pair< std::optional< DataRefImpl >, uint64_t > > getPltAddresses() const
Expected< std::vector< BBAddrMap > > readBBAddrMap(std::optional< unsigned > TextSectionIndex=std::nullopt) const
Returns a vector of all BB address maps in the object file. When.
virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const =0
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
Expected< SubtargetFeatures > getFeatures() const override
std::optional< StringRef > tryGetCPUName() const override
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
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
This class is the base class for all object file types.
Definition: ObjectFile.h:228
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.
Definition: ObjectFile.cpp:109
section_iterator_range sections() const
Definition: ObjectFile.h:327
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
virtual basic_symbol_iterator symbol_end() const =0
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition: ELF.h:918
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition: ELF.h:919
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition: ELF.h:917
@ EF_LOONGARCH_ABI_MODIFIER_MASK
Definition: ELF.h:920
@ ELFCLASS64
Definition: ELF.h:329
@ ELFCLASS32
Definition: ELF.h:328
@ EM_PPC64
Definition: ELF.h:149
@ EM_LOONGARCH
Definition: ELF.h:322
@ EM_MIPS
Definition: ELF.h:141
@ EM_RISCV
Definition: ELF.h:317
@ EM_ARM
Definition: ELF.h:156
@ EM_AMDGPU
Definition: ELF.h:316
@ ELFDATA2MSB
Definition: ELF.h:336
@ ELFDATA2LSB
Definition: ELF.h:335
@ EF_RISCV_RVC
Definition: ELF.h:670
@ SHT_LLVM_BB_ADDR_MAP_V0
Definition: ELF.h:1028
@ SHT_GNU_verneed
Definition: ELF.h:1040
@ SHT_GNU_verdef
Definition: ELF.h:1039
@ SHT_LLVM_BB_ADDR_MAP
Definition: ELF.h:1032
@ SHT_GNU_versym
Definition: ELF.h:1041
@ EF_AMDGPU_MACH_AMDGCN_GFX703
Definition: ELF.h:746
@ EF_AMDGPU_MACH_AMDGCN_GFX1035
Definition: ELF.h:770
@ EF_AMDGPU_MACH_AMDGCN_GFX1031
Definition: ELF.h:764
@ EF_AMDGPU_MACH_R600_CAYMAN
Definition: ELF.h:729
@ EF_AMDGPU_MACH_AMDGCN_GFX704
Definition: ELF.h:747
@ EF_AMDGPU_MACH_AMDGCN_GFX902
Definition: ELF.h:754
@ EF_AMDGPU_MACH_AMDGCN_GFX810
Definition: ELF.h:752
@ EF_AMDGPU_MACH_AMDGCN_GFX1036
Definition: ELF.h:778
@ EF_AMDGPU_MACH_AMDGCN_GFX1102
Definition: ELF.h:780
@ EF_AMDGPU_MACH_R600_RV730
Definition: ELF.h:718
@ EF_AMDGPU_MACH_R600_RV710
Definition: ELF.h:717
@ EF_AMDGPU_MACH_AMDGCN_GFX908
Definition: ELF.h:757
@ EF_AMDGPU_MACH_AMDGCN_GFX1011
Definition: ELF.h:761
@ EF_AMDGPU_MACH_R600_CYPRESS
Definition: ELF.h:722
@ EF_AMDGPU_MACH_AMDGCN_GFX1032
Definition: ELF.h:765
@ EF_AMDGPU_MACH_R600_R600
Definition: ELF.h:712
@ EF_AMDGPU_MACH_AMDGCN_GFX940
Definition: ELF.h:773
@ EF_AMDGPU_MACH_R600_TURKS
Definition: ELF.h:730
@ EF_AMDGPU_MACH_R600_JUNIPER
Definition: ELF.h:723
@ EF_AMDGPU_MACH_AMDGCN_GFX601
Definition: ELF.h:742
@ EF_AMDGPU_MACH_R600_R630
Definition: ELF.h:713
@ EF_AMDGPU_MACH_R600_REDWOOD
Definition: ELF.h:724
@ EF_AMDGPU_MACH_R600_RV770
Definition: ELF.h:719
@ EF_AMDGPU_MACH_AMDGCN_GFX600
Definition: ELF.h:741
@ EF_AMDGPU_MACH_AMDGCN_GFX602
Definition: ELF.h:767
@ EF_AMDGPU_MACH_AMDGCN_GFX1101
Definition: ELF.h:779
@ EF_AMDGPU_MACH_AMDGCN_GFX1100
Definition: ELF.h:774
@ EF_AMDGPU_MACH_AMDGCN_GFX1033
Definition: ELF.h:766
@ EF_AMDGPU_MACH_AMDGCN_GFX801
Definition: ELF.h:749
@ EF_AMDGPU_MACH_AMDGCN_GFX705
Definition: ELF.h:768
@ EF_AMDGPU_MACH_AMDGCN_GFX1010
Definition: ELF.h:760
@ EF_AMDGPU_MACH_R600_RV670
Definition: ELF.h:715
@ EF_AMDGPU_MACH_AMDGCN_GFX701
Definition: ELF.h:744
@ EF_AMDGPU_MACH_AMDGCN_GFX1012
Definition: ELF.h:762
@ EF_AMDGPU_MACH_AMDGCN_GFX1030
Definition: ELF.h:763
@ EF_AMDGPU_MACH_R600_CEDAR
Definition: ELF.h:721
@ EF_AMDGPU_MACH_AMDGCN_GFX700
Definition: ELF.h:743
@ EF_AMDGPU_MACH_AMDGCN_GFX803
Definition: ELF.h:751
@ EF_AMDGPU_MACH_AMDGCN_GFX802
Definition: ELF.h:750
@ EF_AMDGPU_MACH_AMDGCN_GFX90C
Definition: ELF.h:759
@ EF_AMDGPU_MACH_AMDGCN_GFX900
Definition: ELF.h:753
@ EF_AMDGPU_MACH_AMDGCN_GFX909
Definition: ELF.h:758
@ EF_AMDGPU_MACH
Definition: ELF.h:704
@ EF_AMDGPU_MACH_AMDGCN_GFX906
Definition: ELF.h:756
@ EF_AMDGPU_MACH_AMDGCN_GFX1103
Definition: ELF.h:777
@ EF_AMDGPU_MACH_R600_CAICOS
Definition: ELF.h:728
@ EF_AMDGPU_MACH_AMDGCN_GFX90A
Definition: ELF.h:772
@ EF_AMDGPU_MACH_AMDGCN_GFX1034
Definition: ELF.h:771
@ EF_AMDGPU_MACH_AMDGCN_GFX1013
Definition: ELF.h:775
@ EF_AMDGPU_MACH_AMDGCN_GFX904
Definition: ELF.h:755
@ EF_AMDGPU_MACH_R600_RS880
Definition: ELF.h:714
@ EF_AMDGPU_MACH_AMDGCN_GFX805
Definition: ELF.h:769
@ EF_AMDGPU_MACH_R600_SUMO
Definition: ELF.h:725
@ EF_AMDGPU_MACH_R600_BARTS
Definition: ELF.h:727
@ EF_AMDGPU_MACH_AMDGCN_GFX702
Definition: ELF.h:745
@ ET_REL
Definition: ELF.h:116
@ EF_MIPS_ARCH
Definition: ELF.h:565
@ EF_MIPS_MICROMIPS
Definition: ELF.h:548
@ EF_MIPS_ARCH_32R6
Definition: ELF.h:563
@ EF_MIPS_MACH_NONE
Definition: ELF.h:526
@ EF_MIPS_ARCH_64
Definition: ELF.h:560
@ EF_MIPS_ARCH_32
Definition: ELF.h:559
@ EF_MIPS_MACH_OCTEON
Definition: ELF.h:534
@ EF_MIPS_ARCH_4
Definition: ELF.h:557
@ EF_MIPS_ARCH_5
Definition: ELF.h:558
@ EF_MIPS_ARCH_2
Definition: ELF.h:555
@ EF_MIPS_ARCH_32R2
Definition: ELF.h:561
@ EF_MIPS_ARCH_64R2
Definition: ELF.h:562
@ EF_MIPS_ARCH_ASE_M16
Definition: ELF.h:549
@ EF_MIPS_MACH
Definition: ELF.h:545
@ EF_MIPS_ARCH_1
Definition: ELF.h:554
@ EF_MIPS_ARCH_64R6
Definition: ELF.h:564
@ EF_MIPS_ARCH_3
Definition: ELF.h:556
@ STT_FUNC
Definition: ELF.h:1250
@ STT_NOTYPE
Definition: ELF.h:1248
@ STT_SECTION
Definition: ELF.h:1251
@ STT_FILE
Definition: ELF.h:1252
@ STT_COMMON
Definition: ELF.h:1253
@ STT_GNU_IFUNC
Definition: ELF.h:1255
@ STT_OBJECT
Definition: ELF.h:1249
@ STT_TLS
Definition: ELF.h:1254
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Error createError(const Twine &Err)
Definition: Error.h:84
constexpr int NumElfSymbolTypes
Definition: ELFObjectFile.h:46
static std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
Definition: ELF.h:143
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
Definition: ELF.h:78
const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:179
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:745
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.