44class ContiguousBlobAccumulator {
57 "reached the output size limit");
63 : InitialOffset(BaseOffset), MaxSize(
SizeLimit),
OS(Buf) {}
67 void writeBlobToStream(
raw_ostream &Out)
const { Out <<
OS.str(); }
69 Error takeLimitError() {
72 return std::move(ReachedLimitErr);
82 uint64_t PaddingSize = AlignedOffset - CurrentOffset;
83 if (!checkLimit(PaddingSize))
86 writeZeros(PaddingSize);
97 if (!checkLimit(
Bin.binary_size()))
99 Bin.writeAsBinary(OS,
N);
108 if (checkLimit(
Size))
112 void write(
unsigned char C) {
117 unsigned writeULEB128(
uint64_t Val) {
123 unsigned writeSLEB128(int64_t Val) {
130 if (checkLimit(
sizeof(
T)))
131 support::endian::write<T>(OS, Val, E);
134 void updateDataAt(
uint64_t Pos,
void *Data,
size_t Size) {
136 memcpy(&Buf[Pos - InitialOffset], Data,
Size);
148 return Map.insert({
Name, Ndx}).second;
163 assert(
false &&
"Expected section not found in index");
166 unsigned size()
const {
return Map.size(); }
181template <
class ELFT>
class ELFState {
201 StringRef SectionHeaderStringTableName =
".shstrtab";
206 NameToIdxMap DynSymN2I;
212 bool HasError =
false;
222 void buildSectionIndex();
223 void buildSymbolIndexes();
224 void initProgramHeaders(std::vector<Elf_Phdr> &PHeaders);
225 bool initImplicitHeader(ContiguousBlobAccumulator &CBA, Elf_Shdr &Header,
227 void initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
228 ContiguousBlobAccumulator &CBA);
229 void initSymtabSectionHeader(Elf_Shdr &SHeader, SymtabType STType,
230 ContiguousBlobAccumulator &CBA,
232 void initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
234 ContiguousBlobAccumulator &CBA,
236 void initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
237 ContiguousBlobAccumulator &CBA,
239 void setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
240 std::vector<Elf_Shdr> &SHeaders);
242 std::vector<Fragment>
246 void finalizeStrings();
248 void writeSectionContent(Elf_Shdr &SHeader,
250 ContiguousBlobAccumulator &CBA);
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);
312 void writeFill(
ELFYAML::Fill &Fill, ContiguousBlobAccumulator &CBA);
322 std::optional<llvm::yaml::Hex64>
Offset);
333 return A.size() *
sizeof(
T);
340template <
class T>
static void zero(
T &Obj) { memset(&Obj, 0,
sizeof(Obj)); }
344 : Doc(
D), ErrHandler(EH) {
348 if (Doc.Header.SectionHeaderStringTable) {
349 SectionHeaderStringTableName = *Doc.Header.SectionHeaderStringTable;
350 if (*Doc.Header.SectionHeaderStringTable ==
".strtab")
351 ShStrtabStrings = &DotStrtab;
352 else if (*Doc.Header.SectionHeaderStringTable ==
".dynstr")
353 ShStrtabStrings = &DotDynstr;
357 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
359 if (Sections.empty() || Sections.front()->Type !=
ELF::SHT_NULL)
362 std::make_unique<ELFYAML::Section>(
363 ELFYAML::Chunk::ChunkKind::RawContent,
true));
367 for (
size_t I = 0;
I < Doc.Chunks.size(); ++
I) {
368 const std::unique_ptr<ELFYAML::Chunk> &
C = Doc.Chunks[
I];
371 if (
auto S = dyn_cast<ELFYAML::SectionHeaderTable>(
C.get())) {
373 reportError(
"multiple section header tables are not allowed");
381 if (
C->Name.empty()) {
388 if (!DocSections.
insert(
C->Name).second)
390 "' at YAML section/fill number " +
Twine(
I));
394 if (Doc.DynamicSymbols) {
395 if (SectionHeaderStringTableName ==
".dynsym")
396 reportError(
"cannot use '.dynsym' as the section header name table when "
397 "there are dynamic symbols");
398 ImplicitSections.
insert(
".dynsym");
399 ImplicitSections.
insert(
".dynstr");
402 if (SectionHeaderStringTableName ==
".symtab")
403 reportError(
"cannot use '.symtab' as the section header name table when "
404 "there are symbols");
405 ImplicitSections.
insert(
".symtab");
408 for (
StringRef DebugSecName : Doc.DWARF->getNonEmptySectionNames()) {
409 std::string SecName = (
"." + DebugSecName).str();
412 if (SectionHeaderStringTableName == SecName)
414 "' as the section header name table when it is needed for "
419 ImplicitSections.
insert(
".strtab");
420 if (!SecHdrTable || !SecHdrTable->
NoHeaders.value_or(
false))
421 ImplicitSections.
insert(SectionHeaderStringTableName);
425 for (
StringRef SecName : ImplicitSections) {
426 if (DocSections.
count(SecName))
429 std::unique_ptr<ELFYAML::Section> Sec = std::make_unique<ELFYAML::Section>(
430 ELFYAML::Chunk::ChunkKind::RawContent,
true );
433 if (SecName == SectionHeaderStringTableName)
435 else if (SecName ==
".dynsym")
437 else if (SecName ==
".symtab")
447 if (Doc.Chunks.back().get() == SecHdrTable)
448 Doc.Chunks.insert(Doc.Chunks.end() - 1, std::move(Sec));
450 Doc.Chunks.push_back(std::move(Sec));
456 Doc.Chunks.push_back(
457 std::make_unique<ELFYAML::SectionHeaderTable>(
true));
466 Header.e_ident[
EI_MAG0] = 0x7f;
471 Header.e_ident[
EI_DATA] = Doc.Header.Data;
473 Header.e_ident[
EI_OSABI] = Doc.Header.OSABI;
475 Header.e_type = Doc.Header.Type;
477 if (Doc.Header.Machine)
478 Header.e_machine = *Doc.Header.Machine;
483 Header.e_entry = Doc.Header.Entry;
484 if (Doc.Header.Flags)
485 Header.e_flags = *Doc.Header.Flags;
489 Header.e_ehsize =
sizeof(Elf_Ehdr);
491 if (Doc.Header.EPhOff)
492 Header.e_phoff = *Doc.Header.EPhOff;
493 else if (!Doc.ProgramHeaders.empty())
494 Header.e_phoff =
sizeof(Header);
498 if (Doc.Header.EPhEntSize)
499 Header.e_phentsize = *Doc.Header.EPhEntSize;
500 else if (!Doc.ProgramHeaders.empty())
501 Header.e_phentsize =
sizeof(Elf_Phdr);
503 Header.e_phentsize = 0;
505 if (Doc.Header.EPhNum)
506 Header.e_phnum = *Doc.Header.EPhNum;
507 else if (!Doc.ProgramHeaders.empty())
508 Header.e_phnum = Doc.ProgramHeaders.size();
512 Header.e_shentsize = Doc.Header.EShEntSize ? (
uint16_t)*Doc.Header.EShEntSize
516 Doc.getSectionHeaderTable();
518 if (Doc.Header.EShOff)
519 Header.e_shoff = *Doc.Header.EShOff;
520 else if (SectionHeaders.
Offset)
521 Header.e_shoff = *SectionHeaders.
Offset;
525 if (Doc.Header.EShNum)
526 Header.e_shnum = *Doc.Header.EShNum;
528 Header.e_shnum = SectionHeaders.
getNumHeaders(Doc.getSections().size());
530 if (Doc.Header.EShStrNdx)
531 Header.e_shstrndx = *Doc.Header.EShStrNdx;
532 else if (SectionHeaders.
Offset &&
533 !ExcludedSectionHeaders.count(SectionHeaderStringTableName))
534 Header.e_shstrndx = SN2I.get(SectionHeaderStringTableName);
536 Header.e_shstrndx = 0;
538 OS.
write((
const char *)&Header,
sizeof(Header));
542void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
544 for (
size_t I = 0, E = Doc.Chunks.size();
I != E; ++
I) {
545 NameToIndex[Doc.Chunks[
I]->Name] =
I + 1;
548 for (
size_t I = 0, E = Doc.ProgramHeaders.size();
I != E; ++
I) {
552 Phdr.p_type = YamlPhdr.
Type;
553 Phdr.p_flags = YamlPhdr.
Flags;
554 Phdr.p_vaddr = YamlPhdr.
VAddr;
555 Phdr.p_paddr = YamlPhdr.
PAddr;
556 PHeaders.push_back(Phdr);
565 "' by the 'FirstSec' key of the program header with index " +
570 "' by the 'LastSec' key of the program header with index " +
577 ": the section index of " + *YamlPhdr.
FirstSec +
578 " is greater than the index of " + *YamlPhdr.
LastSec);
581 YamlPhdr.
Chunks.push_back(Doc.Chunks[
I - 1].get());
591 if (!SN2I.lookup(S, Index) && !to_integer(S, Index)) {
593 reportError(
"unknown section referenced: '" + S +
"' by YAML symbol '" +
596 reportError(
"unknown section referenced: '" + S +
"' by YAML section '" +
602 Doc.getSectionHeaderTable();
609 size_t FirstExcluded =
611 if (Index > FirstExcluded) {
613 reportError(
"unable to link '" + LocSec +
"' to excluded section '" + S +
616 reportError(
"excluded section referenced: '" + S +
"' by symbol '" +
625 const NameToIdxMap &
SymMap = IsDynamic ? DynSymN2I : SymN2I;
629 if (!
SymMap.lookup(S, Index) && !to_integer(S, Index)) {
630 reportError(
"unknown symbol referenced: '" + S +
"' by YAML section '" +
641 if (
From->ShAddrAlign)
642 To.sh_addralign = *
From->ShAddrAlign;
644 To.sh_flags = *
From->ShFlags;
646 To.sh_name = *
From->ShName;
648 To.sh_offset = *
From->ShOffset;
650 To.sh_size = *
From->ShSize;
652 To.sh_type = *
From->ShType;
656bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
660 if (Header.sh_offset)
663 if (SecName ==
".strtab")
664 initStrtabSectionHeader(Header, SecName, DotStrtab, CBA, YAMLSec);
665 else if (SecName ==
".dynstr")
666 initStrtabSectionHeader(Header, SecName, DotDynstr, CBA, YAMLSec);
667 else if (SecName == SectionHeaderStringTableName)
668 initStrtabSectionHeader(Header, SecName, *ShStrtabStrings, CBA, YAMLSec);
669 else if (SecName ==
".symtab")
670 initSymtabSectionHeader(Header, SymtabType::Static, CBA, YAMLSec);
671 else if (SecName ==
".dynsym")
672 initSymtabSectionHeader(Header, SymtabType::Dynamic, CBA, YAMLSec);
676 if (YAMLSec && !isa<ELFYAML::RawContentSection>(YAMLSec))
678 initDWARFSectionHeader(Header, SecName, CBA, YAMLSec);
682 LocationCounter += Header.sh_size;
685 overrideFields<ELFT>(YAMLSec, Header);
695 std::string Ret =
Name.empty() ?
"" :
Name.str() +
' ';
710 return S.
substr(0, SuffixPos - 1);
717 if (ExcludedSectionHeaders.count(
Name))
719 return ShStrtabStrings->getOffset(
Name);
723 const std::optional<yaml::BinaryRef> &
Content,
724 const std::optional<llvm::yaml::Hex64> &
Size) {
725 size_t ContentSize = 0;
728 ContentSize =
Content->binary_size();
734 CBA.writeZeros(*
Size - ContentSize);
762void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
763 ContiguousBlobAccumulator &CBA) {
766 SHeaders.resize(Doc.getSections().size());
768 for (
const std::unique_ptr<ELFYAML::Chunk> &
D : Doc.Chunks) {
770 S->Offset = alignToOffset(CBA, 1, S->Offset);
772 LocationCounter += S->Size;
777 dyn_cast<ELFYAML::SectionHeaderTable>(
D.get())) {
778 if (S->NoHeaders.value_or(
false))
782 S->Offset = alignToOffset(CBA,
sizeof(
typename ELFT::uint),
785 S->Offset = alignToOffset(CBA, 1, S->Offset);
787 uint64_t Size = S->getNumHeaders(SHeaders.size()) *
sizeof(Elf_Shdr);
790 CBA.writeZeros(
Size);
791 LocationCounter +=
Size;
796 bool IsFirstUndefSection = Sec == Doc.getSections().front();
800 Elf_Shdr &SHeader = SHeaders[SN2I.get(Sec->
Name)];
802 SHeader.sh_link = toSectionIndex(*Sec->
Link, Sec->
Name);
806 if (!LinkSec.
empty() && !ExcludedSectionHeaders.count(LinkSec) &&
807 SN2I.lookup(LinkSec, Link))
808 SHeader.sh_link = Link;
812 SHeader.sh_entsize = *Sec->
EntSize;
814 SHeader.sh_entsize = ELFYAML::getDefaultShEntSize<ELFT>(
821 if (initImplicitHeader(CBA, SHeader, Sec->
Name,
825 assert(Sec &&
"It can't be null unless it is an implicit section. But all "
826 "implicit sections should already have been handled above.");
830 SHeader.sh_type = Sec->
Type;
832 SHeader.sh_flags = *Sec->
Flags;
837 if (!IsFirstUndefSection || Sec->
Offset)
838 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, Sec->
Offset);
840 assignSectionAddress(SHeader, Sec);
842 if (IsFirstUndefSection) {
843 if (
auto RawSec = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
846 SHeader.sh_size = *RawSec->Size;
848 SHeader.sh_info = *RawSec->Info;
851 LocationCounter += SHeader.sh_size;
852 overrideFields<ELFT>(Sec, SHeader);
856 if (!isa<ELFYAML::NoBitsSection>(Sec) && (Sec->
Content || Sec->
Size))
859 if (
auto S = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
860 writeSectionContent(SHeader, *S, CBA);
861 }
else if (
auto S = dyn_cast<ELFYAML::SymtabShndxSection>(Sec)) {
862 writeSectionContent(SHeader, *S, CBA);
863 }
else if (
auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
864 writeSectionContent(SHeader, *S, CBA);
865 }
else if (
auto S = dyn_cast<ELFYAML::RelrSection>(Sec)) {
866 writeSectionContent(SHeader, *S, CBA);
867 }
else if (
auto S = dyn_cast<ELFYAML::GroupSection>(Sec)) {
868 writeSectionContent(SHeader, *S, CBA);
869 }
else if (
auto S = dyn_cast<ELFYAML::ARMIndexTableSection>(Sec)) {
870 writeSectionContent(SHeader, *S, CBA);
871 }
else if (
auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec)) {
872 writeSectionContent(SHeader, *S, CBA);
873 }
else if (
auto S = dyn_cast<ELFYAML::NoBitsSection>(Sec)) {
874 writeSectionContent(SHeader, *S, CBA);
875 }
else if (
auto S = dyn_cast<ELFYAML::DynamicSection>(Sec)) {
876 writeSectionContent(SHeader, *S, CBA);
877 }
else if (
auto S = dyn_cast<ELFYAML::SymverSection>(Sec)) {
878 writeSectionContent(SHeader, *S, CBA);
879 }
else if (
auto S = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
880 writeSectionContent(SHeader, *S, CBA);
881 }
else if (
auto S = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
882 writeSectionContent(SHeader, *S, CBA);
883 }
else if (
auto S = dyn_cast<ELFYAML::StackSizesSection>(Sec)) {
884 writeSectionContent(SHeader, *S, CBA);
885 }
else if (
auto S = dyn_cast<ELFYAML::HashSection>(Sec)) {
886 writeSectionContent(SHeader, *S, CBA);
887 }
else if (
auto S = dyn_cast<ELFYAML::AddrsigSection>(Sec)) {
888 writeSectionContent(SHeader, *S, CBA);
889 }
else if (
auto S = dyn_cast<ELFYAML::LinkerOptionsSection>(Sec)) {
890 writeSectionContent(SHeader, *S, CBA);
891 }
else if (
auto S = dyn_cast<ELFYAML::NoteSection>(Sec)) {
892 writeSectionContent(SHeader, *S, CBA);
893 }
else if (
auto S = dyn_cast<ELFYAML::GnuHashSection>(Sec)) {
894 writeSectionContent(SHeader, *S, CBA);
895 }
else if (
auto S = dyn_cast<ELFYAML::DependentLibrariesSection>(Sec)) {
896 writeSectionContent(SHeader, *S, CBA);
897 }
else if (
auto S = dyn_cast<ELFYAML::CallGraphProfileSection>(Sec)) {
898 writeSectionContent(SHeader, *S, CBA);
899 }
else if (
auto S = dyn_cast<ELFYAML::BBAddrMapSection>(Sec)) {
900 writeSectionContent(SHeader, *S, CBA);
905 LocationCounter += SHeader.sh_size;
908 overrideFields<ELFT>(Sec, SHeader);
913void ELFState<ELFT>::assignSectionAddress(Elf_Shdr &SHeader,
915 if (YAMLSec && YAMLSec->
Address) {
916 SHeader.sh_addr = *YAMLSec->
Address;
917 LocationCounter = *YAMLSec->
Address;
929 alignTo(LocationCounter, SHeader.sh_addralign ? SHeader.sh_addralign : 1);
930 SHeader.sh_addr = LocationCounter;
934 for (
size_t I = 0;
I < Symbols.size(); ++
I)
937 return Symbols.size();
941std::vector<typename ELFT::Sym>
944 std::vector<Elf_Sym>
Ret;
945 Ret.resize(Symbols.size() + 1);
956 else if (!
Sym.Name.empty())
961 Symbol.st_shndx = toSectionIndex(*
Sym.Section,
"",
Sym.Name);
965 Symbol.st_value =
Sym.Value.value_or(yaml::Hex64(0));
967 Symbol.st_size =
Sym.Size.value_or(yaml::Hex64(0));
974void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
976 ContiguousBlobAccumulator &CBA,
979 bool IsStatic = STType == SymtabType::Static;
981 if (IsStatic && Doc.Symbols)
982 Symbols = *Doc.Symbols;
983 else if (!IsStatic && Doc.DynamicSymbols)
984 Symbols = *Doc.DynamicSymbols;
987 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
989 bool HasSymbolsDescription =
990 (IsStatic && Doc.Symbols) || (!IsStatic && Doc.DynamicSymbols);
991 if (HasSymbolsDescription) {
992 StringRef Property = (IsStatic ?
"`Symbols`" :
"`DynamicSymbols`");
994 reportError(
"cannot specify both `Content` and " + Property +
995 " for symbol table section '" + RawSec->
Name +
"'");
997 reportError(
"cannot specify both `Size` and " + Property +
998 " for symbol table section '" + RawSec->
Name +
"'");
1003 SHeader.sh_name = getSectionNameOffset(IsStatic ?
".symtab" :
".dynsym");
1006 SHeader.sh_type = YAMLSec->
Type;
1010 if (YAMLSec && YAMLSec->
Flags)
1011 SHeader.sh_flags = *YAMLSec->
Flags;
1017 SHeader.sh_info = (RawSec && RawSec->
Info) ? (
unsigned)(*RawSec->
Info)
1021 assignSectionAddress(SHeader, YAMLSec);
1023 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1024 RawSec ? RawSec->
Offset : std::nullopt);
1026 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1032 std::vector<Elf_Sym> Syms =
1033 toELFSymbols(Symbols, IsStatic ? DotStrtab : DotDynstr);
1034 SHeader.sh_size = Syms.size() *
sizeof(Elf_Sym);
1035 CBA.write((
const char *)Syms.data(), SHeader.sh_size);
1038template <
class ELFT>
1039void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1041 ContiguousBlobAccumulator &CBA,
1048 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1050 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1051 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1053 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1058 SHeader.sh_size = STB.
getSize();
1061 if (RawSec && RawSec->
Info)
1062 SHeader.sh_info = *RawSec->
Info;
1064 if (YAMLSec && YAMLSec->
Flags)
1065 SHeader.sh_flags = *YAMLSec->
Flags;
1066 else if (
Name ==
".dynstr")
1069 assignSectionAddress(SHeader, YAMLSec);
1074 return Name.consume_front(
".") && DebugSecNames.
count(
Name);
1077template <
class ELFT>
1080 ContiguousBlobAccumulator &CBA) {
1091 if (
Error Err = EmitFunc(*
OS, DWARF))
1092 return std::move(Err);
1094 return CBA.tell() - BeginOffset;
1097template <
class ELFT>
1098void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1099 ContiguousBlobAccumulator &CBA,
1104 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1105 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1108 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1112 "' contents in the 'DWARF' entry and the 'Content' "
1113 "or 'Size' in the 'Sections' entry at the same time");
1116 emitDWARF<ELFT>(SHeader,
Name, *Doc.DWARF, CBA))
1117 SHeader.sh_size = *ShSizeOrErr;
1125 "entry or a RawContentSection");
1127 if (RawSec && RawSec->
Info)
1128 SHeader.sh_info = *RawSec->
Info;
1130 if (YAMLSec && YAMLSec->
Flags)
1131 SHeader.sh_flags = *YAMLSec->
Flags;
1132 else if (
Name ==
".debug_str")
1135 assignSectionAddress(SHeader, YAMLSec);
1138template <
class ELFT>
void ELFState<ELFT>::reportError(
const Twine &Msg) {
1143template <
class ELFT>
void ELFState<ELFT>::reportError(
Error Err) {
1149template <
class ELFT>
1150std::vector<Fragment>
1153 std::vector<Fragment>
Ret;
1162 const Elf_Shdr &
H = SHeaders[SN2I.get(S->
Name)];
1163 Ret.push_back({
H.sh_offset,
H.sh_size,
H.sh_type,
H.sh_addralign});
1168template <
class ELFT>
1169void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
1170 std::vector<Elf_Shdr> &SHeaders) {
1172 for (
auto &YamlPhdr : Doc.ProgramHeaders) {
1173 Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
1174 std::vector<Fragment> Fragments = getPhdrFragments(YamlPhdr, SHeaders);
1176 return A.Offset <
B.Offset;
1178 reportError(
"sections in the program header with index " +
1179 Twine(PhdrIdx) +
" are not sorted by their file offset");
1182 if (!Fragments.empty() && *YamlPhdr.
Offset > Fragments.front().Offset)
1184 " must be less than or equal to the minimum file offset of "
1185 "all included sections (0x" +
1187 PHeader.p_offset = *YamlPhdr.
Offset;
1188 }
else if (!Fragments.empty()) {
1189 PHeader.p_offset = Fragments.front().Offset;
1194 PHeader.p_filesz = *YamlPhdr.
FileSize;
1195 }
else if (!Fragments.empty()) {
1196 uint64_t FileSize = Fragments.back().Offset - PHeader.p_offset;
1201 FileSize += Fragments.back().Size;
1202 PHeader.p_filesz = FileSize;
1206 uint64_t MemOffset = PHeader.p_offset;
1207 for (
const Fragment &
F : Fragments)
1208 MemOffset = std::max(MemOffset,
F.Offset +
F.Size);
1211 : MemOffset - PHeader.p_offset;
1213 if (YamlPhdr.
Align) {
1214 PHeader.p_align = *YamlPhdr.
Align;
1219 PHeader.p_align = 1;
1220 for (
const Fragment &
F : Fragments)
1221 PHeader.p_align = std::max((
uint64_t)PHeader.p_align,
F.AddrAlign);
1232 return (isa<ELFYAML::Fill>(C) ||
1233 cast<ELFYAML::Section>(C)->Type != ELF::SHT_NOBITS);
1240template <
class ELFT>
1241void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1243 ContiguousBlobAccumulator &CBA) {
1247 SHeader.sh_size = *S.
Size;
1252 if (shouldAllocateFileSpace(Doc.ProgramHeaders, S))
1253 CBA.writeZeros(*S.
Size);
1256template <
class ELFT>
1257void ELFState<ELFT>::writeSectionContent(
1259 ContiguousBlobAccumulator &CBA) {
1261 SHeader.sh_info = *Section.Info;
1270template <
class ELFT>
1271void ELFState<ELFT>::writeSectionContent(
1273 ContiguousBlobAccumulator &CBA) {
1277 "Section type is not SHT_REL nor SHT_RELA");
1279 if (!
Section.RelocatableSec.empty())
1280 SHeader.sh_info = toSectionIndex(
Section.RelocatableSec,
Section.Name);
1287 typename ELFT::uint OffsetMask = 8,
Offset = 0, Addend = 0;
1289 uint64_t CurrentOffset = CBA.getOffset();
1292 OffsetMask |= Rel.
Offset;
1298 const bool IsDynamic =
Section.Link && (*
Section.Link ==
".dynsym");
1306 (
static_cast<typename ELFT::uint
>(Rel.
Offset) -
Offset) >> Shift;
1309 DeltaOffset * 8 + (SymIdx != CurSymIdx) + (
Type != Rel.
Type ? 2 : 0) +
1310 (Addend !=
static_cast<typename ELFT::uint
>(Rel.
Addend) ? 4 : 0);
1311 if (DeltaOffset < 0x10) {
1314 CBA.write(
B | 0x80);
1315 CBA.writeULEB128(DeltaOffset >> 4);
1320 std::make_signed_t<typename ELFT::uint>(CurSymIdx - SymIdx));
1324 CBA.writeSLEB128(
static_cast<int32_t
>(Rel.
Type -
Type));
1329 std::make_signed_t<typename ELFT::uint>(Rel.
Addend - Addend));
1332 }
else if (IsRela) {
1335 REntry.r_offset = Rel.
Offset;
1336 REntry.r_addend = Rel.
Addend;
1338 CBA.write((
const char *)&REntry,
sizeof(REntry));
1342 REntry.r_offset = Rel.
Offset;
1344 CBA.write((
const char *)&REntry,
sizeof(REntry));
1348 SHeader.sh_size = CBA.getOffset() - CurrentOffset;
1351template <
class ELFT>
1352void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1354 ContiguousBlobAccumulator &CBA) {
1358 for (llvm::yaml::Hex64 E : *
Section.Entries) {
1359 if (!ELFT::Is64Bits && E > UINT32_MAX)
1362 CBA.write<uintX_t>(E, ELFT::Endianness);
1365 SHeader.sh_size =
sizeof(uintX_t) *
Section.Entries->size();
1368template <
class ELFT>
1369void ELFState<ELFT>::writeSectionContent(
1371 ContiguousBlobAccumulator &CBA) {
1381 CBA.write<
uint32_t>(E, ELFT::Endianness);
1382 SHeader.sh_size = Shndx.
Entries->size() * SHeader.sh_entsize;
1385template <
class ELFT>
1386void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1388 ContiguousBlobAccumulator &CBA) {
1390 "Section type is not SHT_GROUP");
1400 unsigned int SectionIndex = 0;
1401 if (
Member.sectionNameOrType ==
"GRP_COMDAT")
1404 SectionIndex = toSectionIndex(
Member.sectionNameOrType,
Section.Name);
1405 CBA.write<
uint32_t>(SectionIndex, ELFT::Endianness);
1407 SHeader.sh_size = SHeader.sh_entsize *
Section.Members->size();
1410template <
class ELFT>
1411void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1413 ContiguousBlobAccumulator &CBA) {
1419 SHeader.sh_size =
Section.Entries->size() * SHeader.sh_entsize;
1422template <
class ELFT>
1423void ELFState<ELFT>::writeSectionContent(
1425 ContiguousBlobAccumulator &CBA) {
1430 CBA.write<uintX_t>(E.
Address, ELFT::Endianness);
1431 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(E.
Size);
1435template <
class ELFT>
1436void ELFState<ELFT>::writeSectionContent(
1438 ContiguousBlobAccumulator &CBA) {
1442 <<
"PGOAnalyses should not exist in SHT_LLVM_BB_ADDR_MAP when "
1443 "Entries does not exist";
1447 const std::vector<ELFYAML::PGOAnalysisMapEntry> *PGOAnalyses =
nullptr;
1451 "in SHT_LLVM_BB_ADDR_MAP";
1453 PGOAnalyses = &
Section.PGOAnalyses.value();
1461 <<
static_cast<int>(E.Version)
1462 <<
"; encoding using the most recent version";
1463 CBA.
write(E.Version);
1464 CBA.
write(E.Feature);
1465 SHeader.sh_size += 2;
1468 bool MultiBBRangeFeatureEnabled =
false;
1472 MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
1474 MultiBBRangeFeatureEnabled ||
1475 (E.NumBBRanges.has_value() && E.NumBBRanges.value() != 1) ||
1476 (E.BBRanges && E.BBRanges->size() != 1);
1477 if (MultiBBRange && !MultiBBRangeFeatureEnabled)
1479 <<
") does not support multiple BB ranges.";
1484 E.NumBBRanges.value_or(E.BBRanges ? E.BBRanges->size() : 0);
1485 SHeader.sh_size += CBA.writeULEB128(NumBBRanges);
1490 bool EmitCallsiteEndOffsets =
1491 FeatureOrErr->CallsiteEndOffsets || E.hasAnyCallsiteEndOffsets();
1494 CBA.write<uintX_t>(BBR.
BaseAddress, ELFT::Endianness);
1500 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(NumBlocks);
1502 if (!BBR.
BBEntries || FeatureOrErr->OmitBBEntries)
1507 SHeader.sh_size += CBA.writeULEB128(BBE.
ID);
1509 if (EmitCallsiteEndOffsets) {
1510 size_t NumCallsiteEndOffsets =
1512 SHeader.sh_size += CBA.writeULEB128(NumCallsiteEndOffsets);
1515 SHeader.sh_size += CBA.writeULEB128(
Offset);
1518 SHeader.sh_size += CBA.writeULEB128(BBE.
Size);
1519 SHeader.sh_size += CBA.writeULEB128(BBE.
Metadata);
1532 const auto &PGOBBEntries = PGOEntry.
PGOBBEntries.value();
1533 if (TotalNumBlocks != PGOBBEntries.size()) {
1535 "BBEntries in SHT_LLVM_BB_ADDR_MAP.\n"
1536 <<
"Mismatch on function with address: "
1537 << E.getFunctionAddress();
1541 for (
const auto &PGOBBE : PGOBBEntries) {
1543 SHeader.sh_size += CBA.writeULEB128(*PGOBBE.BBFreq);
1544 if (PGOBBE.Successors) {
1545 SHeader.sh_size += CBA.writeULEB128(PGOBBE.Successors->size());
1546 for (
const auto &[
ID,
BrProb] : *PGOBBE.Successors) {
1547 SHeader.sh_size += CBA.writeULEB128(
ID);
1548 SHeader.sh_size += CBA.writeULEB128(
BrProb);
1555template <
class ELFT>
1556void ELFState<ELFT>::writeSectionContent(
1558 ContiguousBlobAccumulator &CBA) {
1563 CBA.write(
LO.Key.data(),
LO.Key.size());
1565 CBA.write(
LO.Value.data(),
LO.Value.size());
1567 SHeader.sh_size += (
LO.Key.size() +
LO.Value.size() + 2);
1571template <
class ELFT>
1572void ELFState<ELFT>::writeSectionContent(
1574 ContiguousBlobAccumulator &CBA) {
1579 CBA.write(
Lib.data(),
Lib.size());
1581 SHeader.sh_size +=
Lib.size() + 1;
1585template <
class ELFT>
1587ELFState<ELFT>::alignToOffset(ContiguousBlobAccumulator &CBA,
uint64_t Align,
1588 std::optional<llvm::yaml::Hex64>
Offset) {
1589 uint64_t CurrentOffset = CBA.getOffset();
1596 return CurrentOffset;
1605 CBA.writeZeros(AlignedOffset - CurrentOffset);
1606 return AlignedOffset;
1609template <
class ELFT>
1610void ELFState<ELFT>::writeSectionContent(
1612 ContiguousBlobAccumulator &CBA) {
1622template <
class ELFT>
1623void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1625 ContiguousBlobAccumulator &CBA) {
1630 Section.NBucket.value_or(llvm::yaml::Hex64(
Section.Bucket->size())),
1633 Section.NChain.value_or(llvm::yaml::Hex64(
Section.Chain->size())),
1637 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1639 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1641 SHeader.sh_size = (2 +
Section.Bucket->size() +
Section.Chain->size()) * 4;
1644template <
class ELFT>
1645void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1647 ContiguousBlobAccumulator &CBA) {
1650 SHeader.sh_info = *
Section.Info;
1652 SHeader.sh_info =
Section.Entries->size();
1658 for (
size_t I = 0;
I <
Section.Entries->size(); ++
I) {
1662 VerDef.vd_version = E.
Version.value_or(1);
1663 VerDef.vd_flags = E.
Flags.value_or(0);
1665 VerDef.vd_hash = E.
Hash.value_or(0);
1666 VerDef.vd_aux = E.
VDAux.value_or(
sizeof(Elf_Verdef));
1668 if (
I ==
Section.Entries->size() - 1)
1672 sizeof(Elf_Verdef) + E.
VerNames.size() *
sizeof(Elf_Verdaux);
1673 CBA.write((
const char *)&VerDef,
sizeof(Elf_Verdef));
1675 for (
size_t J = 0; J < E.
VerNames.size(); ++J, ++AuxCnt) {
1676 Elf_Verdaux VerdAux;
1677 VerdAux.vda_name = DotDynstr.getOffset(E.
VerNames[J]);
1679 VerdAux.vda_next = 0;
1681 VerdAux.vda_next =
sizeof(Elf_Verdaux);
1682 CBA.write((
const char *)&VerdAux,
sizeof(Elf_Verdaux));
1686 SHeader.sh_size =
Section.Entries->size() *
sizeof(Elf_Verdef) +
1687 AuxCnt *
sizeof(Elf_Verdaux);
1690template <
class ELFT>
1691void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1693 ContiguousBlobAccumulator &CBA) {
1695 SHeader.sh_info = *
Section.Info;
1697 SHeader.sh_info =
Section.VerneedV->size();
1703 for (
size_t I = 0;
I <
Section.VerneedV->size(); ++
I) {
1706 Elf_Verneed VerNeed;
1707 VerNeed.vn_version = VE.
Version;
1708 VerNeed.vn_file = DotDynstr.getOffset(VE.
File);
1709 if (
I ==
Section.VerneedV->size() - 1)
1710 VerNeed.vn_next = 0;
1713 sizeof(Elf_Verneed) + VE.
AuxV.size() *
sizeof(Elf_Vernaux);
1714 VerNeed.vn_cnt = VE.
AuxV.size();
1715 VerNeed.vn_aux =
sizeof(Elf_Verneed);
1716 CBA.write((
const char *)&VerNeed,
sizeof(Elf_Verneed));
1718 for (
size_t J = 0; J < VE.
AuxV.size(); ++J, ++AuxCnt) {
1721 Elf_Vernaux VernAux;
1722 VernAux.vna_hash = VAuxE.
Hash;
1723 VernAux.vna_flags = VAuxE.
Flags;
1724 VernAux.vna_other = VAuxE.
Other;
1725 VernAux.vna_name = DotDynstr.getOffset(VAuxE.
Name);
1726 if (J == VE.
AuxV.size() - 1)
1727 VernAux.vna_next = 0;
1729 VernAux.vna_next =
sizeof(Elf_Vernaux);
1730 CBA.write((
const char *)&VernAux,
sizeof(Elf_Vernaux));
1734 SHeader.sh_size =
Section.VerneedV->size() *
sizeof(Elf_Verneed) +
1735 AuxCnt *
sizeof(Elf_Vernaux);
1738template <
class ELFT>
1739void ELFState<ELFT>::writeSectionContent(
1741 ContiguousBlobAccumulator &CBA) {
1749 SHeader.sh_size =
Section.Entries->size() * 8;
1752template <
class ELFT>
1753void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1755 ContiguousBlobAccumulator &CBA) {
1757 "Section type is not SHT_MIPS_ABIFLAGS");
1761 SHeader.sh_size = SHeader.sh_entsize;
1774 CBA.write((
const char *)&Flags,
sizeof(Flags));
1777template <
class ELFT>
1778void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1780 ContiguousBlobAccumulator &CBA) {
1782 "Section type is not SHT_DYNAMIC");
1788 CBA.write<uintX_t>(DE.
Tag, ELFT::Endianness);
1789 CBA.write<uintX_t>(DE.
Val, ELFT::Endianness);
1791 SHeader.sh_size = 2 *
sizeof(uintX_t) *
Section.Entries->size();
1794template <
class ELFT>
1795void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1797 ContiguousBlobAccumulator &CBA) {
1803 CBA.writeULEB128(toSymbolIndex(
Sym,
Section.Name,
false));
1806template <
class ELFT>
1807void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1809 ContiguousBlobAccumulator &CBA) {
1814 switch (
Section.AddressAlign) {
1828 if (CBA.getOffset() !=
alignTo(CBA.getOffset(),
Align)) {
1838 if (
NE.Name.empty())
1839 CBA.write<
uint32_t>(0, ELFT::Endianness);
1841 CBA.write<
uint32_t>(
NE.Name.size() + 1, ELFT::Endianness);
1844 if (
NE.Desc.binary_size() == 0)
1845 CBA.write<
uint32_t>(0, ELFT::Endianness);
1847 CBA.write<
uint32_t>(
NE.Desc.binary_size(), ELFT::Endianness);
1850 CBA.write<
uint32_t>(
NE.Type, ELFT::Endianness);
1853 if (!
NE.Name.empty()) {
1854 CBA.write(
NE.Name.data(),
NE.Name.size());
1859 if (
NE.Desc.binary_size() != 0) {
1860 CBA.padToAlignment(
Align);
1861 CBA.writeAsBinary(
NE.Desc);
1864 CBA.padToAlignment(
Align);
1867 SHeader.sh_size = CBA.tell() -
Offset;
1870template <
class ELFT>
1871void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1873 ContiguousBlobAccumulator &CBA) {
1895 if (
Section.Header->MaskWords)
1904 for (llvm::yaml::Hex64 Val : *
Section.BloomFilter)
1905 CBA.write<uintX_t>(Val, ELFT::Endianness);
1908 for (llvm::yaml::Hex32 Val : *
Section.HashBuckets)
1909 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1912 for (llvm::yaml::Hex32 Val : *
Section.HashValues)
1913 CBA.write<
uint32_t>(Val, ELFT::Endianness);
1915 SHeader.sh_size = 16 +
1916 Section.BloomFilter->size() *
sizeof(
typename ELFT::uint) +
1917 Section.HashBuckets->size() * 4 +
1918 Section.HashValues->size() * 4;
1921template <
class ELFT>
1923 ContiguousBlobAccumulator &CBA) {
1924 size_t PatternSize = Fill.
Pattern ? Fill.
Pattern->binary_size() : 0;
1926 CBA.writeZeros(Fill.
Size);
1932 for (; Written + PatternSize <= Fill.
Size; Written += PatternSize)
1933 CBA.writeAsBinary(*Fill.
Pattern);
1934 CBA.writeAsBinary(*Fill.
Pattern, Fill.
Size - Written);
1937template <
class ELFT>
1940 Doc.getSectionHeaderTable();
1950 if (!
Ret.try_emplace(Hdr.Name, ++SecNdx).second)
1951 reportError(
"repeated section name: '" + Hdr.Name +
1952 "' in the section header description");
1966 if (S == Doc.getSections().front())
1970 "' should be present in the 'Sections' or 'Excluded' lists");
1974 for (
const auto &It : Seen)
1975 reportError(
"section header contains undefined section '" + It.getKey() +
1980template <
class ELFT>
void ELFState<ELFT>::buildSectionIndex() {
1989 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
1991 Doc.getSectionHeaderTable();
1994 if (!ExcludedSectionHeaders.insert(Hdr.
Name).second)
1997 if (SectionHeaders.
NoHeaders.value_or(
false))
1999 if (!ExcludedSectionHeaders.insert(S->
Name).second)
2007 if (!SN2I.addName(S->
Name, Index))
2010 if (!ExcludedSectionHeaders.count(S->
Name))
2015template <
class ELFT>
void ELFState<ELFT>::buildSymbolIndexes() {
2017 for (
size_t I = 0, S =
V.size();
I < S; ++
I) {
2019 if (!
Sym.Name.empty() && !
Map.addName(
Sym.Name,
I + 1))
2025 Build(*Doc.Symbols, SymN2I);
2026 if (Doc.DynamicSymbols)
2027 Build(*Doc.DynamicSymbols, DynSymN2I);
2030template <
class ELFT>
void ELFState<ELFT>::finalizeStrings() {
2035 DotStrtab.finalize();
2038 if (Doc.DynamicSymbols)
2045 if (
auto VerNeed = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
2046 if (VerNeed->VerneedV) {
2048 DotDynstr.add(VE.
File);
2050 DotDynstr.add(Aux.
Name);
2053 }
else if (
auto VerDef = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
2054 if (VerDef->Entries)
2057 DotDynstr.add(
Name);
2061 DotDynstr.finalize();
2065 if (ShStrtabStrings != &DotStrtab && ShStrtabStrings != &DotDynstr)
2066 ShStrtabStrings->finalize();
2069template <
class ELFT>
2072 ELFState<ELFT> State(Doc, EH);
2078 State.buildSectionIndex();
2079 State.buildSymbolIndexes();
2084 State.finalizeStrings();
2089 std::vector<Elf_Phdr> PHeaders;
2090 State.initProgramHeaders(PHeaders);
2094 const size_t SectionContentBeginOffset =
2100 ContiguousBlobAccumulator CBA(SectionContentBeginOffset, MaxSize);
2102 std::vector<Elf_Shdr> SHeaders;
2103 State.initSectionHeaders(SHeaders, CBA);
2106 State.setProgramHeaderLayout(PHeaders, SHeaders);
2108 bool ReachedLimit = CBA.getOffset() > MaxSize;
2109 if (
Error E = CBA.takeLimitError()) {
2112 ReachedLimit =
true;
2117 "the desired output size is greater than permitted. Use the "
2118 "--max-size option to change the limit");
2123 State.writeELFHeader(
OS);
2128 CBA.updateDataAt(*SHT.
Offset, SHeaders.data(),
2131 CBA.writeBlobToStream(
OS);
2144 return ELFState<object::ELF64LE>::writeELF(Out, Doc, EH, MaxSize);
2145 return ELFState<object::ELF64BE>::writeELF(Out, Doc, EH, MaxSize);
2148 return ELFState<object::ELF32LE>::writeELF(Out, Doc, EH, MaxSize);
2149 return ELFState<object::ELF32BE>::writeELF(Out, Doc, EH, MaxSize);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
DXIL Resource Implicit Binding
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.
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.
LLVM_ABI size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
LLVM_ABI 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 LLVM_ABI 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.
LLVM_ABI 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
LLVM_ABI 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)
LLVM_ABI 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.
const char * toString(DWARFSectionKind Kind)
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.
LLVM_ABI SetVector< StringRef > getNonEmptySectionNames() const
llvm::yaml::Hex64 Metadata
std::optional< std::vector< llvm::yaml::Hex64 > > CallsiteEndOffsets
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::optional< uint16_t > VDAux
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.