42 StringMap<unsigned> Map;
46 bool addName(StringRef Name,
unsigned Ndx) {
47 return Map.insert({
Name, Ndx}).second;
50 bool lookup(StringRef Name,
unsigned &Idx)
const {
51 auto I = Map.find(Name);
58 unsigned get(StringRef Name)
const {
62 assert(
false &&
"Expected section not found in index");
65 unsigned size()
const {
return Map.size(); }
80template <
class ELFT>
class ELFState {
100 StringRef SectionHeaderStringTableName =
".shstrtab";
101 StringTableBuilder *ShStrtabStrings = &DotShStrtab;
105 NameToIdxMap DynSymN2I;
106 ELFYAML::Object &Doc;
108 std::vector<std::pair<Elf_Shdr *, ELFYAML::Section>>
109 SectionHeadersOverrideHelper;
111 StringSet<> ExcludedSectionHeaders;
113 uint64_t LocationCounter = 0;
114 bool HasError =
false;
120 const StringTableBuilder &Strtab);
121 unsigned toSectionIndex(StringRef S, StringRef LocSec, StringRef LocSym =
"");
122 unsigned toSymbolIndex(StringRef S, StringRef LocSec,
bool IsDynamic);
124 void buildSectionIndex();
125 void buildSymbolIndexes();
126 void initProgramHeaders(std::vector<Elf_Phdr> &PHeaders);
127 bool initImplicitHeader(ContiguousBlobAccumulator &CBA, Elf_Shdr &Header,
128 StringRef SecName, ELFYAML::Section *YAMLSec);
129 void initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
130 ContiguousBlobAccumulator &CBA);
131 void overrideSectionHeaders(std::vector<Elf_Shdr> &SHeaders);
132 void initSymtabSectionHeader(Elf_Shdr &SHeader, SymtabType STType,
133 ContiguousBlobAccumulator &CBA,
134 ELFYAML::Section *YAMLSec);
135 void initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
136 StringTableBuilder &STB,
137 ContiguousBlobAccumulator &CBA,
138 ELFYAML::Section *YAMLSec);
139 void initDWARFSectionHeader(Elf_Shdr &SHeader, StringRef Name,
140 ContiguousBlobAccumulator &CBA,
141 ELFYAML::Section *YAMLSec);
142 void setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
143 std::vector<Elf_Shdr> &SHeaders);
145 std::vector<Fragment>
146 getPhdrFragments(
const ELFYAML::ProgramHeader &Phdr,
149 void finalizeStrings();
150 void writeELFHeader(raw_ostream &OS);
151 void writeSectionContent(Elf_Shdr &SHeader,
152 const ELFYAML::NoBitsSection &Section,
153 ContiguousBlobAccumulator &CBA);
154 void writeSectionContent(Elf_Shdr &SHeader,
155 const ELFYAML::RawContentSection &Section,
156 ContiguousBlobAccumulator &CBA);
157 void writeSectionContent(Elf_Shdr &SHeader,
158 const ELFYAML::RelocationSection &Section,
159 ContiguousBlobAccumulator &CBA);
160 void writeSectionContent(Elf_Shdr &SHeader,
161 const ELFYAML::RelrSection &Section,
162 ContiguousBlobAccumulator &CBA);
163 void writeSectionContent(Elf_Shdr &SHeader,
164 const ELFYAML::GroupSection &Group,
165 ContiguousBlobAccumulator &CBA);
166 void writeSectionContent(Elf_Shdr &SHeader,
167 const ELFYAML::SymtabShndxSection &Shndx,
168 ContiguousBlobAccumulator &CBA);
169 void writeSectionContent(Elf_Shdr &SHeader,
170 const ELFYAML::SymverSection &Section,
171 ContiguousBlobAccumulator &CBA);
172 void writeSectionContent(Elf_Shdr &SHeader,
173 const ELFYAML::VerneedSection &Section,
174 ContiguousBlobAccumulator &CBA);
175 void writeSectionContent(Elf_Shdr &SHeader,
176 const ELFYAML::VerdefSection &Section,
177 ContiguousBlobAccumulator &CBA);
178 void writeSectionContent(Elf_Shdr &SHeader,
179 const ELFYAML::ARMIndexTableSection &Section,
180 ContiguousBlobAccumulator &CBA);
181 void writeSectionContent(Elf_Shdr &SHeader,
182 const ELFYAML::MipsABIFlags &Section,
183 ContiguousBlobAccumulator &CBA);
184 void writeSectionContent(Elf_Shdr &SHeader,
185 const ELFYAML::DynamicSection &Section,
186 ContiguousBlobAccumulator &CBA);
187 void writeSectionContent(Elf_Shdr &SHeader,
188 const ELFYAML::StackSizesSection &Section,
189 ContiguousBlobAccumulator &CBA);
190 void writeSectionContent(Elf_Shdr &SHeader,
191 const ELFYAML::BBAddrMapSection &Section,
192 ContiguousBlobAccumulator &CBA);
193 void writeSectionContent(Elf_Shdr &SHeader,
194 const ELFYAML::HashSection &Section,
195 ContiguousBlobAccumulator &CBA);
196 void writeSectionContent(Elf_Shdr &SHeader,
197 const ELFYAML::AddrsigSection &Section,
198 ContiguousBlobAccumulator &CBA);
199 void writeSectionContent(Elf_Shdr &SHeader,
200 const ELFYAML::NoteSection &Section,
201 ContiguousBlobAccumulator &CBA);
202 void writeSectionContent(Elf_Shdr &SHeader,
203 const ELFYAML::GnuHashSection &Section,
204 ContiguousBlobAccumulator &CBA);
205 void writeSectionContent(Elf_Shdr &SHeader,
206 const ELFYAML::LinkerOptionsSection &Section,
207 ContiguousBlobAccumulator &CBA);
208 void writeSectionContent(Elf_Shdr &SHeader,
209 const ELFYAML::DependentLibrariesSection &Section,
210 ContiguousBlobAccumulator &CBA);
211 void writeSectionContent(Elf_Shdr &SHeader,
212 const ELFYAML::CallGraphProfileSection &Section,
213 ContiguousBlobAccumulator &CBA);
215 void writeFill(ELFYAML::Fill &Fill, ContiguousBlobAccumulator &CBA);
219 void assignSectionAddress(Elf_Shdr &SHeader, ELFYAML::Section *YAMLSec);
221 DenseMap<StringRef, size_t> buildSectionHeaderReorderMap();
224 uint64_t alignToOffset(ContiguousBlobAccumulator &CBA, uint64_t Align,
225 std::optional<llvm::yaml::Hex64>
Offset);
227 uint64_t getSectionNameOffset(StringRef Name);
230 static bool writeELF(raw_ostream &OS, ELFYAML::Object &Doc,
236 return A.size() *
sizeof(
T);
243template <
class T>
static void zero(
T &Obj) { memset(&Obj, 0,
sizeof(Obj)); }
247 : Doc(
D), ErrHandler(EH) {
251 if (Doc.Header.SectionHeaderStringTable) {
252 SectionHeaderStringTableName = *Doc.Header.SectionHeaderStringTable;
253 if (*Doc.Header.SectionHeaderStringTable ==
".strtab")
254 ShStrtabStrings = &DotStrtab;
255 else if (*Doc.Header.SectionHeaderStringTable ==
".dynstr")
256 ShStrtabStrings = &DotDynstr;
260 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
265 std::make_unique<ELFYAML::Section>(
270 for (
size_t I = 0;
I < Doc.Chunks.size(); ++
I) {
271 const std::unique_ptr<ELFYAML::Chunk> &
C = Doc.Chunks[
I];
276 reportError(
"multiple section header tables are not allowed");
284 if (
C->Name.empty()) {
291 if (!DocSections.insert(
C->Name).second)
293 "' at YAML section/fill number " +
Twine(
I));
297 if (Doc.DynamicSymbols) {
298 if (SectionHeaderStringTableName ==
".dynsym")
299 reportError(
"cannot use '.dynsym' as the section header name table when "
300 "there are dynamic symbols");
301 ImplicitSections.insert(
".dynsym");
302 ImplicitSections.insert(
".dynstr");
305 if (SectionHeaderStringTableName ==
".symtab")
306 reportError(
"cannot use '.symtab' as the section header name table when "
307 "there are symbols");
308 ImplicitSections.insert(
".symtab");
311 for (
StringRef DebugSecName : Doc.DWARF->getNonEmptySectionNames()) {
312 std::string SecName = (
"." + DebugSecName).str();
315 if (SectionHeaderStringTableName == SecName)
316 reportError(
"cannot use '" + SecName +
317 "' as the section header name table when it is needed for "
319 ImplicitSections.insert(StringRef(SecName).copy(StringAlloc));
322 ImplicitSections.
insert(
".strtab");
323 if (!SecHdrTable || !SecHdrTable->NoHeaders.value_or(
false))
324 ImplicitSections.
insert(SectionHeaderStringTableName);
329 if (DocSections.count(SecName))
332 std::unique_ptr<ELFYAML::Section> Sec = std::make_unique<ELFYAML::Section>(
336 if (SecName == SectionHeaderStringTableName)
338 else if (SecName ==
".dynsym")
340 else if (SecName ==
".symtab")
350 if (Doc.Chunks.back().get() == SecHdrTable)
351 Doc.Chunks.insert(Doc.Chunks.end() - 1, std::move(Sec));
353 Doc.Chunks.push_back(std::move(Sec));
359 Doc.Chunks.push_back(
360 std::make_unique<ELFYAML::SectionHeaderTable>(
true));
364void ELFState<ELFT>::writeELFHeader(
raw_ostream &OS) {
369 Header.e_ident[
EI_MAG0] = 0x7f;
374 Header.e_ident[
EI_DATA] = Doc.Header.Data;
376 Header.e_ident[
EI_OSABI] = Doc.Header.OSABI;
378 Header.e_type = Doc.Header.Type;
380 if (Doc.Header.Machine)
381 Header.e_machine = *Doc.Header.Machine;
386 Header.e_entry = Doc.Header.Entry;
387 if (Doc.Header.Flags)
388 Header.e_flags = *Doc.Header.Flags;
392 Header.e_ehsize =
sizeof(Elf_Ehdr);
394 if (Doc.Header.EPhOff)
395 Header.e_phoff = *Doc.Header.EPhOff;
396 else if (!Doc.ProgramHeaders.empty())
397 Header.e_phoff =
sizeof(Header);
401 if (Doc.Header.EPhEntSize)
402 Header.e_phentsize = *Doc.Header.EPhEntSize;
403 else if (!Doc.ProgramHeaders.empty())
404 Header.e_phentsize =
sizeof(Elf_Phdr);
406 Header.e_phentsize = 0;
408 if (Doc.Header.EPhNum)
409 Header.e_phnum = *Doc.Header.EPhNum;
410 else if (!Doc.ProgramHeaders.empty())
411 Header.e_phnum = Doc.ProgramHeaders.size();
415 Header.e_shentsize = Doc.Header.EShEntSize ? (
uint16_t)*Doc.Header.EShEntSize
419 Doc.getSectionHeaderTable();
421 if (Doc.Header.EShOff)
422 Header.e_shoff = *Doc.Header.EShOff;
424 Header.e_shoff = *SectionHeaders.
Offset;
428 if (Doc.Header.EShNum)
429 Header.e_shnum = *Doc.Header.EShNum;
431 Header.e_shnum = SectionHeaders.
getNumHeaders(Doc.getSections().size());
433 if (Doc.Header.EShStrNdx)
434 Header.e_shstrndx = *Doc.Header.EShStrNdx;
436 !ExcludedSectionHeaders.count(SectionHeaderStringTableName))
437 Header.e_shstrndx = SN2I.get(SectionHeaderStringTableName);
439 Header.e_shstrndx = 0;
441 OS.
write((
const char *)&Header,
sizeof(Header));
445void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
447 for (
size_t I = 0,
E = Doc.Chunks.size();
I !=
E; ++
I) {
448 NameToIndex[Doc.Chunks[
I]->Name] =
I + 1;
451 for (
size_t I = 0,
E = Doc.ProgramHeaders.size();
I !=
E; ++
I) {
455 Phdr.p_type = YamlPhdr.
Type;
456 Phdr.p_flags = YamlPhdr.
Flags;
457 Phdr.p_vaddr = YamlPhdr.
VAddr;
458 Phdr.p_paddr = YamlPhdr.
PAddr;
459 PHeaders.push_back(Phdr);
468 "' by the 'FirstSec' key of the program header with index " +
473 "' by the 'LastSec' key of the program header with index " +
480 ": the section index of " + *YamlPhdr.
FirstSec +
481 " is greater than the index of " + *YamlPhdr.
LastSec);
484 YamlPhdr.
Chunks.push_back(Doc.Chunks[
I - 1].get());
494 if (!SN2I.lookup(S, Index) && !
to_integer(S, Index)) {
496 reportError(
"unknown section referenced: '" + S +
"' by YAML symbol '" +
499 reportError(
"unknown section referenced: '" + S +
"' by YAML section '" +
505 Doc.getSectionHeaderTable();
512 size_t FirstExcluded =
514 if (Index > FirstExcluded) {
516 reportError(
"unable to link '" + LocSec +
"' to excluded section '" + S +
519 reportError(
"excluded section referenced: '" + S +
"' by symbol '" +
528 const NameToIdxMap &
SymMap = IsDynamic ? DynSymN2I : SymN2I;
533 reportError(
"unknown symbol referenced: '" + S +
"' by YAML section '" +
549 To.sh_name = *From->
ShName;
553 To.sh_size = *From->
ShSize;
555 To.sh_type = *From->
ShType;
563 if (Header.sh_offset)
566 if (SecName ==
".strtab")
567 initStrtabSectionHeader(Header, SecName, DotStrtab, CBA, YAMLSec);
568 else if (SecName ==
".dynstr")
569 initStrtabSectionHeader(Header, SecName, DotDynstr, CBA, YAMLSec);
570 else if (SecName == SectionHeaderStringTableName)
571 initStrtabSectionHeader(Header, SecName, *ShStrtabStrings, CBA, YAMLSec);
572 else if (SecName ==
".symtab")
573 initSymtabSectionHeader(Header, SymtabType::Static, CBA, YAMLSec);
574 else if (SecName ==
".dynsym")
575 initSymtabSectionHeader(Header, SymtabType::Dynamic, CBA, YAMLSec);
581 initDWARFSectionHeader(Header, SecName, CBA, YAMLSec);
585 LocationCounter += Header.sh_size;
598 std::string Ret = Name.empty() ?
"" : Name.str() +
' ';
613 return S.
substr(0, SuffixPos - 1);
620 if (ExcludedSectionHeaders.count(Name))
622 return ShStrtabStrings->getOffset(Name);
626 const std::optional<yaml::BinaryRef> &Content,
627 const std::optional<llvm::yaml::Hex64> &
Size) {
628 size_t ContentSize = 0;
631 ContentSize = Content->binary_size();
665void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
669 SHeaders.resize(Doc.getSections().size());
671 for (
const std::unique_ptr<ELFYAML::Chunk> &
D : Doc.Chunks) {
673 S->Offset = alignToOffset(CBA, 1, S->Offset);
675 LocationCounter += S->Size;
681 if (S->NoHeaders.value_or(
false))
685 S->Offset = alignToOffset(CBA,
sizeof(
typename ELFT::uint),
688 S->Offset = alignToOffset(CBA, 1, S->Offset);
690 uint64_t Size = S->getNumHeaders(SHeaders.size()) *
sizeof(Elf_Shdr);
694 LocationCounter +=
Size;
699 bool IsFirstUndefSection = Sec == Doc.getSections().front();
703 Elf_Shdr &SHeader = SHeaders[SN2I.get(Sec->
Name)];
705 SHeader.sh_link = toSectionIndex(*Sec->
Link, Sec->
Name);
709 if (!LinkSec.
empty() && !ExcludedSectionHeaders.count(LinkSec) &&
710 SN2I.lookup(LinkSec, Link))
711 SHeader.sh_link = Link;
715 SHeader.sh_entsize = *Sec->
EntSize;
724 if (initImplicitHeader(CBA, SHeader, Sec->
Name,
728 assert(Sec &&
"It can't be null unless it is an implicit section. But all "
729 "implicit sections should already have been handled above.");
733 SHeader.sh_type = Sec->
Type;
735 SHeader.sh_flags = *Sec->
Flags;
740 if (!IsFirstUndefSection || Sec->
Offset)
741 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, Sec->
Offset);
743 assignSectionAddress(SHeader, Sec);
745 if (IsFirstUndefSection) {
749 SHeader.sh_size = *RawSec->Size;
751 SHeader.sh_info = *RawSec->Info;
754 LocationCounter += SHeader.sh_size;
755 SectionHeadersOverrideHelper.push_back({&SHeader, *Sec});
763 writeSectionContent(SHeader, *S, CBA);
765 writeSectionContent(SHeader, *S, CBA);
767 writeSectionContent(SHeader, *S, CBA);
769 writeSectionContent(SHeader, *S, CBA);
771 writeSectionContent(SHeader, *S, CBA);
773 writeSectionContent(SHeader, *S, CBA);
775 writeSectionContent(SHeader, *S, CBA);
777 writeSectionContent(SHeader, *S, CBA);
779 writeSectionContent(SHeader, *S, CBA);
781 writeSectionContent(SHeader, *S, CBA);
783 writeSectionContent(SHeader, *S, CBA);
785 writeSectionContent(SHeader, *S, CBA);
787 writeSectionContent(SHeader, *S, CBA);
789 writeSectionContent(SHeader, *S, CBA);
791 writeSectionContent(SHeader, *S, CBA);
793 writeSectionContent(SHeader, *S, CBA);
795 writeSectionContent(SHeader, *S, CBA);
797 writeSectionContent(SHeader, *S, CBA);
799 writeSectionContent(SHeader, *S, CBA);
801 writeSectionContent(SHeader, *S, CBA);
803 writeSectionContent(SHeader, *S, CBA);
808 LocationCounter += SHeader.sh_size;
809 SectionHeadersOverrideHelper.push_back({&SHeader, *Sec});
814void ELFState<ELFT>::overrideSectionHeaders(std::vector<Elf_Shdr> &SHeaders) {
815 for (std::pair<Elf_Shdr *, ELFYAML::Section> &HeaderAndSec :
816 SectionHeadersOverrideHelper)
821void ELFState<ELFT>::assignSectionAddress(Elf_Shdr &SHeader,
823 if (YAMLSec && YAMLSec->
Address) {
824 SHeader.sh_addr = *YAMLSec->
Address;
825 LocationCounter = *YAMLSec->
Address;
837 alignTo(LocationCounter, SHeader.sh_addralign ? SHeader.sh_addralign : 1);
838 SHeader.sh_addr = LocationCounter;
842 for (
size_t I = 0;
I < Symbols.size(); ++
I)
845 return Symbols.size();
849std::vector<typename ELFT::Sym>
852 std::vector<Elf_Sym> Ret;
853 Ret.resize(
Symbols.size() + 1);
857 Elf_Sym &Symbol = Ret[++
I];
863 Symbol.st_name = *Sym.StName;
864 else if (!Sym.Name.empty())
867 Symbol.setBindingAndType(Sym.Binding, Sym.Type);
869 Symbol.st_shndx = toSectionIndex(*Sym.Section,
"", Sym.Name);
871 Symbol.st_shndx = *Sym.Index;
873 Symbol.st_value = Sym.Value.value_or(yaml::Hex64(0));
874 Symbol.st_other = Sym.Other.value_or(0);
875 Symbol.st_size = Sym.Size.value_or(yaml::Hex64(0));
882void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
887 bool IsStatic = STType == SymtabType::Static;
889 if (IsStatic && Doc.Symbols)
891 else if (!IsStatic && Doc.DynamicSymbols)
897 bool HasSymbolsDescription =
898 (IsStatic && Doc.Symbols) || (!IsStatic && Doc.DynamicSymbols);
899 if (HasSymbolsDescription) {
902 reportError(
"cannot specify both `Content` and " + Property +
903 " for symbol table section '" + RawSec->
Name +
"'");
905 reportError(
"cannot specify both `Size` and " + Property +
906 " for symbol table section '" + RawSec->
Name +
"'");
911 SHeader.sh_name = getSectionNameOffset(IsStatic ?
".symtab" :
".dynsym");
914 SHeader.sh_type = YAMLSec->
Type;
918 if (YAMLSec && YAMLSec->
Flags)
919 SHeader.sh_flags = *YAMLSec->
Flags;
925 SHeader.sh_info = (RawSec && RawSec->
Info) ? (
unsigned)(*RawSec->
Info)
929 assignSectionAddress(SHeader, YAMLSec);
931 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
932 RawSec ? RawSec->
Offset : std::nullopt);
940 std::vector<Elf_Sym> Syms =
941 toELFSymbols(Symbols, IsStatic ? DotStrtab : DotDynstr);
942 SHeader.sh_size = Syms.size() *
sizeof(Elf_Sym);
943 CBA.
write((
const char *)Syms.data(), SHeader.sh_size);
947void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
958 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
959 YAMLSec ? YAMLSec->
Offset : std::nullopt);
966 SHeader.sh_size = STB.
getSize();
969 if (RawSec && RawSec->
Info)
970 SHeader.sh_info = *RawSec->
Info;
972 if (YAMLSec && YAMLSec->
Flags)
973 SHeader.sh_flags = *YAMLSec->
Flags;
974 else if (Name ==
".dynstr")
977 assignSectionAddress(SHeader, YAMLSec);
982 return Name.consume_front(
".") && DebugSecNames.
count(Name);
999 if (
Error Err = EmitFunc(*OS, DWARF))
1000 return std::move(Err);
1002 return CBA.
tell() - BeginOffset;
1005template <
class ELFT>
1006void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader,
StringRef Name,
1012 SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
1013 YAMLSec ? YAMLSec->
Offset : std::nullopt);
1020 "' contents in the 'DWARF' entry and the 'Content' "
1021 "or 'Size' in the 'Sections' entry at the same time");
1025 SHeader.sh_size = *ShSizeOrErr;
1033 "entry or a RawContentSection");
1035 if (RawSec && RawSec->
Info)
1036 SHeader.sh_info = *RawSec->
Info;
1038 if (YAMLSec && YAMLSec->
Flags)
1039 SHeader.sh_flags = *YAMLSec->
Flags;
1040 else if (Name ==
".debug_str")
1043 assignSectionAddress(SHeader, YAMLSec);
1046template <
class ELFT>
void ELFState<ELFT>::reportError(
const Twine &
Msg) {
1051template <
class ELFT>
void ELFState<ELFT>::reportError(
Error Err) {
1057template <
class ELFT>
1058std::vector<Fragment>
1061 std::vector<Fragment> Ret;
1070 const Elf_Shdr &
H = SHeaders[SN2I.get(S->
Name)];
1071 Ret.push_back({
H.sh_offset,
H.sh_size,
H.sh_type,
H.sh_addralign});
1076template <
class ELFT>
1077void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
1078 std::vector<Elf_Shdr> &SHeaders) {
1080 for (
auto &YamlPhdr : Doc.ProgramHeaders) {
1081 Elf_Phdr &PHeader = PHeaders[PhdrIdx++];
1082 std::vector<Fragment> Fragments = getPhdrFragments(YamlPhdr, SHeaders);
1084 return A.Offset <
B.Offset;
1086 reportError(
"sections in the program header with index " +
1087 Twine(PhdrIdx) +
" are not sorted by their file offset");
1090 if (!Fragments.empty() && *YamlPhdr.
Offset > Fragments.front().Offset)
1092 " must be less than or equal to the minimum file offset of "
1093 "all included sections (0x" +
1095 PHeader.p_offset = *YamlPhdr.
Offset;
1096 }
else if (!Fragments.empty()) {
1097 PHeader.p_offset = Fragments.front().Offset;
1102 PHeader.p_filesz = *YamlPhdr.
FileSize;
1103 }
else if (!Fragments.empty()) {
1104 uint64_t FileSize = Fragments.back().Offset - PHeader.p_offset;
1109 FileSize += Fragments.back().Size;
1110 PHeader.p_filesz = FileSize;
1114 uint64_t MemOffset = PHeader.p_offset;
1115 for (
const Fragment &
F : Fragments)
1116 MemOffset = std::max(MemOffset,
F.Offset +
F.Size);
1119 : MemOffset - PHeader.p_offset;
1121 if (YamlPhdr.
Align) {
1122 PHeader.p_align = *YamlPhdr.
Align;
1127 PHeader.p_align = 1;
1128 for (
const Fragment &
F : Fragments)
1129 PHeader.p_align = std::max((
uint64_t)PHeader.p_align,
F.AddrAlign);
1140 return (isa<ELFYAML::Fill>(C) ||
1141 cast<ELFYAML::Section>(C)->Type != ELF::SHT_NOBITS);
1148template <
class ELFT>
1149void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1155 SHeader.sh_size = *S.
Size;
1160 if (shouldAllocateFileSpace(Doc.ProgramHeaders, S))
1164template <
class ELFT>
1165void ELFState<ELFT>::writeSectionContent(
1169 SHeader.sh_info = *Section.Info;
1178template <
class ELFT>
1179void ELFState<ELFT>::writeSectionContent(
1185 "Section type is not SHT_REL nor SHT_RELA");
1187 if (!
Section.RelocatableSec.empty())
1188 SHeader.sh_info = toSectionIndex(
Section.RelocatableSec,
Section.Name);
1195 typename ELFT::uint OffsetMask = 8,
Offset = 0, Addend = 0;
1200 OffsetMask |= Rel.
Offset;
1206 const bool IsDynamic =
Section.Link && (*
Section.Link ==
".dynsym");
1214 (
static_cast<typename ELFT::uint
>(Rel.
Offset) -
Offset) >> Shift;
1217 DeltaOffset * 8 + (SymIdx != CurSymIdx) + (
Type != Rel.
Type ? 2 : 0) +
1218 (Addend !=
static_cast<typename ELFT::uint
>(Rel.
Addend) ? 4 : 0);
1219 if (DeltaOffset < 0x10) {
1228 std::make_signed_t<typename ELFT::uint>(CurSymIdx - SymIdx));
1237 std::make_signed_t<typename ELFT::uint>(Rel.
Addend - Addend));
1240 }
else if (IsRela) {
1243 REntry.r_offset = Rel.
Offset;
1244 REntry.r_addend = Rel.
Addend;
1246 CBA.
write((
const char *)&REntry,
sizeof(REntry));
1250 REntry.r_offset = Rel.
Offset;
1252 CBA.
write((
const char *)&REntry,
sizeof(REntry));
1256 SHeader.sh_size = CBA.
getOffset() - CurrentOffset;
1259template <
class ELFT>
1260void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1266 for (llvm::yaml::Hex64
E : *
Section.Entries) {
1267 if (!ELFT::Is64Bits &&
E > UINT32_MAX)
1270 CBA.
write<uintX_t>(
E, ELFT::Endianness);
1273 SHeader.sh_size =
sizeof(uintX_t) *
Section.Entries->size();
1276template <
class ELFT>
1277void ELFState<ELFT>::writeSectionContent(
1290 SHeader.sh_size = Shndx.
Entries->size() * SHeader.sh_entsize;
1293template <
class ELFT>
1294void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1298 "Section type is not SHT_GROUP");
1308 unsigned int SectionIndex = 0;
1309 if (
Member.sectionNameOrType ==
"GRP_COMDAT")
1312 SectionIndex = toSectionIndex(
Member.sectionNameOrType,
Section.Name);
1315 SHeader.sh_size = SHeader.sh_entsize *
Section.Members->size();
1318template <
class ELFT>
1319void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1327 SHeader.sh_size =
Section.Entries->size() * SHeader.sh_entsize;
1330template <
class ELFT>
1331void ELFState<ELFT>::writeSectionContent(
1338 CBA.
write<uintX_t>(
E.Address, ELFT::Endianness);
1339 SHeader.sh_size +=
sizeof(uintX_t) + CBA.
writeULEB128(
E.Size);
1343template <
class ELFT>
1344void ELFState<ELFT>::writeSectionContent(
1350 <<
"PGOAnalyses should not exist in SHT_LLVM_BB_ADDR_MAP when "
1351 "Entries does not exist";
1355 const std::vector<BBAddrMapYAML::PGOAnalysisMapEntry> *PGOAnalyses =
nullptr;
1359 "in SHT_LLVM_BB_ADDR_MAP";
1361 PGOAnalyses = &
Section.PGOAnalyses.value();
1369 <<
static_cast<int>(
E.Version)
1370 <<
"; encoding using the most recent version";
1377 if (!FeatureOrErr) {
1382 bool MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
1384 MultiBBRangeFeatureEnabled ||
1385 (
E.NumBBRanges.has_value() &&
E.NumBBRanges.value() != 1) ||
1386 (
E.BBRanges &&
E.BBRanges->size() != 1);
1387 if (MultiBBRange && !MultiBBRangeFeatureEnabled)
1389 <<
") does not support multiple BB ranges.";
1394 E.NumBBRanges.value_or(
E.BBRanges ?
E.BBRanges->size() : 0);
1400 bool EmitCallsiteEndOffsets =
1401 FeatureOrErr->CallsiteEndOffsets ||
E.hasAnyCallsiteEndOffsets();
1412 if (!BBR.
BBEntries || FeatureOrErr->OmitBBEntries)
1419 if (EmitCallsiteEndOffsets) {
1420 size_t NumCallsiteEndOffsets =
1430 if (FeatureOrErr->BBHash || BBE.
Hash.has_value()) {
1432 BBE.
Hash.has_value() ? BBE.
Hash.value() : llvm::yaml::Hex64(0);
1447 const auto &PGOBBEntries = PGOEntry.
PGOBBEntries.value();
1448 if (TotalNumBlocks != PGOBBEntries.size()) {
1450 "BBEntries in the BB address map.\n"
1451 <<
"Mismatch on function with address: "
1452 <<
E.getFunctionAddress();
1456 for (
const auto &PGOBBE : PGOBBEntries) {
1459 if (FeatureOrErr->PostLinkCfg || PGOBBE.PostLinkBBFreq.has_value())
1461 if (PGOBBE.Successors) {
1463 for (
const auto &[
ID,
BrProb, PostLinkBrFreq] : *PGOBBE.Successors) {
1466 if (FeatureOrErr->PostLinkCfg || PostLinkBrFreq.has_value())
1472 SHeader.sh_size += CBA.
getOffset() - CurrentOffset;
1475template <
class ELFT>
1476void ELFState<ELFT>::writeSectionContent(
1483 CBA.
write(
LO.Key.data(),
LO.Key.size());
1485 CBA.
write(
LO.Value.data(),
LO.Value.size());
1487 SHeader.sh_size += (
LO.Key.size() +
LO.Value.size() + 2);
1491template <
class ELFT>
1492void ELFState<ELFT>::writeSectionContent(
1501 SHeader.sh_size +=
Lib.size() + 1;
1505template <
class ELFT>
1508 std::optional<llvm::yaml::Hex64>
Offset) {
1516 return CurrentOffset;
1525 CBA.
writeZeros(AlignedOffset - CurrentOffset);
1526 return AlignedOffset;
1529template <
class ELFT>
1530void ELFState<ELFT>::writeSectionContent(
1542template <
class ELFT>
1543void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1550 Section.NBucket.value_or(llvm::yaml::Hex64(
Section.Bucket->size())),
1553 Section.NChain.value_or(llvm::yaml::Hex64(
Section.Chain->size())),
1561 SHeader.sh_size = (2 +
Section.Bucket->size() +
Section.Chain->size()) * 4;
1564template <
class ELFT>
1565void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1570 SHeader.sh_info = *
Section.Info;
1572 SHeader.sh_info =
Section.Entries->size();
1578 for (
size_t I = 0;
I <
Section.Entries->size(); ++
I) {
1582 VerDef.vd_version =
E.Version.value_or(1);
1583 VerDef.vd_flags =
E.Flags.value_or(0);
1584 VerDef.vd_ndx =
E.VersionNdx.value_or(0);
1585 VerDef.vd_hash =
E.Hash.value_or(0);
1586 VerDef.vd_aux =
E.VDAux.value_or(
sizeof(Elf_Verdef));
1587 VerDef.vd_cnt =
E.VerNames.size();
1588 if (
I ==
Section.Entries->size() - 1)
1592 sizeof(Elf_Verdef) +
E.VerNames.size() *
sizeof(Elf_Verdaux);
1593 CBA.
write((
const char *)&VerDef,
sizeof(Elf_Verdef));
1595 for (
size_t J = 0; J <
E.VerNames.size(); ++J, ++AuxCnt) {
1596 Elf_Verdaux VerdAux;
1597 VerdAux.vda_name = DotDynstr.getOffset(
E.VerNames[J]);
1598 if (J ==
E.VerNames.size() - 1)
1599 VerdAux.vda_next = 0;
1601 VerdAux.vda_next =
sizeof(Elf_Verdaux);
1602 CBA.
write((
const char *)&VerdAux,
sizeof(Elf_Verdaux));
1606 SHeader.sh_size =
Section.Entries->size() *
sizeof(Elf_Verdef) +
1607 AuxCnt *
sizeof(Elf_Verdaux);
1610template <
class ELFT>
1611void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1615 SHeader.sh_info = *
Section.Info;
1617 SHeader.sh_info =
Section.VerneedV->size();
1623 for (
size_t I = 0;
I <
Section.VerneedV->size(); ++
I) {
1626 Elf_Verneed VerNeed;
1627 VerNeed.vn_version =
VE.Version;
1628 VerNeed.vn_file = DotDynstr.getOffset(
VE.File);
1629 if (
I ==
Section.VerneedV->size() - 1)
1630 VerNeed.vn_next = 0;
1633 sizeof(Elf_Verneed) +
VE.AuxV.size() *
sizeof(Elf_Vernaux);
1634 VerNeed.vn_cnt =
VE.AuxV.size();
1635 VerNeed.vn_aux =
sizeof(Elf_Verneed);
1636 CBA.
write((
const char *)&VerNeed,
sizeof(Elf_Verneed));
1638 for (
size_t J = 0; J <
VE.AuxV.size(); ++J, ++AuxCnt) {
1641 Elf_Vernaux VernAux;
1642 VernAux.vna_hash = VAuxE.
Hash;
1643 VernAux.vna_flags = VAuxE.
Flags;
1644 VernAux.vna_other = VAuxE.
Other;
1645 VernAux.vna_name = DotDynstr.getOffset(VAuxE.
Name);
1646 if (J ==
VE.AuxV.size() - 1)
1647 VernAux.vna_next = 0;
1649 VernAux.vna_next =
sizeof(Elf_Vernaux);
1650 CBA.
write((
const char *)&VernAux,
sizeof(Elf_Vernaux));
1654 SHeader.sh_size =
Section.VerneedV->size() *
sizeof(Elf_Verneed) +
1655 AuxCnt *
sizeof(Elf_Vernaux);
1658template <
class ELFT>
1659void ELFState<ELFT>::writeSectionContent(
1669 SHeader.sh_size =
Section.Entries->size() * 8;
1672template <
class ELFT>
1673void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1677 "Section type is not SHT_MIPS_ABIFLAGS");
1681 SHeader.sh_size = SHeader.sh_entsize;
1683 Flags.version =
Section.Version;
1684 Flags.isa_level =
Section.ISALevel;
1685 Flags.isa_rev =
Section.ISARevision;
1686 Flags.gpr_size =
Section.GPRSize;
1687 Flags.cpr1_size =
Section.CPR1Size;
1688 Flags.cpr2_size =
Section.CPR2Size;
1690 Flags.isa_ext =
Section.ISAExtension;
1692 Flags.flags1 =
Section.Flags1;
1693 Flags.flags2 =
Section.Flags2;
1694 CBA.
write((
const char *)&Flags,
sizeof(Flags));
1697template <
class ELFT>
1698void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1702 "Section type is not SHT_DYNAMIC");
1708 CBA.
write<uintX_t>(DE.
Tag, ELFT::Endianness);
1709 CBA.
write<uintX_t>(DE.
Val, ELFT::Endianness);
1711 SHeader.sh_size = 2 *
sizeof(uintX_t) *
Section.Entries->size();
1714template <
class ELFT>
1715void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1726template <
class ELFT>
1727void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1734 switch (
Section.AddressAlign) {
1758 if (
NE.Name.empty())
1764 if (
NE.Desc.binary_size() == 0)
1773 if (!
NE.Name.empty()) {
1774 CBA.
write(
NE.Name.data(),
NE.Name.size());
1779 if (
NE.Desc.binary_size() != 0) {
1790template <
class ELFT>
1791void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
1815 if (
Section.Header->MaskWords)
1824 for (llvm::yaml::Hex64 Val : *
Section.BloomFilter)
1825 CBA.
write<uintX_t>(Val, ELFT::Endianness);
1828 for (llvm::yaml::Hex32 Val : *
Section.HashBuckets)
1832 for (llvm::yaml::Hex32 Val : *
Section.HashValues)
1835 SHeader.sh_size = 16 +
1836 Section.BloomFilter->size() *
sizeof(
typename ELFT::uint) +
1837 Section.HashBuckets->size() * 4 +
1838 Section.HashValues->size() * 4;
1841template <
class ELFT>
1844 size_t PatternSize = Fill.
Pattern ? Fill.
Pattern->binary_size() : 0;
1852 for (; Written + PatternSize <= Fill.
Size; Written += PatternSize)
1857template <
class ELFT>
1860 Doc.getSectionHeaderTable();
1871 reportError(
"repeated section name: '" + Hdr.Name +
1872 "' in the section header description");
1886 if (S == Doc.getSections().front())
1890 "' should be present in the 'Sections' or 'Excluded' lists");
1894 for (
const auto &It : Seen)
1895 reportError(
"section header contains undefined section '" + It.getKey() +
1900template <
class ELFT>
void ELFState<ELFT>::buildSectionIndex() {
1909 std::vector<ELFYAML::Section *> Sections = Doc.getSections();
1911 Doc.getSectionHeaderTable();
1914 if (!ExcludedSectionHeaders.insert(Hdr.
Name).second)
1917 if (SectionHeaders.
NoHeaders.value_or(
false))
1919 if (!ExcludedSectionHeaders.insert(S->
Name).second)
1926 size_t Index = ReorderMap.
empty() ? SecNdx : ReorderMap.
lookup(S->
Name);
1927 if (!SN2I.addName(S->
Name, Index))
1930 if (!ExcludedSectionHeaders.count(S->
Name))
1935template <
class ELFT>
void ELFState<ELFT>::buildSymbolIndexes() {
1937 for (
size_t I = 0, S = V.size();
I < S; ++
I) {
1945 Build(*Doc.Symbols, SymN2I);
1946 if (Doc.DynamicSymbols)
1947 Build(*Doc.DynamicSymbols, DynSymN2I);
1950template <
class ELFT>
void ELFState<ELFT>::finalizeStrings() {
1955 DotStrtab.finalize();
1958 if (Doc.DynamicSymbols)
1966 if (VerNeed->VerneedV) {
1968 DotDynstr.add(
VE.File);
1970 DotDynstr.add(Aux.
Name);
1974 if (VerDef->Entries)
1977 DotDynstr.add(Name);
1981 DotDynstr.finalize();
1985 if (ShStrtabStrings != &DotStrtab && ShStrtabStrings != &DotDynstr)
1986 ShStrtabStrings->finalize();
1989template <
class ELFT>
1992 ELFState<ELFT> State(Doc, EH);
1998 State.buildSectionIndex();
1999 State.buildSymbolIndexes();
2004 State.finalizeStrings();
2009 std::vector<Elf_Phdr> PHeaders;
2010 State.initProgramHeaders(PHeaders);
2014 const size_t SectionContentBeginOffset =
2022 std::vector<Elf_Shdr> SHeaders;
2023 State.initSectionHeaders(SHeaders, CBA);
2026 State.setProgramHeaderLayout(PHeaders, SHeaders);
2031 State.overrideSectionHeaders(SHeaders);
2033 bool ReachedLimit = CBA.
getOffset() > MaxSize;
2037 ReachedLimit =
true;
2042 "the desired output size is greater than permitted. Use the "
2043 "--max-size option to change the limit");
2048 State.writeELFHeader(OS);
2069 return ELFState<object::ELF64LE>::writeELF(Out, Doc, EH, MaxSize);
2070 return ELFState<object::ELF64BE>::writeELF(Out, Doc, EH, MaxSize);
2073 return ELFState<object::ELF32LE>::writeELF(Out, Doc, EH, MaxSize);
2074 return ELFState<object::ELF32BE>::writeELF(Out, Doc, EH, MaxSize);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Error reportError(StringRef Message)
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")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines ContiguousBlobAccumulator, the size-limited output buffer shared by the yaml2obj em...
Common declarations for yaml2obj.
This file declares classes for handling the YAML representation of DWARF Debug Info.
DXIL Resource Implicit Binding
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 bool lookup(const GsymReader &GR, GsymDataExtractor &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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
A vector that has set insertion semantics.
size_type count(const_arg_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.
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Represent a constant reference to a string, i.e.
static constexpr size_t npos
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
Check if the string is empty.
char back() const
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
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(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.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
LLVM_ABI uint64_t padToAlignment(unsigned Align)
LLVM_ABI unsigned writeSLEB128(int64_t Val)
LLVM_ABI void writeAsBinary(const BinaryRef &Bin, uint64_t N=UINT64_MAX)
void writeBlobToStream(raw_ostream &Out) const
void write(const char *Ptr, size_t Size)
uint64_t getOffset() const
void writeZeros(uint64_t Num)
LLVM_ABI unsigned writeULEB128(uint64_t Val)
raw_ostream * getRawOS(uint64_t Size)
LLVM_ABI void updateDataAt(uint64_t Pos, const void *Data, size_t Size)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI std::function< Error(raw_ostream &, const Data &)> getDWARFEmitterByName(StringRef SecName)
LLVM_ABI std::string appendUniqueSuffix(StringRef Name, const Twine &Msg)
unsigned getDefaultShEntSize(unsigned EMachine, ELF_SHT SecType, StringRef SecName)
LLVM_ABI StringRef dropUniqueSuffix(StringRef S)
LLVM_ABI bool shouldAllocateFileSpace(ArrayRef< ProgramHeader > Phdrs, const NoBitsSection &S)
@ SHT_LLVM_CALL_GRAPH_PROFILE
constexpr unsigned CREL_HDR_ADDEND
LLVM_ABI bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH, uint64_t MaxSize)
llvm::function_ref< void(const Twine &Msg)> ErrorHandler
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,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
auto dyn_cast_or_null(const Y &Val)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ Dynamic
Denotes mode unknown at compile time.
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
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::yaml::Hex64 Metadata
std::optional< std::vector< llvm::yaml::Hex64 > > CallsiteEndOffsets
std::optional< llvm::yaml::Hex64 > Hash
llvm::yaml::Hex64 AddressOffset
std::optional< std::vector< BBEntry > > BBEntries
std::optional< uint64_t > NumBlocks
llvm::yaml::Hex64 BaseAddress
std::optional< uint64_t > FuncEntryCount
std::optional< std::vector< PGOBBEntry > > PGOBBEntries
LLVM_ABI SetVector< StringRef > getNonEmptySectionNames() const
std::optional< llvm::yaml::Hex64 > Offset
std::optional< yaml::BinaryRef > Pattern
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
std::optional< llvm::yaml::Hex64 > ShAddrAlign
llvm::yaml::Hex64 AddressAlign
std::optional< ELF_SHF > Flags
std::optional< ELF_SHT > ShType
std::optional< llvm::yaml::Hex64 > ShOffset
std::optional< llvm::yaml::Hex64 > ShFlags
std::optional< llvm::yaml::Hex64 > ShName
std::optional< yaml::BinaryRef > Content
std::optional< llvm::yaml::Hex64 > EntSize
std::optional< llvm::yaml::Hex64 > ShSize
std::optional< std::vector< uint32_t > > Entries
static Expected< Features > decode(uint16_t Val)
Common declarations for yaml2obj.