46class ContiguousBlobAccumulator {
59 "reached the output size limit");
65 : InitialOffset(BaseOffset), MaxSize(
SizeLimit),
OS(Buf) {}
69 void writeBlobToStream(
raw_ostream &Out)
const { Out <<
OS.str(); }
71 Error takeLimitError() {
74 return std::move(ReachedLimitErr);
84 uint64_t PaddingSize = AlignedOffset - CurrentOffset;
85 if (!checkLimit(PaddingSize))
88 writeZeros(PaddingSize);
99 if (!checkLimit(
Bin.binary_size()))
101 Bin.writeAsBinary(OS,
N);
110 if (checkLimit(
Size))
114 void write(
unsigned char C) {
119 unsigned writeULEB128(
uint64_t Val) {
126 if (checkLimit(
sizeof(
T)))
127 support::endian::write<T>(OS, Val,
E);
132 memcpy(&Buf[Pos - InitialOffset],
Data,
Size);
144 return Map.insert({
Name, Ndx}).second;
159 assert(
false &&
"Expected section not found in index");
162 unsigned size()
const {
return Map.size(); }
177template <
class ELFT>
class ELFState {
197 StringRef SectionHeaderStringTableName =
".shstrtab";
202 NameToIdxMap DynSymN2I;
208 bool HasError =
false;
218 void buildSectionIndex();
219 void buildSymbolIndexes();
220 void initProgramHeaders(std::vector<Elf_Phdr> &PHeaders);
221 bool initImplicitHeader(ContiguousBlobAccumulator &CBA, Elf_Shdr &Header,
223 void initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
224 ContiguousBlobAccumulator &CBA);
225 void initSymtabSectionHeader(Elf_Shdr &SHeader, SymtabType STType,
226 ContiguousBlobAccumulator &CBA,
228 void initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
230 ContiguousBlobAccumulator &CBA,
232 void initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
233 ContiguousBlobAccumulator &CBA,
235 void setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
236 std::vector<Elf_Shdr> &SHeaders);
238 std::vector<Fragment>
242 void finalizeStrings();
244 void writeSectionContent(Elf_Shdr &SHeader,
246 ContiguousBlobAccumulator &CBA);
247 void writeSectionContent(Elf_Shdr &SHeader,
249 ContiguousBlobAccumulator &CBA);
250 void writeSectionContent(Elf_Shdr &SHeader,
252 ContiguousBlobAccumulator &CBA);
253 void writeSectionContent(Elf_Shdr &SHeader,
255 ContiguousBlobAccumulator &CBA);
256 void writeSectionContent(Elf_Shdr &SHeader,
258 ContiguousBlobAccumulator &CBA);
259 void writeSectionContent(Elf_Shdr &SHeader,
261 ContiguousBlobAccumulator &CBA);
262 void writeSectionContent(Elf_Shdr &SHeader,
264 ContiguousBlobAccumulator &CBA);
265 void writeSectionContent(Elf_Shdr &SHeader,
267 ContiguousBlobAccumulator &CBA);
268 void writeSectionContent(Elf_Shdr &SHeader,
270 ContiguousBlobAccumulator &CBA);
271 void writeSectionContent(Elf_Shdr &SHeader,
273 ContiguousBlobAccumulator &CBA);
274 void writeSectionContent(Elf_Shdr &SHeader,
276 ContiguousBlobAccumulator &CBA);
277 void writeSectionContent(Elf_Shdr &SHeader,
279 ContiguousBlobAccumulator &CBA);
280 void writeSectionContent(Elf_Shdr &SHeader,
282 ContiguousBlobAccumulator &CBA);
283 void writeSectionContent(Elf_Shdr &SHeader,
285 ContiguousBlobAccumulator &CBA);
286 void writeSectionContent(Elf_Shdr &SHeader,
288 ContiguousBlobAccumulator &CBA);
289 void writeSectionContent(Elf_Shdr &SHeader,
291 ContiguousBlobAccumulator &CBA);
292 void writeSectionContent(Elf_Shdr &SHeader,
294 ContiguousBlobAccumulator &CBA);
295 void writeSectionContent(Elf_Shdr &SHeader,
297 ContiguousBlobAccumulator &CBA);
298 void writeSectionContent(Elf_Shdr &SHeader,
300 ContiguousBlobAccumulator &CBA);
301 void writeSectionContent(Elf_Shdr &SHeader,
303 ContiguousBlobAccumulator &CBA);
304 void writeSectionContent(Elf_Shdr &SHeader,
306 ContiguousBlobAccumulator &CBA);
308 void writeFill(
ELFYAML::Fill &Fill, ContiguousBlobAccumulator &CBA);
318 std::optional<llvm::yaml::Hex64>
Offset);
329 return A.size() *
sizeof(
T);
336template <
class T>
static void zero(
T &Obj) { memset(&Obj, 0,
sizeof(Obj)); }
340 : Doc(
D), ErrHandler(EH) {
344 if (Doc.Header.SectionHeaderStringTable) {
345 SectionHeaderStringTableName = *Doc.Header.SectionHeaderStringTable;
346 if (*Doc.Header.SectionHeaderStringTable ==
".strtab")
347 ShStrtabStrings = &DotStrtab;
348 else if (*Doc.Header.SectionHeaderStringTable ==
".dynstr")
349 ShStrtabStrings = &DotDynstr;
353 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
355 if (Sections.empty() || Sections.front()->Type !=
ELF::SHT_NULL)
358 std::make_unique<ELFYAML::Section>(
359 ELFYAML::Chunk::ChunkKind::RawContent,
true));
363 for (
size_t I = 0;
I < Doc.Chunks.size(); ++
I) {
364 const std::unique_ptr<ELFYAML::Chunk> &
C = Doc.Chunks[
I];
367 if (
auto S = dyn_cast<ELFYAML::SectionHeaderTable>(
C.get())) {
369 reportError(
"multiple section header tables are not allowed");
377 if (
C->Name.empty()) {
384 if (!DocSections.
insert(
C->Name).second)
386 "' at YAML section/fill number " +
Twine(
I));
390 if (Doc.DynamicSymbols) {
391 if (SectionHeaderStringTableName ==
".dynsym")
392 reportError(
"cannot use '.dynsym' as the section header name table when "
393 "there are dynamic symbols");
394 ImplicitSections.
insert(
".dynsym");
395 ImplicitSections.
insert(
".dynstr");
398 if (SectionHeaderStringTableName ==
".symtab")
399 reportError(
"cannot use '.symtab' as the section header name table when "
400 "there are symbols");
401 ImplicitSections.
insert(
".symtab");
404 for (
StringRef DebugSecName : Doc.DWARF->getNonEmptySectionNames()) {
405 std::string SecName = (
"." + DebugSecName).str();
408 if (SectionHeaderStringTableName == SecName)
410 "' as the section header name table when it is needed for "
415 ImplicitSections.
insert(
".strtab");
416 if (!SecHdrTable || !SecHdrTable->
NoHeaders.value_or(
false))
417 ImplicitSections.
insert(SectionHeaderStringTableName);
421 for (
StringRef SecName : ImplicitSections) {
422 if (DocSections.
count(SecName))
425 std::unique_ptr<ELFYAML::Section> Sec = std::make_unique<ELFYAML::Section>(
426 ELFYAML::Chunk::ChunkKind::RawContent,
true );
429 if (SecName == SectionHeaderStringTableName)
431 else if (SecName ==
".dynsym")
433 else if (SecName ==
".symtab")
443 if (Doc.Chunks.back().get() == SecHdrTable)
444 Doc.Chunks.insert(Doc.Chunks.end() - 1, std::move(Sec));
446 Doc.Chunks.push_back(std::move(Sec));
452 Doc.Chunks.push_back(
453 std::make_unique<ELFYAML::SectionHeaderTable>(
true));
462 Header.e_ident[
EI_MAG0] = 0x7f;
467 Header.e_ident[
EI_DATA] = Doc.Header.Data;
469 Header.e_ident[
EI_OSABI] = Doc.Header.OSABI;
471 Header.e_type = Doc.Header.Type;
473 if (Doc.Header.Machine)
474 Header.e_machine = *Doc.Header.Machine;
479 Header.e_entry = Doc.Header.Entry;
480 Header.e_flags = Doc.Header.Flags;
481 Header.e_ehsize =
sizeof(Elf_Ehdr);
483 if (Doc.Header.EPhOff)
484 Header.e_phoff = *Doc.Header.EPhOff;
485 else if (!Doc.ProgramHeaders.empty())
486 Header.e_phoff =
sizeof(Header);
490 if (Doc.Header.EPhEntSize)
491 Header.e_phentsize = *Doc.Header.EPhEntSize;
492 else if (!Doc.ProgramHeaders.empty())
493 Header.e_phentsize =
sizeof(Elf_Phdr);
495 Header.e_phentsize = 0;
497 if (Doc.Header.EPhNum)
498 Header.e_phnum = *Doc.Header.EPhNum;
499 else if (!Doc.ProgramHeaders.empty())
500 Header.e_phnum = Doc.ProgramHeaders.size();
504 Header.e_shentsize = Doc.Header.EShEntSize ? (
uint16_t)*Doc.Header.EShEntSize
508 Doc.getSectionHeaderTable();
510 if (Doc.Header.EShOff)
511 Header.e_shoff = *Doc.Header.EShOff;
512 else if (SectionHeaders.
Offset)
513 Header.e_shoff = *SectionHeaders.
Offset;
517 if (Doc.Header.EShNum)
518 Header.e_shnum = *Doc.Header.EShNum;
520 Header.e_shnum = SectionHeaders.
getNumHeaders(Doc.getSections().size());
522 if (Doc.Header.EShStrNdx)
523 Header.e_shstrndx = *Doc.Header.EShStrNdx;
524 else if (SectionHeaders.
Offset &&
525 !ExcludedSectionHeaders.count(SectionHeaderStringTableName))
526 Header.e_shstrndx = SN2I.get(SectionHeaderStringTableName);
528 Header.e_shstrndx = 0;
530 OS.
write((
const char *)&Header,
sizeof(Header));
534void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
537 for (
size_t I = 0,
E = Doc.Chunks.size();
I !=
E; ++
I) {
538 if (
auto S = dyn_cast<ELFYAML::Fill>(Doc.Chunks[
I].get()))
539 NameToFill[S->Name] = S;
540 NameToIndex[Doc.Chunks[
I]->Name] =
I + 1;
543 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
544 for (
size_t I = 0,
E = Doc.ProgramHeaders.size();
I !=
E; ++
I) {
548 Phdr.p_type = YamlPhdr.
Type;
549 Phdr.p_flags = YamlPhdr.
Flags;
550 Phdr.p_vaddr = YamlPhdr.
VAddr;
551 Phdr.p_paddr = YamlPhdr.
PAddr;
552 PHeaders.push_back(Phdr);
561 "' by the 'FirstSec' key of the program header with index " +
566 "' by the 'LastSec' key of the program header with index " +
573 ": the section index of " + *YamlPhdr.
FirstSec +
574 " is greater than the index of " + *YamlPhdr.
LastSec);
576 for (
size_t I = First;
I <=
Last; ++
I)
577 YamlPhdr.
Chunks.push_back(Doc.Chunks[
I - 1].get());
587 if (!SN2I.lookup(S,
Index) && !to_integer(S,
Index)) {
589 reportError(
"unknown section referenced: '" + S +
"' by YAML symbol '" +
592 reportError(
"unknown section referenced: '" + S +
"' by YAML section '" +
598 Doc.getSectionHeaderTable();
605 size_t FirstExcluded =
607 if (
Index > FirstExcluded) {
609 reportError(
"unable to link '" + LocSec +
"' to excluded section '" + S +
612 reportError(
"excluded section referenced: '" + S +
"' by symbol '" +
621 const NameToIdxMap &
SymMap = IsDynamic ? DynSymN2I : SymN2I;
626 reportError(
"unknown symbol referenced: '" + S +
"' by YAML section '" +
637 if (
From->ShAddrAlign)
638 To.sh_addralign = *
From->ShAddrAlign;
640 To.sh_flags = *
From->ShFlags;
642 To.sh_name = *
From->ShName;
644 To.sh_offset = *
From->ShOffset;
646 To.sh_size = *
From->ShSize;
648 To.sh_type = *
From->ShType;
652bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
656 if (Header.sh_offset)
659 if (SecName ==
".strtab")
660 initStrtabSectionHeader(Header, SecName, DotStrtab, CBA, YAMLSec);
661 else if (SecName ==
".dynstr")
662 initStrtabSectionHeader(Header, SecName, DotDynstr, CBA, YAMLSec);
663 else if (SecName == SectionHeaderStringTableName)
664 initStrtabSectionHeader(Header, SecName, *ShStrtabStrings, CBA, YAMLSec);
665 else if (SecName ==
".symtab")
666 initSymtabSectionHeader(Header, SymtabType::Static, CBA, YAMLSec);
667 else if (SecName ==
".dynsym")
668 initSymtabSectionHeader(Header, SymtabType::Dynamic, CBA, YAMLSec);
672 if (YAMLSec && !isa<ELFYAML::RawContentSection>(YAMLSec))
674 initDWARFSectionHeader(Header, SecName, CBA, YAMLSec);
678 LocationCounter += Header.sh_size;
681 overrideFields<ELFT>(YAMLSec, Header);
691 std::string Ret =
Name.empty() ?
"" :
Name.str() +
' ';
706 return S.
substr(0, SuffixPos - 1);
713 if (ExcludedSectionHeaders.count(
Name))
715 return ShStrtabStrings->getOffset(
Name);
719 const std::optional<yaml::BinaryRef> &
Content,
720 const std::optional<llvm::yaml::Hex64> &
Size) {
721 size_t ContentSize = 0;
724 ContentSize =
Content->binary_size();
730 CBA.writeZeros(*
Size - ContentSize);
758void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
759 ContiguousBlobAccumulator &CBA) {
762 SHeaders.resize(Doc.getSections().size());
764 for (
const std::unique_ptr<ELFYAML::Chunk> &
D : Doc.Chunks) {
766 S->Offset = alignToOffset(CBA, 1, S->Offset);
768 LocationCounter += S->Size;
773 dyn_cast<ELFYAML::SectionHeaderTable>(
D.get())) {
774 if (S->NoHeaders.value_or(
false))
778 S->Offset = alignToOffset(CBA,
sizeof(
typename ELFT::uint),
781 S->Offset = alignToOffset(CBA, 1, S->Offset);
783 uint64_t Size = S->getNumHeaders(SHeaders.size()) *
sizeof(Elf_Shdr);
786 CBA.writeZeros(
Size);
787 LocationCounter +=
Size;
792 bool IsFirstUndefSection = Sec == Doc.getSections().front();
796 Elf_Shdr &SHeader = SHeaders[SN2I.get(Sec->
Name)];
798 SHeader.sh_link = toSectionIndex(*Sec->
Link, Sec->
Name);
802 if (!LinkSec.
empty() && !ExcludedSectionHeaders.count(LinkSec) &&
803 SN2I.lookup(LinkSec, Link))
804 SHeader.sh_link =
Link;
808 SHeader.sh_entsize = *Sec->
EntSize;
810 SHeader.sh_entsize = ELFYAML::getDefaultShEntSize<ELFT>(
817 if (initImplicitHeader(CBA, SHeader, Sec->
Name,
821 assert(Sec &&
"It can't be null unless it is an implicit section. But all "
822 "implicit sections should already have been handled above.");
826 SHeader.sh_type = Sec->
Type;
828 SHeader.sh_flags = *Sec->
Flags;
833 if (!IsFirstUndefSection || Sec->
Offset)
834 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, Sec->
Offset);
836 assignSectionAddress(SHeader, Sec);
838 if (IsFirstUndefSection) {
839 if (
auto RawSec = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
842 SHeader.sh_size = *RawSec->Size;
844 SHeader.sh_info = *RawSec->Info;
847 LocationCounter += SHeader.sh_size;
848 overrideFields<ELFT>(Sec, SHeader);
852 if (!isa<ELFYAML::NoBitsSection>(Sec) && (Sec->
Content || Sec->
Size))
855 if (
auto S = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
856 writeSectionContent(SHeader, *S, CBA);
857 }
else if (
auto S = dyn_cast<ELFYAML::SymtabShndxSection>(Sec)) {
858 writeSectionContent(SHeader, *S, CBA);
859 }
else if (
auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
860 writeSectionContent(SHeader, *S, CBA);
861 }
else if (
auto S = dyn_cast<ELFYAML::RelrSection>(Sec)) {
862 writeSectionContent(SHeader, *S, CBA);
863 }
else if (
auto S = dyn_cast<ELFYAML::GroupSection>(Sec)) {
864 writeSectionContent(SHeader, *S, CBA);
865 }
else if (
auto S = dyn_cast<ELFYAML::ARMIndexTableSection>(Sec)) {
866 writeSectionContent(SHeader, *S, CBA);
867 }
else if (
auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec)) {
868 writeSectionContent(SHeader, *S, CBA);
869 }
else if (
auto S = dyn_cast<ELFYAML::NoBitsSection>(Sec)) {
870 writeSectionContent(SHeader, *S, CBA);
871 }
else if (
auto S = dyn_cast<ELFYAML::DynamicSection>(Sec)) {
872 writeSectionContent(SHeader, *S, CBA);
873 }
else if (
auto S = dyn_cast<ELFYAML::SymverSection>(Sec)) {
874 writeSectionContent(SHeader, *S, CBA);
875 }
else if (
auto S = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
876 writeSectionContent(SHeader, *S, CBA);
877 }
else if (
auto S = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
878 writeSectionContent(SHeader, *S, CBA);
879 }
else if (
auto S = dyn_cast<ELFYAML::StackSizesSection>(Sec)) {
880 writeSectionContent(SHeader, *S, CBA);
881 }
else if (
auto S = dyn_cast<ELFYAML::HashSection>(Sec)) {
882 writeSectionContent(SHeader, *S, CBA);
883 }
else if (
auto S = dyn_cast<ELFYAML::AddrsigSection>(Sec)) {
884 writeSectionContent(SHeader, *S, CBA);
885 }
else if (
auto S = dyn_cast<ELFYAML::LinkerOptionsSection>(Sec)) {
886 writeSectionContent(SHeader, *S, CBA);
887 }
else if (
auto S = dyn_cast<ELFYAML::NoteSection>(Sec)) {
888 writeSectionContent(SHeader, *S, CBA);
889 }
else if (
auto S = dyn_cast<ELFYAML::GnuHashSection>(Sec)) {
890 writeSectionContent(SHeader, *S, CBA);
891 }
else if (
auto S = dyn_cast<ELFYAML::DependentLibrariesSection>(Sec)) {
892 writeSectionContent(SHeader, *S, CBA);
893 }
else if (
auto S = dyn_cast<ELFYAML::CallGraphProfileSection>(Sec)) {
894 writeSectionContent(SHeader, *S, CBA);
895 }
else if (
auto S = dyn_cast<ELFYAML::BBAddrMapSection>(Sec)) {
896 writeSectionContent(SHeader, *S, CBA);
901 LocationCounter += SHeader.sh_size;
904 overrideFields<ELFT>(Sec, SHeader);
909void ELFState<ELFT>::assignSectionAddress(Elf_Shdr &SHeader,
911 if (YAMLSec && YAMLSec->
Address) {
912 SHeader.sh_addr = *YAMLSec->
Address;
913 LocationCounter = *YAMLSec->
Address;
925 alignTo(LocationCounter, SHeader.sh_addralign ? SHeader.sh_addralign : 1);
926 SHeader.sh_addr = LocationCounter;
930 for (
size_t I = 0;
I < Symbols.size(); ++
I)
933 return Symbols.size();
937std::vector<typename ELFT::Sym>
940 std::vector<Elf_Sym>
Ret;
941 Ret.resize(Symbols.size() + 1);
952 else if (!
Sym.Name.empty())
957 Symbol.st_shndx = toSectionIndex(*
Sym.Section,
"",
Sym.Name);
961 Symbol.st_value =
Sym.Value.value_or(yaml::Hex64(0));
963 Symbol.st_size =
Sym.Size.value_or(yaml::Hex64(0));
970void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
972 ContiguousBlobAccumulator &CBA,
975 bool IsStatic = STType == SymtabType::Static;
977 if (IsStatic && Doc.Symbols)
978 Symbols = *Doc.Symbols;
979 else if (!IsStatic && Doc.DynamicSymbols)
980 Symbols = *Doc.DynamicSymbols;
983 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
985 bool HasSymbolsDescription =
986 (IsStatic && Doc.Symbols) || (!IsStatic && Doc.DynamicSymbols);
987 if (HasSymbolsDescription) {
988 StringRef Property = (IsStatic ?
"`Symbols`" :
"`DynamicSymbols`");
990 reportError(
"cannot specify both `Content` and " + Property +
991 " for symbol table section '" + RawSec->
Name +
"'");
993 reportError(
"cannot specify both `Size` and " + Property +
994 " for symbol table section '" + RawSec->
Name +
"'");
999 SHeader.sh_name = getSectionNameOffset(IsStatic ?
".symtab" :
".dynsym");
1002 SHeader.sh_type = YAMLSec->
Type;
1006 if (YAMLSec && YAMLSec->
Flags)
1007 SHeader.sh_flags = *YAMLSec->
Flags;
1013 SHeader.sh_info = (RawSec && RawSec->
Info) ? (
unsigned)(*RawSec->
Info)
1017 assignSectionAddress(SHeader, YAMLSec);
1019 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1020 RawSec ? RawSec->
Offset : std::nullopt);
1022 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1028 std::vector<Elf_Sym> Syms =
1029 toELFSymbols(Symbols, IsStatic ? DotStrtab : DotDynstr);
1030 SHeader.sh_size = Syms.size() *
sizeof(Elf_Sym);
1031 CBA.write((
const char *)Syms.data(), SHeader.sh_size);
1034template <
class ELFT>
1035void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1037 ContiguousBlobAccumulator &CBA,
1044 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1046 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1047 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1049 if (RawSec && (RawSec->
Content || RawSec->
Size)) {
1054 SHeader.sh_size = STB.
getSize();
1057 if (RawSec && RawSec->
Info)
1058 SHeader.sh_info = *RawSec->
Info;
1060 if (YAMLSec && YAMLSec->
Flags)
1061 SHeader.sh_flags = *YAMLSec->
Flags;
1062 else if (
Name ==
".dynstr")
1065 assignSectionAddress(SHeader, YAMLSec);
1070 return Name.consume_front(
".") && DebugSecNames.
count(
Name);
1073template <
class ELFT>
1076 ContiguousBlobAccumulator &CBA) {
1087 if (
Error Err = EmitFunc(*
OS, DWARF))
1088 return std::move(Err);
1090 return CBA.tell() - BeginOffset;
1093template <
class ELFT>
1094void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1095 ContiguousBlobAccumulator &CBA,
1100 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1101 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1104 dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
1108 "' contents in the 'DWARF' entry and the 'Content' "
1109 "or 'Size' in the 'Sections' entry at the same time");
1112 emitDWARF<ELFT>(SHeader,
Name, *Doc.DWARF, CBA))
1113 SHeader.sh_size = *ShSizeOrErr;
1121 "entry or a RawContentSection");
1123 if (RawSec && RawSec->
Info)
1124 SHeader.sh_info = *RawSec->
Info;
1126 if (YAMLSec && YAMLSec->
Flags)
1127 SHeader.sh_flags = *YAMLSec->
Flags;
1128 else if (
Name ==
".debug_str")
1131 assignSectionAddress(SHeader, YAMLSec);
1134template <
class ELFT>
void ELFState<ELFT>::reportError(
const Twine &Msg) {
1139template <
class ELFT>
void ELFState<ELFT>::reportError(
Error Err) {
1145template <
class ELFT>
1146std::vector<Fragment>
1149 std::vector<Fragment>
Ret;
1158 const Elf_Shdr &
H = SHeaders[SN2I.get(S->
Name)];
1159 Ret.push_back({
H.sh_offset,
H.sh_size,
H.sh_type,
H.sh_addralign});
1164template <
class ELFT>
1165void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
1166 std::vector<Elf_Shdr> &SHeaders) {
1168 for (
auto &YamlPhdr : Doc.ProgramHeaders) {
1169 Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
1170 std::vector<Fragment> Fragments = getPhdrFragments(YamlPhdr, SHeaders);
1172 return A.Offset <
B.Offset;
1174 reportError(
"sections in the program header with index " +
1175 Twine(PhdrIdx) +
" are not sorted by their file offset");
1178 if (!Fragments.empty() && *YamlPhdr.
Offset > Fragments.front().Offset)
1180 " must be less than or equal to the minimum file offset of "
1181 "all included sections (0x" +
1183 PHeader.p_offset = *YamlPhdr.
Offset;
1184 }
else if (!Fragments.empty()) {
1185 PHeader.p_offset = Fragments.front().Offset;
1190 PHeader.p_filesz = *YamlPhdr.
FileSize;
1191 }
else if (!Fragments.empty()) {
1192 uint64_t FileSize = Fragments.back().Offset - PHeader.p_offset;
1197 FileSize += Fragments.back().Size;
1198 PHeader.p_filesz = FileSize;
1202 uint64_t MemOffset = PHeader.p_offset;
1203 for (
const Fragment &
F : Fragments)
1204 MemOffset = std::max(MemOffset,
F.Offset +
F.Size);
1207 : MemOffset - PHeader.p_offset;
1209 if (YamlPhdr.
Align) {
1210 PHeader.p_align = *YamlPhdr.
Align;
1215 PHeader.p_align = 1;
1216 for (
const Fragment &
F : Fragments)
1217 PHeader.p_align = std::max((
uint64_t)PHeader.p_align,
F.AddrAlign);
1228 return (isa<ELFYAML::Fill>(C) ||
1229 cast<ELFYAML::Section>(C)->Type != ELF::SHT_NOBITS);
1236template <
class ELFT>
1237void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1239 ContiguousBlobAccumulator &CBA) {
1243 SHeader.sh_size = *S.
Size;
1248 if (shouldAllocateFileSpace(Doc.ProgramHeaders, S))
1249 CBA.writeZeros(*S.
Size);
1252template <
class ELFT>
1253void ELFState<ELFT>::writeSectionContent(
1255 ContiguousBlobAccumulator &CBA) {
1257 SHeader.sh_info = *Section.Info;
1266template <
class ELFT>
1267void ELFState<ELFT>::writeSectionContent(
1269 ContiguousBlobAccumulator &CBA) {
1272 "Section type is not SHT_REL nor SHT_RELA");
1274 if (!
Section.RelocatableSec.empty())
1275 SHeader.sh_info = toSectionIndex(
Section.RelocatableSec,
Section.Name);
1282 const bool IsDynamic =
Section.Link && (*
Section.Link ==
".dynsym");
1288 REntry.r_offset = Rel.
Offset;
1289 REntry.r_addend = Rel.
Addend;
1291 CBA.write((
const char *)&REntry,
sizeof(REntry));
1295 REntry.r_offset = Rel.
Offset;
1297 CBA.write((
const char *)&REntry,
sizeof(REntry));
1301 SHeader.sh_size = (IsRela ?
sizeof(Elf_Rela) :
sizeof(Elf_Rel)) *
1305template <
class ELFT>
1306void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1308 ContiguousBlobAccumulator &CBA) {
1312 for (llvm::yaml::Hex64
E : *
Section.Entries) {
1313 if (!ELFT::Is64Bits &&
E > UINT32_MAX)
1316 CBA.write<uintX_t>(
E, ELFT::TargetEndianness);
1319 SHeader.sh_size =
sizeof(uintX_t) *
Section.Entries->size();
1322template <
class ELFT>
1323void ELFState<ELFT>::writeSectionContent(
1325 ContiguousBlobAccumulator &CBA) {
1335 CBA.write<
uint32_t>(
E, ELFT::TargetEndianness);
1336 SHeader.sh_size = Shndx.
Entries->size() * SHeader.sh_entsize;
1339template <
class ELFT>
1340void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1342 ContiguousBlobAccumulator &CBA) {
1344 "Section type is not SHT_GROUP");
1354 unsigned int SectionIndex = 0;
1355 if (
Member.sectionNameOrType ==
"GRP_COMDAT")
1358 SectionIndex = toSectionIndex(
Member.sectionNameOrType,
Section.Name);
1359 CBA.write<
uint32_t>(SectionIndex, ELFT::TargetEndianness);
1361 SHeader.sh_size = SHeader.sh_entsize *
Section.Members->size();
1364template <
class ELFT>
1365void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1367 ContiguousBlobAccumulator &CBA) {
1373 SHeader.sh_size =
Section.Entries->size() * SHeader.sh_entsize;
1376template <
class ELFT>
1377void ELFState<ELFT>::writeSectionContent(
1379 ContiguousBlobAccumulator &CBA) {
1384 CBA.write<uintX_t>(
E.Address, ELFT::TargetEndianness);
1385 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(
E.Size);
1389template <
class ELFT>
1390void ELFState<ELFT>::writeSectionContent(
1392 ContiguousBlobAccumulator &CBA) {
1401 <<
static_cast<int>(
E.Version)
1402 <<
"; encoding using the most recent version";
1405 SHeader.sh_size += 2;
1408 CBA.
write<uintX_t>(
E.Address, ELFT::TargetEndianness);
1412 E.NumBlocks.value_or(
E.BBEntries ?
E.BBEntries->size() : 0);
1413 SHeader.sh_size +=
sizeof(uintX_t) + CBA.writeULEB128(NumBlocks);
1419 SHeader.sh_size += CBA.writeULEB128(BBE.
ID);
1421 CBA.writeULEB128(BBE.
Size) +
1427template <
class ELFT>
1428void ELFState<ELFT>::writeSectionContent(
1430 ContiguousBlobAccumulator &CBA) {
1435 CBA.write(
LO.Key.data(),
LO.Key.size());
1437 CBA.write(
LO.Value.data(),
LO.Value.size());
1439 SHeader.sh_size += (
LO.Key.size() +
LO.Value.size() + 2);
1443template <
class ELFT>
1444void ELFState<ELFT>::writeSectionContent(
1446 ContiguousBlobAccumulator &CBA) {
1451 CBA.write(
Lib.data(),
Lib.size());
1453 SHeader.sh_size +=
Lib.size() + 1;
1457template <
class ELFT>
1459ELFState<ELFT>::alignToOffset(ContiguousBlobAccumulator &CBA,
uint64_t Align,
1460 std::optional<llvm::yaml::Hex64>
Offset) {
1461 uint64_t CurrentOffset = CBA.getOffset();
1468 return CurrentOffset;
1477 CBA.writeZeros(AlignedOffset - CurrentOffset);
1478 return AlignedOffset;
1481template <
class ELFT>
1482void ELFState<ELFT>::writeSectionContent(
1484 ContiguousBlobAccumulator &CBA) {
1489 CBA.write<
uint64_t>(
E.Weight, ELFT::TargetEndianness);
1494template <
class ELFT>
1495void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1497 ContiguousBlobAccumulator &CBA) {
1502 Section.NBucket.value_or(llvm::yaml::Hex64(
Section.Bucket->size())),
1503 ELFT::TargetEndianness);
1505 Section.NChain.value_or(llvm::yaml::Hex64(
Section.Chain->size())),
1506 ELFT::TargetEndianness);
1509 CBA.write<
uint32_t>(Val, ELFT::TargetEndianness);
1511 CBA.write<
uint32_t>(Val, ELFT::TargetEndianness);
1513 SHeader.sh_size = (2 +
Section.Bucket->size() +
Section.Chain->size()) * 4;
1516template <
class ELFT>
1517void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1519 ContiguousBlobAccumulator &CBA) {
1522 SHeader.sh_info = *
Section.Info;
1524 SHeader.sh_info =
Section.Entries->size();
1530 for (
size_t I = 0;
I <
Section.Entries->size(); ++
I) {
1534 VerDef.vd_version =
E.Version.value_or(1);
1535 VerDef.vd_flags =
E.Flags.value_or(0);
1536 VerDef.vd_ndx =
E.VersionNdx.value_or(0);
1537 VerDef.vd_hash =
E.Hash.value_or(0);
1538 VerDef.vd_aux =
sizeof(Elf_Verdef);
1539 VerDef.vd_cnt =
E.VerNames.size();
1540 if (
I ==
Section.Entries->size() - 1)
1544 sizeof(Elf_Verdef) +
E.VerNames.size() *
sizeof(Elf_Verdaux);
1545 CBA.write((
const char *)&VerDef,
sizeof(Elf_Verdef));
1547 for (
size_t J = 0; J <
E.VerNames.size(); ++J, ++AuxCnt) {
1548 Elf_Verdaux VernAux;
1549 VernAux.vda_name = DotDynstr.getOffset(
E.VerNames[J]);
1550 if (J ==
E.VerNames.size() - 1)
1551 VernAux.vda_next = 0;
1553 VernAux.vda_next =
sizeof(Elf_Verdaux);
1554 CBA.write((
const char *)&VernAux,
sizeof(Elf_Verdaux));
1558 SHeader.sh_size =
Section.Entries->size() *
sizeof(Elf_Verdef) +
1559 AuxCnt *
sizeof(Elf_Verdaux);
1562template <
class ELFT>
1563void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1565 ContiguousBlobAccumulator &CBA) {
1567 SHeader.sh_info = *
Section.Info;
1569 SHeader.sh_info =
Section.VerneedV->size();
1575 for (
size_t I = 0;
I <
Section.VerneedV->size(); ++
I) {
1578 Elf_Verneed VerNeed;
1579 VerNeed.vn_version = VE.
Version;
1580 VerNeed.vn_file = DotDynstr.getOffset(VE.
File);
1581 if (
I ==
Section.VerneedV->size() - 1)
1582 VerNeed.vn_next = 0;
1585 sizeof(Elf_Verneed) + VE.
AuxV.size() *
sizeof(Elf_Vernaux);
1586 VerNeed.vn_cnt = VE.
AuxV.size();
1587 VerNeed.vn_aux =
sizeof(Elf_Verneed);
1588 CBA.write((
const char *)&VerNeed,
sizeof(Elf_Verneed));
1590 for (
size_t J = 0; J < VE.
AuxV.size(); ++J, ++AuxCnt) {
1593 Elf_Vernaux VernAux;
1594 VernAux.vna_hash = VAuxE.
Hash;
1595 VernAux.vna_flags = VAuxE.
Flags;
1596 VernAux.vna_other = VAuxE.
Other;
1597 VernAux.vna_name = DotDynstr.getOffset(VAuxE.
Name);
1598 if (J == VE.
AuxV.size() - 1)
1599 VernAux.vna_next = 0;
1601 VernAux.vna_next =
sizeof(Elf_Vernaux);
1602 CBA.write((
const char *)&VernAux,
sizeof(Elf_Vernaux));
1606 SHeader.sh_size =
Section.VerneedV->size() *
sizeof(Elf_Verneed) +
1607 AuxCnt *
sizeof(Elf_Vernaux);
1610template <
class ELFT>
1611void ELFState<ELFT>::writeSectionContent(
1613 ContiguousBlobAccumulator &CBA) {
1618 CBA.write<
uint32_t>(
E.Offset, ELFT::TargetEndianness);
1619 CBA.write<
uint32_t>(
E.Value, ELFT::TargetEndianness);
1621 SHeader.sh_size =
Section.Entries->size() * 8;
1624template <
class ELFT>
1625void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1627 ContiguousBlobAccumulator &CBA) {
1629 "Section type is not SHT_MIPS_ABIFLAGS");
1633 SHeader.sh_size = SHeader.sh_entsize;
1646 CBA.write((
const char *)&Flags,
sizeof(Flags));
1649template <
class ELFT>
1650void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1652 ContiguousBlobAccumulator &CBA) {
1654 "Section type is not SHT_DYNAMIC");
1660 CBA.write<uintX_t>(DE.
Tag, ELFT::TargetEndianness);
1661 CBA.write<uintX_t>(DE.
Val, ELFT::TargetEndianness);
1663 SHeader.sh_size = 2 *
sizeof(uintX_t) *
Section.Entries->size();
1666template <
class ELFT>
1667void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1669 ContiguousBlobAccumulator &CBA) {
1675 CBA.writeULEB128(toSymbolIndex(
Sym,
Section.Name,
false));
1678template <
class ELFT>
1679void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1681 ContiguousBlobAccumulator &CBA) {
1688 if (
NE.Name.empty())
1689 CBA.write<
uint32_t>(0, ELFT::TargetEndianness);
1691 CBA.write<
uint32_t>(
NE.Name.size() + 1, ELFT::TargetEndianness);
1694 if (
NE.Desc.binary_size() == 0)
1695 CBA.write<
uint32_t>(0, ELFT::TargetEndianness);
1697 CBA.write<
uint32_t>(
NE.Desc.binary_size(), ELFT::TargetEndianness);
1700 CBA.write<
uint32_t>(
NE.Type, ELFT::TargetEndianness);
1703 if (!
NE.Name.empty()) {
1704 CBA.write(
NE.Name.data(),
NE.Name.size());
1706 CBA.padToAlignment(4);
1710 if (
NE.Desc.binary_size() != 0) {
1711 CBA.writeAsBinary(
NE.Desc);
1712 CBA.padToAlignment(4);
1716 SHeader.sh_size = CBA.tell() -
Offset;
1719template <
class ELFT>
1720void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1722 ContiguousBlobAccumulator &CBA) {
1734 CBA.write<
uint32_t>(*
Section.Header->NBuckets, ELFT::TargetEndianness);
1736 CBA.write<
uint32_t>(
Section.HashBuckets->size(), ELFT::TargetEndianness);
1744 if (
Section.Header->MaskWords)
1745 CBA.write<
uint32_t>(*
Section.Header->MaskWords, ELFT::TargetEndianness);
1747 CBA.write<
uint32_t>(
Section.BloomFilter->size(), ELFT::TargetEndianness);
1753 for (llvm::yaml::Hex64 Val : *
Section.BloomFilter)
1754 CBA.write<uintX_t>(Val, ELFT::TargetEndianness);
1757 for (llvm::yaml::Hex32 Val : *
Section.HashBuckets)
1758 CBA.write<
uint32_t>(Val, ELFT::TargetEndianness);
1761 for (llvm::yaml::Hex32 Val : *
Section.HashValues)
1762 CBA.write<
uint32_t>(Val, ELFT::TargetEndianness);
1764 SHeader.sh_size = 16 +
1765 Section.BloomFilter->size() *
sizeof(
typename ELFT::uint) +
1766 Section.HashBuckets->size() * 4 +
1767 Section.HashValues->size() * 4;
1770template <
class ELFT>
1772 ContiguousBlobAccumulator &CBA) {
1773 size_t PatternSize = Fill.
Pattern ? Fill.
Pattern->binary_size() : 0;
1775 CBA.writeZeros(Fill.
Size);
1781 for (; Written + PatternSize <= Fill.
Size; Written += PatternSize)
1782 CBA.writeAsBinary(*Fill.
Pattern);
1783 CBA.writeAsBinary(*Fill.
Pattern, Fill.
Size - Written);
1786template <
class ELFT>
1789 Doc.getSectionHeaderTable();
1799 if (!
Ret.try_emplace(Hdr.Name, ++SecNdx).second)
1800 reportError(
"repeated section name: '" + Hdr.Name +
1801 "' in the section header description");
1815 if (S == Doc.getSections().front())
1819 "' should be present in the 'Sections' or 'Excluded' lists");
1823 for (
const auto &It : Seen)
1824 reportError(
"section header contains undefined section '" + It.getKey() +
1829template <
class ELFT>
void ELFState<ELFT>::buildSectionIndex() {
1838 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
1840 Doc.getSectionHeaderTable();
1843 if (!ExcludedSectionHeaders.insert(Hdr.
Name).second)
1846 if (SectionHeaders.
NoHeaders.value_or(
false))
1848 if (!ExcludedSectionHeaders.insert(S->
Name).second)
1859 if (!ExcludedSectionHeaders.count(S->
Name))
1864template <
class ELFT>
void ELFState<ELFT>::buildSymbolIndexes() {
1866 for (
size_t I = 0, S =
V.size();
I < S; ++
I) {
1868 if (!
Sym.Name.empty() && !
Map.addName(
Sym.Name,
I + 1))
1874 Build(*Doc.Symbols, SymN2I);
1875 if (Doc.DynamicSymbols)
1876 Build(*Doc.DynamicSymbols, DynSymN2I);
1879template <
class ELFT>
void ELFState<ELFT>::finalizeStrings() {
1884 DotStrtab.finalize();
1887 if (Doc.DynamicSymbols)
1894 if (
auto VerNeed = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
1895 if (VerNeed->VerneedV) {
1897 DotDynstr.add(VE.
File);
1899 DotDynstr.add(Aux.
Name);
1902 }
else if (
auto VerDef = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
1903 if (VerDef->Entries)
1906 DotDynstr.add(
Name);
1910 DotDynstr.finalize();
1914 if (ShStrtabStrings != &DotStrtab && ShStrtabStrings != &DotDynstr)
1915 ShStrtabStrings->finalize();
1918template <
class ELFT>
1921 ELFState<ELFT> State(Doc, EH);
1927 State.buildSectionIndex();
1928 State.buildSymbolIndexes();
1933 State.finalizeStrings();
1938 std::vector<Elf_Phdr> PHeaders;
1939 State.initProgramHeaders(PHeaders);
1943 const size_t SectionContentBeginOffset =
1949 ContiguousBlobAccumulator CBA(SectionContentBeginOffset, MaxSize);
1951 std::vector<Elf_Shdr> SHeaders;
1952 State.initSectionHeaders(SHeaders, CBA);
1955 State.setProgramHeaderLayout(PHeaders, SHeaders);
1957 bool ReachedLimit = CBA.getOffset() > MaxSize;
1958 if (
Error E = CBA.takeLimitError()) {
1961 ReachedLimit =
true;
1966 "the desired output size is greater than permitted. Use the "
1967 "--max-size option to change the limit");
1972 State.writeELFHeader(
OS);
1977 CBA.updateDataAt(*SHT.
Offset, SHeaders.data(),
1980 CBA.writeBlobToStream(
OS);
1993 return ELFState<object::ELF64LE>::writeELF(Out, Doc, EH, MaxSize);
1994 return ELFState<object::ELF64BE>::writeELF(Out, Doc, EH, MaxSize);
1997 return ELFState<object::ELF32LE>::writeELF(Out, Doc, EH, MaxSize);
1998 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")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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).
constexpr bool empty() const
empty - Check if the string is empty.
char back() const
back - Get the last character in the string.
bool startswith(StringRef Prefix) const
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)
@ SHT_LLVM_CALL_GRAPH_PROFILE
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.
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 write(MCStreamer &Out, ArrayRef< std::string > Inputs, bool ContinueOnCuIndexOverflow)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
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...
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)
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< llvm::yaml::Hex64 > Offset
std::optional< yaml::BinaryRef > Pattern
unsigned getMachine() const
const SectionHeaderTable & getSectionHeaderTable() const
std::vector< ProgramHeader > ProgramHeaders
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
std::optional< std::vector< uint32_t > > Entries
std::vector< VernauxEntry > AuxV
Common declarations for yaml2obj.