47class ContiguousBlobAccumulator {
60 "reached the output size limit");
66 : InitialOffset(BaseOffset), MaxSize(
SizeLimit),
OS(Buf) {}
70 void writeBlobToStream(
raw_ostream &Out)
const { Out <<
OS.str(); }
72 Error takeLimitError() {
75 return std::move(ReachedLimitErr);
85 uint64_t PaddingSize = AlignedOffset - CurrentOffset;
86 if (!checkLimit(PaddingSize))
89 writeZeros(PaddingSize);
100 if (!checkLimit(
Bin.binary_size()))
102 Bin.writeAsBinary(OS,
N);
111 if (checkLimit(
Size))
115 void write(
unsigned char C) {
120 unsigned writeULEB128(
uint64_t Val) {
126 unsigned writeSLEB128(int64_t Val) {
133 if (checkLimit(
sizeof(
T)))
134 support::endian::write<T>(OS, Val, E);
137 void updateDataAt(
uint64_t Pos,
void *Data,
size_t Size) {
139 memcpy(&Buf[Pos - InitialOffset], Data,
Size);
151 return Map.insert({
Name, Ndx}).second;
166 assert(
false &&
"Expected section not found in index");
169 unsigned size()
const {
return Map.size(); }
184template <
class ELFT>
class ELFState {
204 StringRef SectionHeaderStringTableName =
".shstrtab";
209 NameToIdxMap DynSymN2I;
215 bool HasError =
false;
225 void buildSectionIndex();
226 void buildSymbolIndexes();
227 void initProgramHeaders(std::vector<Elf_Phdr> &PHeaders);
228 bool initImplicitHeader(ContiguousBlobAccumulator &CBA, Elf_Shdr &Header,
230 void initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
231 ContiguousBlobAccumulator &CBA);
232 void initSymtabSectionHeader(Elf_Shdr &SHeader, SymtabType STType,
233 ContiguousBlobAccumulator &CBA,
235 void initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
237 ContiguousBlobAccumulator &CBA,
239 void initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
240 ContiguousBlobAccumulator &CBA,
242 void setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
243 std::vector<Elf_Shdr> &SHeaders);
245 std::vector<Fragment>
249 void finalizeStrings();
251 void writeSectionContent(Elf_Shdr &SHeader,
253 ContiguousBlobAccumulator &CBA);
254 void writeSectionContent(Elf_Shdr &SHeader,
256 ContiguousBlobAccumulator &CBA);
257 void writeSectionContent(Elf_Shdr &SHeader,
259 ContiguousBlobAccumulator &CBA);
260 void writeSectionContent(Elf_Shdr &SHeader,
262 ContiguousBlobAccumulator &CBA);
263 void writeSectionContent(Elf_Shdr &SHeader,
265 ContiguousBlobAccumulator &CBA);
266 void writeSectionContent(Elf_Shdr &SHeader,
268 ContiguousBlobAccumulator &CBA);
269 void writeSectionContent(Elf_Shdr &SHeader,
271 ContiguousBlobAccumulator &CBA);
272 void writeSectionContent(Elf_Shdr &SHeader,
274 ContiguousBlobAccumulator &CBA);
275 void writeSectionContent(Elf_Shdr &SHeader,
277 ContiguousBlobAccumulator &CBA);
278 void writeSectionContent(Elf_Shdr &SHeader,
280 ContiguousBlobAccumulator &CBA);
281 void writeSectionContent(Elf_Shdr &SHeader,
283 ContiguousBlobAccumulator &CBA);
284 void writeSectionContent(Elf_Shdr &SHeader,
286 ContiguousBlobAccumulator &CBA);
287 void writeSectionContent(Elf_Shdr &SHeader,
289 ContiguousBlobAccumulator &CBA);
290 void writeSectionContent(Elf_Shdr &SHeader,
292 ContiguousBlobAccumulator &CBA);
293 void writeSectionContent(Elf_Shdr &SHeader,
295 ContiguousBlobAccumulator &CBA);
296 void writeSectionContent(Elf_Shdr &SHeader,
298 ContiguousBlobAccumulator &CBA);
299 void writeSectionContent(Elf_Shdr &SHeader,
301 ContiguousBlobAccumulator &CBA);
302 void writeSectionContent(Elf_Shdr &SHeader,
304 ContiguousBlobAccumulator &CBA);
305 void writeSectionContent(Elf_Shdr &SHeader,
307 ContiguousBlobAccumulator &CBA);
308 void writeSectionContent(Elf_Shdr &SHeader,
310 ContiguousBlobAccumulator &CBA);
311 void writeSectionContent(Elf_Shdr &SHeader,
313 ContiguousBlobAccumulator &CBA);
315 void writeFill(
ELFYAML::Fill &Fill, ContiguousBlobAccumulator &CBA);
325 std::optional<llvm::yaml::Hex64>
Offset);
336 return A.size() *
sizeof(
T);
343template <
class T>
static void zero(
T &Obj) { memset(&Obj, 0,
sizeof(Obj)); }
347 : Doc(
D), ErrHandler(EH) {
351 if (Doc.Header.SectionHeaderStringTable) {
352 SectionHeaderStringTableName = *Doc.Header.SectionHeaderStringTable;
353 if (*Doc.Header.SectionHeaderStringTable ==
".strtab")
354 ShStrtabStrings = &DotStrtab;
355 else if (*Doc.Header.SectionHeaderStringTable ==
".dynstr")
356 ShStrtabStrings = &DotDynstr;
360 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
362 if (Sections.empty() || Sections.front()->Type !=
ELF::SHT_NULL)
365 std::make_unique<ELFYAML::Section>(
366 ELFYAML::Chunk::ChunkKind::RawContent,
true));
370 for (
size_t I = 0;
I < Doc.Chunks.size(); ++
I) {
371 const std::unique_ptr<ELFYAML::Chunk> &
C = Doc.Chunks[
I];
374 if (
auto S = dyn_cast<ELFYAML::SectionHeaderTable>(
C.get())) {
376 reportError(
"multiple section header tables are not allowed");
384 if (
C->Name.empty()) {
391 if (!DocSections.
insert(
C->Name).second)
393 "' at YAML section/fill number " +
Twine(
I));
397 if (Doc.DynamicSymbols) {
398 if (SectionHeaderStringTableName ==
".dynsym")
399 reportError(
"cannot use '.dynsym' as the section header name table when "
400 "there are dynamic symbols");
401 ImplicitSections.
insert(
".dynsym");
402 ImplicitSections.
insert(
".dynstr");
405 if (SectionHeaderStringTableName ==
".symtab")
406 reportError(
"cannot use '.symtab' as the section header name table when "
407 "there are symbols");
408 ImplicitSections.
insert(
".symtab");
411 for (
StringRef DebugSecName : Doc.DWARF->getNonEmptySectionNames()) {
412 std::string SecName = (
"." + DebugSecName).str();
415 if (SectionHeaderStringTableName == SecName)
417 "' as the section header name table when it is needed for "
422 ImplicitSections.
insert(
".strtab");
423 if (!SecHdrTable || !SecHdrTable->
NoHeaders.value_or(
false))
424 ImplicitSections.
insert(SectionHeaderStringTableName);
428 for (
StringRef SecName : ImplicitSections) {
429 if (DocSections.
count(SecName))
432 std::unique_ptr<ELFYAML::Section> Sec = std::make_unique<ELFYAML::Section>(
433 ELFYAML::Chunk::ChunkKind::RawContent,
true );
436 if (SecName == SectionHeaderStringTableName)
438 else if (SecName ==
".dynsym")
440 else if (SecName ==
".symtab")
450 if (Doc.Chunks.back().get() == SecHdrTable)
451 Doc.Chunks.insert(Doc.Chunks.end() - 1, std::move(Sec));
453 Doc.Chunks.push_back(std::move(Sec));
459 Doc.Chunks.push_back(
460 std::make_unique<ELFYAML::SectionHeaderTable>(
true));
469 Header.e_ident[
EI_MAG0] = 0x7f;
474 Header.e_ident[
EI_DATA] = Doc.Header.Data;
476 Header.e_ident[
EI_OSABI] = Doc.Header.OSABI;
478 Header.e_type = Doc.Header.Type;
480 if (Doc.Header.Machine)
481 Header.e_machine = *Doc.Header.Machine;
486 Header.e_entry = Doc.Header.Entry;
487 Header.e_flags = Doc.Header.Flags;
488 Header.e_ehsize =
sizeof(Elf_Ehdr);
490 if (Doc.Header.EPhOff)
491 Header.e_phoff = *Doc.Header.EPhOff;
492 else if (!Doc.ProgramHeaders.empty())
493 Header.e_phoff =
sizeof(Header);
497 if (Doc.Header.EPhEntSize)
498 Header.e_phentsize = *Doc.Header.EPhEntSize;
499 else if (!Doc.ProgramHeaders.empty())
500 Header.e_phentsize =
sizeof(Elf_Phdr);
502 Header.e_phentsize = 0;
504 if (Doc.Header.EPhNum)
505 Header.e_phnum = *Doc.Header.EPhNum;
506 else if (!Doc.ProgramHeaders.empty())
507 Header.e_phnum = Doc.ProgramHeaders.size();
511 Header.e_shentsize = Doc.Header.EShEntSize ? (
uint16_t)*Doc.Header.EShEntSize
515 Doc.getSectionHeaderTable();
517 if (Doc.Header.EShOff)
518 Header.e_shoff = *Doc.Header.EShOff;
519 else if (SectionHeaders.
Offset)
520 Header.e_shoff = *SectionHeaders.
Offset;
524 if (Doc.Header.EShNum)
525 Header.e_shnum = *Doc.Header.EShNum;
527 Header.e_shnum = SectionHeaders.
getNumHeaders(Doc.getSections().size());
529 if (Doc.Header.EShStrNdx)
530 Header.e_shstrndx = *Doc.Header.EShStrNdx;
531 else if (SectionHeaders.
Offset &&
532 !ExcludedSectionHeaders.count(SectionHeaderStringTableName))
533 Header.e_shstrndx = SN2I.get(SectionHeaderStringTableName);
535 Header.e_shstrndx = 0;
537 OS.
write((
const char *)&Header,
sizeof(Header));
541void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
544 for (
size_t I = 0, E = Doc.Chunks.size();
I != E; ++
I) {
545 if (
auto S = dyn_cast<ELFYAML::Fill>(Doc.Chunks[
I].get()))
546 NameToFill[S->Name] = S;
547 NameToIndex[Doc.Chunks[
I]->Name] =
I + 1;
550 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
551 for (
size_t I = 0, E = Doc.ProgramHeaders.size();
I != E; ++
I) {
555 Phdr.p_type = YamlPhdr.
Type;
556 Phdr.p_flags = YamlPhdr.
Flags;
557 Phdr.p_vaddr = YamlPhdr.
VAddr;
558 Phdr.p_paddr = YamlPhdr.
PAddr;
559 PHeaders.push_back(Phdr);
568 "' by the 'FirstSec' key of the program header with index " +
573 "' by the 'LastSec' key of the program header with index " +
580 ": the section index of " + *YamlPhdr.
FirstSec +
581 " is greater than the index of " + *YamlPhdr.
LastSec);
584 YamlPhdr.
Chunks.push_back(Doc.Chunks[
I - 1].get());
594 if (!SN2I.lookup(S,
Index) && !to_integer(S,
Index)) {
596 reportError(
"unknown section referenced: '" + S +
"' by YAML symbol '" +
599 reportError(
"unknown section referenced: '" + S +
"' by YAML section '" +
605 Doc.getSectionHeaderTable();
612 size_t FirstExcluded =
614 if (
Index > FirstExcluded) {
616 reportError(
"unable to link '" + LocSec +
"' to excluded section '" + S +
619 reportError(
"excluded section referenced: '" + S +
"' by symbol '" +
628 const NameToIdxMap &
SymMap = IsDynamic ? DynSymN2I : SymN2I;
633 reportError(
"unknown symbol referenced: '" + S +
"' by YAML section '" +
644 if (
From->ShAddrAlign)
645 To.sh_addralign = *
From->ShAddrAlign;
647 To.sh_flags = *
From->ShFlags;
649 To.sh_name = *
From->ShName;
651 To.sh_offset = *
From->ShOffset;
653 To.sh_size = *
From->ShSize;
655 To.sh_type = *
From->ShType;
659bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
663 if (Header.sh_offset)
666 if (SecName ==
".strtab")
667 initStrtabSectionHeader(Header, SecName, DotStrtab, CBA, YAMLSec);
668 else if (SecName ==
".dynstr")
669 initStrtabSectionHeader(Header, SecName, DotDynstr, CBA, YAMLSec);
670 else if (SecName == SectionHeaderStringTableName)
671 initStrtabSectionHeader(Header, SecName, *ShStrtabStrings, CBA, YAMLSec);
672 else if (SecName ==
".symtab")
673 initSymtabSectionHeader(Header, SymtabType::Static, CBA, YAMLSec);
674 else if (SecName ==
".dynsym")
675 initSymtabSectionHeader(Header, SymtabType::Dynamic, CBA, YAMLSec);
679 if (YAMLSec && !isa<ELFYAML::RawContentSection>(YAMLSec))
681 initDWARFSectionHeader(Header, SecName, CBA, YAMLSec);
685 LocationCounter += Header.sh_size;
688 overrideFields<ELFT>(YAMLSec, Header);
698 std::string Ret =
Name.empty() ?
"" :
Name.str() +
' ';
713 return S.
substr(0, SuffixPos - 1);
720 if (ExcludedSectionHeaders.count(
Name))
722 return ShStrtabStrings->getOffset(
Name);
726 const std::optional<yaml::BinaryRef> &
Content,
727 const std::optional<llvm::yaml::Hex64> &
Size) {
728 size_t ContentSize = 0;
731 ContentSize =
Content->binary_size();
737 CBA.writeZeros(*
Size - ContentSize);
765void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
766 ContiguousBlobAccumulator &CBA) {
769 SHeaders.resize(Doc.getSections().size());
771 for (
const std::unique_ptr<ELFYAML::Chunk> &
D : Doc.Chunks) {
773 S->Offset = alignToOffset(CBA, 1, S->Offset);
775 LocationCounter += S->Size;
780 dyn_cast<ELFYAML::SectionHeaderTable>(
D.get())) {
781 if (S->NoHeaders.value_or(
false))
785 S->Offset = alignToOffset(CBA,
sizeof(
typename ELFT::uint),
788 S->Offset = alignToOffset(CBA, 1, S->Offset);
790 uint64_t Size = S->getNumHeaders(SHeaders.size()) *
sizeof(Elf_Shdr);
793 CBA.writeZeros(
Size);
794 LocationCounter +=
Size;
799 bool IsFirstUndefSection = Sec == Doc.getSections().front();
803 Elf_Shdr &SHeader = SHeaders[SN2I.get(Sec->
Name)];
805 SHeader.sh_link = toSectionIndex(*Sec->
Link, Sec->
Name);
809 if (!LinkSec.
empty() && !ExcludedSectionHeaders.count(LinkSec) &&
810 SN2I.lookup(LinkSec, Link))
811 SHeader.sh_link =
Link;
815 SHeader.sh_entsize = *Sec->
EntSize;
817 SHeader.sh_entsize = ELFYAML::getDefaultShEntSize<ELFT>(
824 if (initImplicitHeader(CBA, SHeader, Sec->
Name,
828 assert(Sec &&
"It can't be null unless it is an implicit section. But all "
829 "implicit sections should already have been handled above.");
833 SHeader.sh_type = Sec->
Type;
835 SHeader.sh_flags = *Sec->
Flags;
840 if (!IsFirstUndefSection || Sec->
Offset)
841 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, Sec->
Offset);
843 assignSectionAddress(SHeader, Sec);
845 if (IsFirstUndefSection) {
846 if (
auto RawSec = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
849 SHeader.sh_size = *RawSec->Size;
851 SHeader.sh_info = *RawSec->Info;
854 LocationCounter += SHeader.sh_size;
855 overrideFields<ELFT>(Sec, SHeader);
859 if (!isa<ELFYAML::NoBitsSection>(Sec) && (Sec->
Content || Sec->
Size))
862 if (
auto S = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
863 writeSectionContent(SHeader, *S, CBA);
864 }
else if (
auto S = dyn_cast<ELFYAML::SymtabShndxSection>(Sec)) {
865 writeSectionContent(SHeader, *S, CBA);
866 }
else if (
auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
867 writeSectionContent(SHeader, *S, CBA);
868 }
else if (
auto S = dyn_cast<ELFYAML::RelrSection>(Sec)) {
869 writeSectionContent(SHeader, *S, CBA);
870 }
else if (
auto S = dyn_cast<ELFYAML::GroupSection>(Sec)) {
871 writeSectionContent(SHeader, *S, CBA);
872 }
else if (
auto S = dyn_cast<ELFYAML::ARMIndexTableSection>(Sec)) {
873 writeSectionContent(SHeader, *S, CBA);
874 }
else if (
auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec)) {
875 writeSectionContent(SHeader, *S, CBA);
876 }
else if (
auto S = dyn_cast<ELFYAML::NoBitsSection>(Sec)) {
877 writeSectionContent(SHeader, *S, CBA);
878 }
else if (
auto S = dyn_cast<ELFYAML::DynamicSection>(Sec)) {
879 writeSectionContent(SHeader, *S, CBA);
880 }
else if (
auto S = dyn_cast<ELFYAML::SymverSection>(Sec)) {
881 writeSectionContent(SHeader, *S, CBA);
882 }
else if (
auto S = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
883 writeSectionContent(SHeader, *S, CBA);
884 }
else if (
auto S = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
885 writeSectionContent(SHeader, *S, CBA);
886 }
else if (
auto S = dyn_cast<ELFYAML::StackSizesSection>(Sec)) {
887 writeSectionContent(SHeader, *S, CBA);
888 }
else if (
auto S = dyn_cast<ELFYAML::HashSection>(Sec)) {
889 writeSectionContent(SHeader, *S, CBA);
890 }
else if (
auto S = dyn_cast<ELFYAML::AddrsigSection>(Sec)) {
891 writeSectionContent(SHeader, *S, CBA);
892 }
else if (
auto S = dyn_cast<ELFYAML::LinkerOptionsSection>(Sec)) {
893 writeSectionContent(SHeader, *S, CBA);
894 }
else if (
auto S = dyn_cast<ELFYAML::NoteSection>(Sec)) {
895 writeSectionContent(SHeader, *S, CBA);
896 }
else if (
auto S = dyn_cast<ELFYAML::GnuHashSection>(Sec)) {
897 writeSectionContent(SHeader, *S, CBA);
898 }
else if (
auto S = dyn_cast<ELFYAML::DependentLibrariesSection>(Sec)) {
899 writeSectionContent(SHeader, *S, CBA);
900 }
else if (
auto S = dyn_cast<ELFYAML::CallGraphProfileSection>(Sec)) {
901 writeSectionContent(SHeader, *S, CBA);
902 }
else if (
auto S = dyn_cast<ELFYAML::BBAddrMapSection>(Sec)) {
903 writeSectionContent(SHeader, *S, CBA);
908 LocationCounter += SHeader.sh_size;
911 overrideFields<ELFT>(Sec, SHeader);
916void ELFState<ELFT>::assignSectionAddress(Elf_Shdr &SHeader,
918 if (YAMLSec && YAMLSec->
Address) {
919 SHeader.sh_addr = *YAMLSec->
Address;
920 LocationCounter = *YAMLSec->
Address;
932 alignTo(LocationCounter, SHeader.sh_addralign ? SHeader.sh_addralign : 1);
933 SHeader.sh_addr = LocationCounter;
937 for (
size_t I = 0;
I < Symbols.size(); ++
I)
940 return Symbols.size();
944std::vector<typename ELFT::Sym>
947 std::vector<Elf_Sym>
Ret;
948 Ret.resize(Symbols.size() + 1);
959 else if (!
Sym.Name.empty())
964 Symbol.st_shndx = toSectionIndex(*
Sym.Section,
"",
Sym.Name);
968 Symbol.st_value =
Sym.Value.value_or(yaml::Hex64(0));
970 Symbol.st_size =
Sym.Size.value_or(yaml::Hex64(0));
977void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
979 ContiguousBlobAccumulator &CBA,
982 bool IsStatic = STType == SymtabType::Static;
984 if (IsStatic && Doc.Symbols)
985 Symbols = *Doc.Symbols;
986 else if (!IsStatic && Doc.DynamicSymbols)
987 Symbols = *Doc.DynamicSymbols;
990 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
992 bool HasSymbolsDescription =
993 (IsStatic && Doc.Symbols) || (!IsStatic && Doc.DynamicSymbols);
994 if (HasSymbolsDescription) {
995 StringRef Property = (IsStatic ?
"`Symbols`" :
"`DynamicSymbols`");
997 reportError(
"cannot specify both `Content` and " + Property +
998 " for symbol table section '" + RawSec->
Name +
"'");
1000 reportError(
"cannot specify both `Size` and " + Property +
1001 " for symbol table section '" + RawSec->
Name +
"'");
1006 SHeader.sh_name = getSectionNameOffset(IsStatic ?
".symtab" :
".dynsym");
1009 SHeader.sh_type = YAMLSec->
Type;
1013 if (YAMLSec && YAMLSec->
Flags)
1014 SHeader.sh_flags = *YAMLSec->
Flags;
1020 SHeader.sh_info = (RawSec && RawSec->
Info) ? (
unsigned)(*RawSec->
Info)
1024 assignSectionAddress(SHeader, YAMLSec);
1026 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1027 RawSec ? RawSec->
Offset : std::nullopt);
1029 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1035 std::vector<Elf_Sym> Syms =
1036 toELFSymbols(Symbols, IsStatic ? DotStrtab : DotDynstr);
1037 SHeader.sh_size = Syms.size() *
sizeof(Elf_Sym);
1038 CBA.write((
const char *)Syms.data(), SHeader.sh_size);
1041template <
class ELFT>
1042void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1044 ContiguousBlobAccumulator &CBA,
1051 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1053 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1054 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1056 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1061 SHeader.sh_size = STB.
getSize();
1064 if (RawSec && RawSec->
Info)
1065 SHeader.sh_info = *RawSec->
Info;
1067 if (YAMLSec && YAMLSec->
Flags)
1068 SHeader.sh_flags = *YAMLSec->
Flags;
1069 else if (
Name ==
".dynstr")
1072 assignSectionAddress(SHeader, YAMLSec);
1077 return Name.consume_front(
".") && DebugSecNames.
count(
Name);
1080template <
class ELFT>
1083 ContiguousBlobAccumulator &CBA) {
1094 if (
Error Err = EmitFunc(*
OS, DWARF))
1095 return std::move(Err);
1097 return CBA.tell() - BeginOffset;
1100template <
class ELFT>
1101void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1102 ContiguousBlobAccumulator &CBA,
1107 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1108 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1111 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1115 "' contents in the 'DWARF' entry and the 'Content' "
1116 "or 'Size' in the 'Sections' entry at the same time");
1119 emitDWARF<ELFT>(SHeader,
Name, *Doc.DWARF, CBA))
1120 SHeader.sh_size = *ShSizeOrErr;
1128 "entry or a RawContentSection");
1130 if (RawSec && RawSec->
Info)
1131 SHeader.sh_info = *RawSec->
Info;
1133 if (YAMLSec && YAMLSec->
Flags)
1134 SHeader.sh_flags = *YAMLSec->
Flags;
1135 else if (
Name ==
".debug_str")
1138 assignSectionAddress(SHeader, YAMLSec);
1141template <
class ELFT>
void ELFState<ELFT>::reportError(
const Twine &Msg) {
1146template <
class ELFT>
void ELFState<ELFT>::reportError(
Error Err) {
1152template <
class ELFT>
1153std::vector<Fragment>
1156 std::vector<Fragment>
Ret;
1165 const Elf_Shdr &
H = SHeaders[SN2I.get(S->
Name)];
1166 Ret.push_back({
H.sh_offset,
H.sh_size,
H.sh_type,
H.sh_addralign});
1171template <
class ELFT>
1172void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
1173 std::vector<Elf_Shdr> &SHeaders) {
1175 for (
auto &YamlPhdr : Doc.ProgramHeaders) {
1176 Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
1177 std::vector<Fragment> Fragments = getPhdrFragments(YamlPhdr, SHeaders);
1179 return A.Offset <
B.Offset;
1181 reportError(
"sections in the program header with index " +
1182 Twine(PhdrIdx) +
" are not sorted by their file offset");
1185 if (!Fragments.empty() && *YamlPhdr.
Offset > Fragments.front().Offset)
1187 " must be less than or equal to the minimum file offset of "
1188 "all included sections (0x" +
1190 PHeader.p_offset = *YamlPhdr.
Offset;
1191 }
else if (!Fragments.empty()) {
1192 PHeader.p_offset = Fragments.front().Offset;
1197 PHeader.p_filesz = *YamlPhdr.
FileSize;
1198 }
else if (!Fragments.empty()) {
1199 uint64_t FileSize = Fragments.back().Offset - PHeader.p_offset;
1204 FileSize += Fragments.back().Size;
1205 PHeader.p_filesz = FileSize;
1209 uint64_t MemOffset = PHeader.p_offset;
1210 for (
const Fragment &
F : Fragments)
1211 MemOffset = std::max(MemOffset,
F.Offset +
F.Size);
1214 : MemOffset - PHeader.p_offset;
1216 if (YamlPhdr.
Align) {
1217 PHeader.p_align = *YamlPhdr.
Align;
1222 PHeader.p_align = 1;
1223 for (
const Fragment &
F : Fragments)
1224 PHeader.p_align = std::max((
uint64_t)PHeader.p_align,
F.AddrAlign);
1235 return (isa<ELFYAML::Fill>(C) ||
1236 cast<ELFYAML::Section>(C)->Type != ELF::SHT_NOBITS);
1243template <
class ELFT>
1244void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1246 ContiguousBlobAccumulator &CBA) {
1250 SHeader.sh_size = *S.
Size;
1255 if (shouldAllocateFileSpace(Doc.ProgramHeaders, S))
1256 CBA.writeZeros(*S.
Size);
1259template <
class ELFT>
1260void ELFState<ELFT>::writeSectionContent(
1262 ContiguousBlobAccumulator &CBA) {
1264 SHeader.sh_info = *Section.Info;
1273template <
class ELFT>
1274void ELFState<ELFT>::writeSectionContent(
1276 ContiguousBlobAccumulator &CBA) {
1280 "Section type is not SHT_REL nor SHT_RELA");
1282 if (!
Section.RelocatableSec.empty())
1283 SHeader.sh_info = toSectionIndex(
Section.RelocatableSec,
Section.Name);
1290 typename ELFT::uint OffsetMask = 8,
Offset = 0, Addend = 0;
1292 uint64_t CurrentOffset = CBA.getOffset();
1295 OffsetMask |= Rel.
Offset;
1301 const bool IsDynamic =
Section.Link && (*
Section.Link ==
".dynsym");
1309 (
static_cast<typename ELFT::uint
>(Rel.
Offset) -
Offset) >> Shift;
1312 DeltaOffset * 8 + (SymIdx != CurSymIdx) + (
Type != Rel.
Type ? 2 : 0) +
1313 (Addend !=
static_cast<typename ELFT::uint
>(Rel.
Addend) ? 4 : 0);
1314 if (DeltaOffset < 0x10) {
1317 CBA.write(
B | 0x80);
1318 CBA.writeULEB128(DeltaOffset >> 4);
1323 std::make_signed_t<typename ELFT::uint>(CurSymIdx - SymIdx));
1327 CBA.writeSLEB128(
static_cast<int32_t
>(Rel.
Type -
Type));
1332 std::make_signed_t<typename ELFT::uint>(Rel.
Addend - Addend));
1335 }
else if (IsRela) {
1338 REntry.r_offset = Rel.
Offset;
1339 REntry.r_addend = Rel.
Addend;
1341 CBA.write((
const char *)&REntry,
sizeof(REntry));
1345 REntry.r_offset = Rel.
Offset;
1347 CBA.write((
const char *)&REntry,
sizeof(REntry));
1351 SHeader.sh_size = CBA.getOffset() - CurrentOffset;
1354template <
class ELFT>
1355void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1357 ContiguousBlobAccumulator &CBA) {
1361 for (llvm::yaml::Hex64 E : *
Section.Entries) {
1362 if (!ELFT::Is64Bits && E > UINT32_MAX)
1365 CBA.write<uintX_t>(E, ELFT::Endianness);
1368 SHeader.sh_size =
sizeof(uintX_t) *
Section.Entries->size();
1371template <
class ELFT>
1372void ELFState<ELFT>::writeSectionContent(
1374 ContiguousBlobAccumulator &CBA) {
1384 CBA.write<
uint32_t>(E, ELFT::Endianness);
1385 SHeader.sh_size = Shndx.
Entries->size() * SHeader.sh_entsize;
1388template <
class ELFT>
1389void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1391 ContiguousBlobAccumulator &CBA) {
1393 "Section type is not SHT_GROUP");
1403 unsigned int SectionIndex = 0;
1404 if (
Member.sectionNameOrType ==
"GRP_COMDAT")
1407 SectionIndex = toSectionIndex(
Member.sectionNameOrType,
Section.Name);
1408 CBA.write<
uint32_t>(SectionIndex, ELFT::Endianness);
1410 SHeader.sh_size = SHeader.sh_entsize *
Section.Members->size();
1413template <
class ELFT>
1414void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1416 ContiguousBlobAccumulator &CBA) {
1422 SHeader.sh_size =
Section.Entries->size() * SHeader.sh_entsize;
1425template <
class ELFT>
1426void ELFState<ELFT>::writeSectionContent(
1428 ContiguousBlobAccumulator &CBA) {
1433 CBA.write<uintX_t>(E.
Address, ELFT::Endianness);
1434 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(E.
Size);
1438template <
class ELFT>
1439void ELFState<ELFT>::writeSectionContent(
1441 ContiguousBlobAccumulator &CBA) {
1445 <<
"PGOAnalyses should not exist in SHT_LLVM_BB_ADDR_MAP when "
1446 "Entries does not exist";
1450 const std::vector<ELFYAML::PGOAnalysisMapEntry> *PGOAnalyses =
nullptr;
1454 "in SHT_LLVM_BB_ADDR_MAP";
1456 PGOAnalyses = &
Section.PGOAnalyses.value();
1464 <<
static_cast<int>(E.Version)
1465 <<
"; encoding using the most recent version";
1466 CBA.
write(E.Version);
1467 CBA.
write(E.Feature);
1468 SHeader.sh_size += 2;
1471 bool MultiBBRangeFeatureEnabled =
false;
1475 MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
1477 MultiBBRangeFeatureEnabled ||
1478 (E.NumBBRanges.has_value() && E.NumBBRanges.value() != 1) ||
1479 (E.BBRanges && E.BBRanges->size() != 1);
1480 if (MultiBBRange && !MultiBBRangeFeatureEnabled)
1482 <<
") does not support multiple BB ranges.";
1487 E.NumBBRanges.value_or(E.BBRanges ? E.BBRanges->size() : 0);
1488 SHeader.sh_size += CBA.writeULEB128(NumBBRanges);
1495 CBA.write<uintX_t>(BBR.
BaseAddress, ELFT::Endianness);
1501 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(NumBlocks);
1508 SHeader.sh_size += CBA.writeULEB128(BBE.
ID);
1510 SHeader.sh_size += CBA.writeULEB128(BBE.
Size);
1511 SHeader.sh_size += CBA.writeULEB128(BBE.
Metadata);
1524 const auto &PGOBBEntries = PGOEntry.
PGOBBEntries.value();
1525 if (TotalNumBlocks != PGOBBEntries.size()) {
1527 "BBEntries in SHT_LLVM_BB_ADDR_MAP.\n"
1528 <<
"Mismatch on function with address: "
1529 << E.getFunctionAddress();
1533 for (
const auto &PGOBBE : PGOBBEntries) {
1535 SHeader.sh_size += CBA.writeULEB128(*PGOBBE.BBFreq);
1536 if (PGOBBE.Successors) {
1537 SHeader.sh_size += CBA.writeULEB128(PGOBBE.Successors->size());
1538 for (
const auto &[
ID,
BrProb] : *PGOBBE.Successors) {
1539 SHeader.sh_size += CBA.writeULEB128(
ID);
1540 SHeader.sh_size += CBA.writeULEB128(
BrProb);
1547template <
class ELFT>
1548void ELFState<ELFT>::writeSectionContent(
1550 ContiguousBlobAccumulator &CBA) {
1555 CBA.write(
LO.Key.data(),
LO.Key.size());
1557 CBA.write(
LO.Value.data(),
LO.Value.size());
1559 SHeader.sh_size += (
LO.Key.size() +
LO.Value.size() + 2);
1563template <
class ELFT>
1564void ELFState<ELFT>::writeSectionContent(
1566 ContiguousBlobAccumulator &CBA) {
1571 CBA.write(
Lib.data(),
Lib.size());
1573 SHeader.sh_size +=
Lib.size() + 1;
1577template <
class ELFT>
1579ELFState<ELFT>::alignToOffset(ContiguousBlobAccumulator &CBA,
uint64_t Align,
1580 std::optional<llvm::yaml::Hex64>
Offset) {
1581 uint64_t CurrentOffset = CBA.getOffset();
1588 return CurrentOffset;
1597 CBA.writeZeros(AlignedOffset - CurrentOffset);
1598 return AlignedOffset;
1601template <
class ELFT>
1602void ELFState<ELFT>::writeSectionContent(
1604 ContiguousBlobAccumulator &CBA) {
1614template <
class ELFT>
1615void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1617 ContiguousBlobAccumulator &CBA) {
1622 Section.NBucket.value_or(llvm::yaml::Hex64(
Section.Bucket->size())),
1625 Section.NChain.value_or(llvm::yaml::Hex64(
Section.Chain->size())),
1629 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1631 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1633 SHeader.sh_size = (2 +
Section.Bucket->size() +
Section.Chain->size()) * 4;
1636template <
class ELFT>
1637void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1639 ContiguousBlobAccumulator &CBA) {
1642 SHeader.sh_info = *
Section.Info;
1644 SHeader.sh_info =
Section.Entries->size();
1650 for (
size_t I = 0;
I <
Section.Entries->size(); ++
I) {
1654 VerDef.vd_version = E.
Version.value_or(1);
1655 VerDef.vd_flags = E.
Flags.value_or(0);
1657 VerDef.vd_hash = E.
Hash.value_or(0);
1658 VerDef.vd_aux =
sizeof(Elf_Verdef);
1660 if (
I ==
Section.Entries->size() - 1)
1664 sizeof(Elf_Verdef) + E.
VerNames.size() *
sizeof(Elf_Verdaux);
1665 CBA.write((
const char *)&VerDef,
sizeof(Elf_Verdef));
1667 for (
size_t J = 0; J < E.
VerNames.size(); ++J, ++AuxCnt) {
1668 Elf_Verdaux VernAux;
1669 VernAux.vda_name = DotDynstr.getOffset(E.
VerNames[J]);
1671 VernAux.vda_next = 0;
1673 VernAux.vda_next =
sizeof(Elf_Verdaux);
1674 CBA.write((
const char *)&VernAux,
sizeof(Elf_Verdaux));
1678 SHeader.sh_size =
Section.Entries->size() *
sizeof(Elf_Verdef) +
1679 AuxCnt *
sizeof(Elf_Verdaux);
1682template <
class ELFT>
1683void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1685 ContiguousBlobAccumulator &CBA) {
1687 SHeader.sh_info = *
Section.Info;
1689 SHeader.sh_info =
Section.VerneedV->size();
1695 for (
size_t I = 0;
I <
Section.VerneedV->size(); ++
I) {
1698 Elf_Verneed VerNeed;
1699 VerNeed.vn_version = VE.
Version;
1700 VerNeed.vn_file = DotDynstr.getOffset(VE.
File);
1701 if (
I ==
Section.VerneedV->size() - 1)
1702 VerNeed.vn_next = 0;
1705 sizeof(Elf_Verneed) + VE.
AuxV.size() *
sizeof(Elf_Vernaux);
1706 VerNeed.vn_cnt = VE.
AuxV.size();
1707 VerNeed.vn_aux =
sizeof(Elf_Verneed);
1708 CBA.write((
const char *)&VerNeed,
sizeof(Elf_Verneed));
1710 for (
size_t J = 0; J < VE.
AuxV.size(); ++J, ++AuxCnt) {
1713 Elf_Vernaux VernAux;
1714 VernAux.vna_hash = VAuxE.
Hash;
1715 VernAux.vna_flags = VAuxE.
Flags;
1716 VernAux.vna_other = VAuxE.
Other;
1717 VernAux.vna_name = DotDynstr.getOffset(VAuxE.
Name);
1718 if (J == VE.
AuxV.size() - 1)
1719 VernAux.vna_next = 0;
1721 VernAux.vna_next =
sizeof(Elf_Vernaux);
1722 CBA.write((
const char *)&VernAux,
sizeof(Elf_Vernaux));
1726 SHeader.sh_size =
Section.VerneedV->size() *
sizeof(Elf_Verneed) +
1727 AuxCnt *
sizeof(Elf_Vernaux);
1730template <
class ELFT>
1731void ELFState<ELFT>::writeSectionContent(
1733 ContiguousBlobAccumulator &CBA) {
1741 SHeader.sh_size =
Section.Entries->size() * 8;
1744template <
class ELFT>
1745void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1747 ContiguousBlobAccumulator &CBA) {
1749 "Section type is not SHT_MIPS_ABIFLAGS");
1753 SHeader.sh_size = SHeader.sh_entsize;
1766 CBA.write((
const char *)&Flags,
sizeof(Flags));
1769template <
class ELFT>
1770void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1772 ContiguousBlobAccumulator &CBA) {
1774 "Section type is not SHT_DYNAMIC");
1780 CBA.write<uintX_t>(DE.
Tag, ELFT::Endianness);
1781 CBA.write<uintX_t>(DE.
Val, ELFT::Endianness);
1783 SHeader.sh_size = 2 *
sizeof(uintX_t) *
Section.Entries->size();
1786template <
class ELFT>
1787void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1789 ContiguousBlobAccumulator &CBA) {
1795 CBA.writeULEB128(toSymbolIndex(
Sym,
Section.Name,
false));
1798template <
class ELFT>
1799void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1801 ContiguousBlobAccumulator &CBA) {
1808 if (
NE.Name.empty())
1809 CBA.write<
uint32_t>(0, ELFT::Endianness);
1811 CBA.write<
uint32_t>(
NE.Name.size() + 1, ELFT::Endianness);
1814 if (
NE.Desc.binary_size() == 0)
1815 CBA.write<
uint32_t>(0, ELFT::Endianness);
1817 CBA.write<
uint32_t>(
NE.Desc.binary_size(), ELFT::Endianness);
1820 CBA.write<
uint32_t>(
NE.Type, ELFT::Endianness);
1823 if (!
NE.Name.empty()) {
1824 CBA.write(
NE.Name.data(),
NE.Name.size());
1826 CBA.padToAlignment(4);
1830 if (
NE.Desc.binary_size() != 0) {
1831 CBA.writeAsBinary(
NE.Desc);
1832 CBA.padToAlignment(4);
1836 SHeader.sh_size = CBA.tell() -
Offset;
1839template <
class ELFT>
1840void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1842 ContiguousBlobAccumulator &CBA) {
1864 if (
Section.Header->MaskWords)
1873 for (llvm::yaml::Hex64 Val : *
Section.BloomFilter)
1874 CBA.write<uintX_t>(Val, ELFT::Endianness);
1877 for (llvm::yaml::Hex32 Val : *
Section.HashBuckets)
1878 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1881 for (llvm::yaml::Hex32 Val : *
Section.HashValues)
1882 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1884 SHeader.sh_size = 16 +
1885 Section.BloomFilter->size() *
sizeof(
typename ELFT::uint) +
1886 Section.HashBuckets->size() * 4 +
1887 Section.HashValues->size() * 4;
1890template <
class ELFT>
1892 ContiguousBlobAccumulator &CBA) {
1893 size_t PatternSize = Fill.
Pattern ? Fill.
Pattern->binary_size() : 0;
1895 CBA.writeZeros(Fill.
Size);
1901 for (; Written + PatternSize <= Fill.
Size; Written += PatternSize)
1902 CBA.writeAsBinary(*Fill.
Pattern);
1903 CBA.writeAsBinary(*Fill.
Pattern, Fill.
Size - Written);
1906template <
class ELFT>
1909 Doc.getSectionHeaderTable();
1919 if (!
Ret.try_emplace(Hdr.Name, ++SecNdx).second)
1920 reportError(
"repeated section name: '" + Hdr.Name +
1921 "' in the section header description");
1935 if (S == Doc.getSections().front())
1939 "' should be present in the 'Sections' or 'Excluded' lists");
1943 for (
const auto &It : Seen)
1944 reportError(
"section header contains undefined section '" + It.getKey() +
1949template <
class ELFT>
void ELFState<ELFT>::buildSectionIndex() {
1958 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
1960 Doc.getSectionHeaderTable();
1963 if (!ExcludedSectionHeaders.insert(Hdr.
Name).second)
1966 if (SectionHeaders.
NoHeaders.value_or(
false))
1968 if (!ExcludedSectionHeaders.insert(S->
Name).second)
1979 if (!ExcludedSectionHeaders.count(S->
Name))
1984template <
class ELFT>
void ELFState<ELFT>::buildSymbolIndexes() {
1986 for (
size_t I = 0, S =
V.size();
I < S; ++
I) {
1988 if (!
Sym.Name.empty() && !
Map.addName(
Sym.Name,
I + 1))
1994 Build(*Doc.Symbols, SymN2I);
1995 if (Doc.DynamicSymbols)
1996 Build(*Doc.DynamicSymbols, DynSymN2I);
1999template <
class ELFT>
void ELFState<ELFT>::finalizeStrings() {
2004 DotStrtab.finalize();
2007 if (Doc.DynamicSymbols)
2014 if (
auto VerNeed = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
2015 if (VerNeed->VerneedV) {
2017 DotDynstr.add(VE.
File);
2019 DotDynstr.add(Aux.
Name);
2022 }
else if (
auto VerDef = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
2023 if (VerDef->Entries)
2026 DotDynstr.add(
Name);
2030 DotDynstr.finalize();
2034 if (ShStrtabStrings != &DotStrtab && ShStrtabStrings != &DotDynstr)
2035 ShStrtabStrings->finalize();
2038template <
class ELFT>
2041 ELFState<ELFT> State(Doc, EH);
2047 State.buildSectionIndex();
2048 State.buildSymbolIndexes();
2053 State.finalizeStrings();
2058 std::vector<Elf_Phdr> PHeaders;
2059 State.initProgramHeaders(PHeaders);
2063 const size_t SectionContentBeginOffset =
2069 ContiguousBlobAccumulator CBA(SectionContentBeginOffset, MaxSize);
2071 std::vector<Elf_Shdr> SHeaders;
2072 State.initSectionHeaders(SHeaders, CBA);
2075 State.setProgramHeaderLayout(PHeaders, SHeaders);
2077 bool ReachedLimit = CBA.getOffset() > MaxSize;
2078 if (
Error E = CBA.takeLimitError()) {
2081 ReachedLimit =
true;
2086 "the desired output size is greater than permitted. Use the "
2087 "--max-size option to change the limit");
2092 State.writeELFHeader(
OS);
2097 CBA.updateDataAt(*SHT.
Offset, SHeaders.data(),
2100 CBA.writeBlobToStream(
OS);
2113 return ELFState<object::ELF64LE>::writeELF(Out, Doc, EH, MaxSize);
2114 return ELFState<object::ELF64BE>::writeELF(Out, Doc, EH, MaxSize);
2117 return ELFState<object::ELF32LE>::writeELF(Out, Doc, EH, MaxSize);
2118 return ELFState<object::ELF32BE>::writeELF(Out, Doc, EH, MaxSize);
static Error reportError(StringRef Message)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Common declarations for yaml2obj.
This file declares classes for handling the YAML representation of DWARF Debug Info.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
static StringRef getDefaultLinkSec(unsigned SecType)
static void overrideFields(ELFYAML::Section *From, typename ELFT::Shdr &To)
static void writeArrayData(raw_ostream &OS, ArrayRef< T > A)
static bool isMips64EL(const ELFYAML::Object &Obj)
static size_t arrayDataSize(ArrayRef< T > A)
constexpr char SuffixStart
static bool shouldEmitDWARF(DWARFYAML::Data &DWARF, StringRef Name)
static uint64_t writeContent(ContiguousBlobAccumulator &CBA, const std::optional< yaml::BinaryRef > &Content, const std::optional< llvm::yaml::Hex64 > &Size)
Expected< uint64_t > emitDWARF(typename ELFT::Shdr &SHeader, StringRef Name, const DWARFYAML::Data &DWARF, ContiguousBlobAccumulator &CBA)
static size_t findFirstNonGlobal(ArrayRef< ELFYAML::Symbol > Symbols)
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
This file declares classes for handling the YAML representation of ELF.
static cl::opt< unsigned > SizeLimit("eif-limit", cl::init(6), cl::Hidden, cl::desc("Size limit in Hexagon early if-conversion"))
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
StringSet - A set-like wrapper for the StringMap.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Allocate memory in an ever growing pool, as if by bump-pointer.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
A vector that has set insertion semantics.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
char back() const
back - Get the last character in the string.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
StringRef copy(Allocator &A) const
static constexpr size_t npos
StringSet - A wrapper for StringMap that provides set-like functionality.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Utility for building string tables with deduplicated suffixes.
size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
void write(raw_ostream &OS) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(const uint64_t &Val)
The instances of the Type class are immutable: once they are created, they are never changed.
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
Specialized YAMLIO scalar type for representing a binary blob.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
std::function< Error(raw_ostream &, const Data &)> getDWARFEmitterByName(StringRef SecName)
std::string appendUniqueSuffix(StringRef Name, const Twine &Msg)
StringRef dropUniqueSuffix(StringRef S)
bool shouldAllocateFileSpace(ArrayRef< ProgramHeader > Phdrs, const NoBitsSection &S)
constexpr unsigned CREL_HDR_ADDEND
@ SHT_LLVM_CALL_GRAPH_PROFILE
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH, uint64_t MaxSize)
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
@ Dynamic
Denotes mode unknown at compile time.
OutputIt copy(R &&Range, OutputIt Out)
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
void consumeError(Error Err)
Consume a Error without doing anything.
This struct is a compact representation of a valid (non-zero power of two) alignment.
SetVector< StringRef > getNonEmptySectionNames() const
llvm::yaml::Hex64 Metadata
llvm::yaml::Hex64 AddressOffset
std::optional< uint64_t > NumBlocks
llvm::yaml::Hex64 BaseAddress
std::optional< std::vector< BBEntry > > BBEntries
std::optional< llvm::yaml::Hex64 > Offset
std::optional< yaml::BinaryRef > Pattern
unsigned getMachine() const
const SectionHeaderTable & getSectionHeaderTable() const
std::vector< ProgramHeader > ProgramHeaders
std::optional< std::vector< PGOBBEntry > > PGOBBEntries
std::optional< uint64_t > FuncEntryCount
std::optional< llvm::yaml::Hex64 > Info
std::optional< StringRef > Symbol
std::optional< llvm::yaml::Hex64 > Address
std::optional< StringRef > Link
std::optional< llvm::yaml::Hex64 > Size
llvm::yaml::Hex64 AddressAlign
std::optional< ELF_SHF > Flags
std::optional< yaml::BinaryRef > Content
std::optional< llvm::yaml::Hex64 > EntSize
llvm::yaml::Hex64 Address
std::optional< std::vector< uint32_t > > Entries
std::optional< uint16_t > Flags
std::vector< StringRef > VerNames
std::optional< uint16_t > VersionNdx
std::optional< uint16_t > Version
std::optional< uint32_t > Hash
std::vector< VernauxEntry > AuxV
static Expected< Features > decode(uint8_t Val)
Common declarations for yaml2obj.