17 #include "llvm/Config/llvm-config.h" 38 #define DEBUG_TYPE "mc" 44 static const uint32_t kInitialTableOffset = 1;
49 struct SectionBookkeeping {
53 uint64_t PayloadOffset;
55 uint64_t ContentsOffset;
61 struct WasmFunctionType {
63 enum { Plain,
Empty, Tombstone } State;
71 WasmFunctionType() : State(Plain) {}
74 return State == Other.State && Returns == Other.Returns &&
75 Params == Other.Params;
80 struct WasmFunctionTypeDenseMapInfo {
81 static WasmFunctionType getEmptyKey() {
82 WasmFunctionType FuncTy;
86 static WasmFunctionType getTombstoneKey() {
87 WasmFunctionType FuncTy;
88 FuncTy.State = WasmFunctionType::Tombstone;
91 static unsigned getHashValue(
const WasmFunctionType &FuncTy) {
92 uintptr_t
Value = FuncTy.State;
99 static bool isEqual(
const WasmFunctionType &LHS,
100 const WasmFunctionType &RHS) {
109 struct WasmDataSegment {
119 struct WasmFunction {
127 uint64_t InitialValue;
133 struct WasmComdatEntry {
139 struct WasmRelocationEntry {
146 WasmRelocationEntry(uint64_t Offset,
const MCSymbolWasm *Symbol,
147 int64_t Addend,
unsigned Type,
150 FixupSection(FixupSection) {}
152 bool hasAddend()
const {
154 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
155 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
156 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
157 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
158 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
167 <<
" Off=" << Offset <<
", Sym=" << *Symbol <<
", Addend=" << Addend
171 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 176 static const uint32_t INVALID_INDEX = -1;
178 struct WasmCustomSection {
187 :
Name(Name),
Section(Section), OutputContentsOffset(0),
188 OutputIndex(INVALID_INDEX) {}
202 std::unique_ptr<MCWasmObjectTargetWriter> TargetObjectWriter;
205 std::vector<WasmRelocationEntry> CodeRelocations;
209 std::vector<WasmRelocationEntry> DataRelocations;
225 std::vector<WasmCustomSection> CustomSections;
228 CustomSectionsRelocations;
238 unsigned NumFunctionImports = 0;
239 unsigned NumGlobalImports = 0;
243 bool is64Bit()
const {
return TargetObjectWriter->is64Bit(); }
245 return TargetObjectWriter->getRelocType(Target, Fixup);
248 void startSection(SectionBookkeeping &
Section,
unsigned SectionId);
249 void startCustomSection(SectionBookkeeping &Section,
StringRef Name);
250 void endSection(SectionBookkeeping &Section);
253 WasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
257 ~WasmObjectWriter()
override;
260 void reset()
override {
261 CodeRelocations.clear();
262 DataRelocations.clear();
265 TableIndices.
clear();
266 DataLocations.
clear();
267 CustomSectionsRelocations.
clear();
268 FunctionTypeIndices.
clear();
269 FunctionTypes.
clear();
271 DataSegments.
clear();
272 SectionFunctions.
clear();
273 NumFunctionImports = 0;
274 NumGlobalImports = 0;
282 MCValue Target, uint64_t &FixedValue)
override;
295 W.
OS <<
static_cast<char>(Ty);
302 void writeGlobalSection();
307 void writeDataSection();
310 void writeLinkingMetaDataSection(
312 ArrayRef<std::pair<uint16_t, uint32_t>> InitFuncs,
313 const std::map<
StringRef, std::vector<WasmComdatEntry>> &Comdats);
315 void writeCustomRelocSections();
320 uint32_t getProvisionalValue(
const WasmRelocationEntry &RelEntry);
322 uint64_t ContentsOffset);
324 uint32_t getRelocationIndexValue(
const WasmRelocationEntry &RelEntry);
331 WasmObjectWriter::~WasmObjectWriter() {}
334 void WasmObjectWriter::startSection(SectionBookkeeping &
Section,
335 unsigned SectionId) {
337 W.OS <<
char(SectionId);
339 Section.SizeOffset =
W.OS.tell();
346 Section.ContentsOffset =
W.OS.tell();
347 Section.PayloadOffset =
W.OS.tell();
348 Section.Index = SectionCount++;
351 void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section,
357 Section.PayloadOffset =
W.OS.tell();
363 Section.ContentsOffset =
W.OS.tell();
368 void WasmObjectWriter::endSection(SectionBookkeeping &Section) {
369 uint64_t
Size =
W.OS.tell() - Section.PayloadOffset;
390 void WasmObjectWriter::executePostLayoutBinding(
MCAssembler &Asm,
396 if (WS.isDefined() && WS.isFunction() && !WS.isVariable()) {
397 const auto &Sec =
static_cast<const MCSectionWasm &
>(S.getSection());
398 auto Pair = SectionFunctions.insert(std::make_pair(&Sec, &S));
401 Sec.getSectionName());
406 void WasmObjectWriter::recordRelocation(
MCAssembler &Asm,
410 uint64_t &FixedValue) {
414 const auto &FixupSection = cast<MCSectionWasm>(*Fragment->
getParent());
420 if (FixupSection.getSectionName().startswith(
".init_array"))
425 "Should not have constructed this");
437 "No relocation available to represent this relative expression");
441 const auto &SymB = cast<MCSymbolWasm>(RefB->getSymbol());
443 if (SymB.isUndefined()) {
445 Twine(
"symbol '") + SymB.getName() +
446 "' can not be undefined in a subtraction expression");
450 assert(!SymB.isAbsolute() &&
"Should have been folded");
451 const MCSection &SecB = SymB.getSection();
452 if (&SecB != &FixupSection) {
454 "Cannot represent a difference across sections");
459 uint64_t K = SymBOffset - FixupOffset;
466 const auto *SymA = RefA ? cast<MCSymbolWasm>(&RefA->
getSymbol()) :
nullptr;
468 if (SymA && SymA->isVariable()) {
469 const MCExpr *Expr = SymA->getVariableValue();
470 const auto *Inner = cast<MCSymbolRefExpr>(Expr);
487 if (Type == wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32 ||
488 Type == wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32) {
489 if (!FixupSection.getKind().isMetadata())
491 "only supported in metadata sections");
493 const MCSymbol *SectionSymbol =
nullptr;
494 const MCSection &SecA = SymA->getSection();
496 SectionSymbol = SectionFunctions.find(&SecA)->second;
503 SymA = cast<MCSymbolWasm>(SectionSymbol);
508 if (Type != wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB) {
509 if (SymA->getName().empty())
511 "supported by wasm");
513 SymA->setUsedInReloc();
516 WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection);
519 if (FixupSection.isWasmData()) {
520 DataRelocations.push_back(Rec);
521 }
else if (FixupSection.getKind().isText()) {
522 CodeRelocations.push_back(Rec);
523 }
else if (FixupSection.getKind().isMetadata()) {
524 CustomSectionsRelocations[&FixupSection].push_back(Rec);
537 Stream.
pwrite((
char *)Buffer, SizeLen, Offset);
547 Stream.
pwrite((
char *)Buffer, SizeLen, Offset);
554 Stream.
pwrite((
char *)Buffer,
sizeof(Buffer), Offset);
560 auto *Inner = cast<MCSymbolRefExpr>(Expr);
561 return cast<MCSymbolWasm>(&Inner->getSymbol());
571 WasmObjectWriter::getProvisionalValue(
const WasmRelocationEntry &RelEntry) {
572 switch (RelEntry.Type) {
573 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
574 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: {
578 return TableIndices[Sym];
580 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
582 return getRelocationIndexValue(RelEntry);
583 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
584 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
586 if (!WasmIndices.count(RelEntry.Symbol))
588 RelEntry.Symbol->getName());
589 return WasmIndices[RelEntry.Symbol];
590 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
591 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: {
592 const auto &Section =
593 static_cast<const MCSectionWasm &
>(RelEntry.Symbol->getSection());
594 return Section.getSectionOffset() + RelEntry.Addend;
596 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
597 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
598 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: {
605 const WasmDataSegment &Segment = DataSegments[Ref.
Segment];
607 return Segment.Offset + Ref.
Offset + RelEntry.Addend;
621 if (Frag.hasInstructions())
624 if (
auto *
Align = dyn_cast<MCAlignFragment>(&Frag)) {
625 if (
Align->getValueSize() != 1)
630 Align->getAlignment()),
632 Align->getMaxBytesToEmit());
633 DataBytes.
resize(Size, Value);
634 }
else if (
auto *Fill = dyn_cast<MCFillFragment>(&Frag)) {
636 if (!Fill->getNumValues().evaluateAsAbsolute(NumValues))
638 DataBytes.
insert(DataBytes.
end(), Fill->getValueSize() * NumValues,
641 const auto &DataFrag = cast<MCDataFragment>(Frag);
644 DataBytes.
insert(DataBytes.
end(), Contents.begin(), Contents.end());
652 WasmObjectWriter::getRelocationIndexValue(
const WasmRelocationEntry &RelEntry) {
653 if (RelEntry.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB) {
654 if (!TypeIndices.count(RelEntry.Symbol))
656 RelEntry.Symbol->getName());
657 return TypeIndices[RelEntry.Symbol];
660 return RelEntry.Symbol->getIndex();
665 void WasmObjectWriter::applyRelocations(
668 for (
const WasmRelocationEntry &RelEntry : Relocations) {
669 uint64_t
Offset = ContentsOffset +
670 RelEntry.FixupSection->getSectionOffset() +
676 switch (RelEntry.Type) {
677 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
678 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
679 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
680 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
683 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
684 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
685 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
686 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
689 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
690 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
699 void WasmObjectWriter::writeTypeSection(
701 if (FunctionTypes.
empty())
709 for (
const WasmFunctionType &FuncTy : FunctionTypes) {
735 writeString(
Import.Module);
736 writeString(
Import.Field);
765 if (Functions.
empty())
772 for (
const WasmFunction &Func : Functions)
778 void WasmObjectWriter::writeGlobalSection() {
786 for (
const WasmGlobal &
Global : Globals) {
787 writeValueType(static_cast<wasm::ValType>(
Global.Type.Type));
816 if (TableElems.
empty())
837 void WasmObjectWriter::writeCodeSection(
const MCAssembler &Asm,
840 if (Functions.
empty())
845 CodeSectionIndex = Section.Index;
849 for (
const WasmFunction &Func : Functions) {
850 auto &FuncSection =
static_cast<MCSectionWasm &
>(Func.Sym->getSection());
853 if (!Func.Sym->getSize()->evaluateAsAbsolute(Size, Layout))
857 FuncSection.setSectionOffset(
W.OS.tell() - Section.ContentsOffset);
862 applyRelocations(CodeRelocations, Section.ContentsOffset);
867 void WasmObjectWriter::writeDataSection() {
868 if (DataSegments.empty())
873 DataSectionIndex = Section.Index;
877 for (
const WasmDataSegment &Segment : DataSegments) {
883 Segment.Section->setSectionOffset(
W.OS.tell() - Section.ContentsOffset);
884 W.OS << Segment.Data;
888 applyRelocations(DataRelocations, Section.ContentsOffset);
893 void WasmObjectWriter::writeRelocSection(
899 if (Relocations.
empty())
903 startCustomSection(Section, std::string(
"reloc.") + Name.
str());
907 for (
const WasmRelocationEntry& RelEntry : Relocations) {
908 uint64_t
Offset = RelEntry.Offset +
909 RelEntry.FixupSection->getSectionOffset();
912 W.OS <<
char(RelEntry.Type);
915 if (RelEntry.hasAddend())
922 void WasmObjectWriter::writeCustomRelocSections() {
923 for (
const auto &Sec : CustomSections) {
924 auto &Relocations = CustomSectionsRelocations[Sec.Section];
925 writeRelocSection(Sec.OutputIndex, Sec.Name, Relocations);
929 void WasmObjectWriter::writeLinkingMetaDataSection(
931 ArrayRef<std::pair<uint16_t, uint32_t>> InitFuncs,
932 const std::map<
StringRef, std::vector<WasmComdatEntry>> &Comdats) {
934 startCustomSection(Section,
"linking");
937 SectionBookkeeping SubSection;
938 if (SymbolInfos.
size() != 0) {
949 writeString(Sym.Name);
952 writeString(Sym.Name);
961 CustomSections[Sym.ElementIndex].OutputIndex;
969 endSection(SubSection);
972 if (DataSegments.size()) {
975 for (
const WasmDataSegment &Segment : DataSegments) {
976 writeString(Segment.Name);
980 endSection(SubSection);
983 if (!InitFuncs.empty()) {
986 for (
auto &StartFunc : InitFuncs) {
990 endSection(SubSection);
993 if (Comdats.size()) {
996 for (
const auto &
C : Comdats) {
997 writeString(
C.first);
1000 for (
const WasmComdatEntry &Entry :
C.second) {
1005 endSection(SubSection);
1008 endSection(Section);
1011 void WasmObjectWriter::writeCustomSections(
const MCAssembler &Asm,
1013 for (
auto &CustomSection : CustomSections) {
1015 auto *Sec = CustomSection.Section;
1016 startCustomSection(Section, CustomSection.Name);
1018 Sec->setSectionOffset(
W.OS.tell() - Section.ContentsOffset);
1021 CustomSection.OutputContentsOffset = Section.ContentsOffset;
1022 CustomSection.OutputIndex = Section.Index;
1024 endSection(Section);
1027 auto &Relocations = CustomSectionsRelocations[CustomSection.Section];
1028 applyRelocations(Relocations, CustomSection.OutputContentsOffset);
1034 assert(TypeIndices.count(&Symbol));
1035 return TypeIndices[&
Symbol];
1047 FunctionTypeIndices.
insert(std::make_pair(F, FunctionTypes.
size()));
1049 FunctionTypes.push_back(F);
1050 TypeIndices[&
Symbol] = Pair.first->second;
1053 <<
" new:" << Pair.second <<
"\n");
1054 LLVM_DEBUG(
dbgs() <<
" -> type index: " << Pair.first->second <<
"\n");
1055 return Pair.first->second;
1077 uint64_t WasmObjectWriter::writeObject(
MCAssembler &Asm,
1079 uint64_t StartOffset =
W.OS.tell();
1091 std::map<StringRef, std::vector<WasmComdatEntry>> Comdats;
1101 MemImport.Field = MemorySym->
getName();
1112 TableImport.Field = TableSym->
getName();
1125 if (WS.isFunction())
1126 registerFunctionType(WS);
1128 if (WS.isTemporary())
1132 if (!WS.isDefined() && !WS.isComdat()) {
1133 if (WS.isFunction()) {
1135 Import.
Module = WS.getModuleName();
1136 Import.
Field = WS.getName();
1138 Import.
SigIndex = getFunctionType(WS);
1140 WasmIndices[&WS] = NumFunctionImports++;
1141 }
else if (WS.isGlobal()) {
1146 Import.
Module = WS.getModuleName();
1147 Import.
Field = WS.getName();
1149 Import.
Global = WS.getGlobalType();
1151 WasmIndices[&WS] = NumGlobalImports++;
1167 if (Section.getKind().isText())
1170 if (Section.isWasmData()) {
1171 uint32_t SegmentIndex = DataSegments.size();
1172 DataSize =
alignTo(DataSize, Section.getAlignment());
1173 DataSegments.emplace_back();
1174 WasmDataSegment &Segment = DataSegments.back();
1176 Segment.Offset = DataSize;
1178 addData(Segment.Data, Section);
1179 Segment.Alignment = Section.getAlignment();
1181 DataSize += Segment.Data.size();
1182 Section.setSegmentIndex(SegmentIndex);
1185 Comdats[
C->
getName()].emplace_back(
1190 assert(Sec.getKind().isMetadata());
1195 if (Name.startswith(
".custom_section."))
1196 Name = Name.substr(strlen(
".custom_section."));
1198 MCSymbol* Begin = Sec.getBeginSymbol();
1200 WasmIndices[cast<MCSymbolWasm>(Begin)] = CustomSections.size();
1201 if (SectionName != Begin->
getName())
1203 Twine(SectionName));
1205 CustomSections.emplace_back(Name, &Section);
1210 for (
const MCSymbol &S : Asm.symbols()) {
1213 if (S.isTemporary() && S.getName().empty())
1218 dbgs() <<
"MCSymbol: " <<
toString(WS.getType()) <<
" '" << S <<
"'" 1219 <<
" isDefined=" << S.isDefined() <<
" isExternal=" 1220 << S.isExternal() <<
" isTemporary=" << S.isTemporary()
1221 <<
" isWeak=" << WS.isWeak() <<
" isHidden=" << WS.isHidden()
1222 <<
" isVariable=" << WS.isVariable() <<
"\n");
1224 if (WS.isVariable())
1226 if (WS.isComdat() && !WS.isDefined())
1229 if (WS.isFunction()) {
1231 if (WS.isDefined()) {
1232 if (WS.getOffset() != 0)
1234 "function sections must contain one function each");
1236 if (WS.getSize() == 0)
1238 "function symbols must have a size set with .size");
1241 Index = NumFunctionImports + Functions.
size();
1243 Func.Type = getFunctionType(WS);
1245 WasmIndices[&WS] =
Index;
1248 auto &Section =
static_cast<MCSectionWasm &
>(WS.getSection());
1250 Comdats[
C->
getName()].emplace_back(
1255 Index = WasmIndices.find(&WS)->second;
1259 }
else if (WS.isData()) {
1260 if (WS.isTemporary() && !WS.getSize())
1263 if (!WS.isDefined()) {
1274 if (!WS.getSize()->evaluateAsAbsolute(Size, Layout))
1277 auto &DataSection =
static_cast<MCSectionWasm &
>(WS.getSection());
1278 assert(DataSection.isWasmData());
1283 DataSection.getSegmentIndex(),
1285 static_cast<uint32_t>(Size)};
1286 DataLocations[&WS] =
Ref;
1287 LLVM_DEBUG(
dbgs() <<
" -> segment index: " << Ref.Segment <<
"\n");
1288 }
else if (WS.isGlobal()) {
1295 << WasmIndices.find(&WS)->second <<
"\n");
1305 for (
const MCSymbol &S : Asm.symbols()) {
1306 if (!S.isVariable())
1314 LLVM_DEBUG(
dbgs() << WS.getName() <<
": weak alias of '" << *ResolvedSym
1317 if (WS.isFunction()) {
1318 assert(WasmIndices.count(ResolvedSym) > 0);
1319 uint32_t WasmIndex = WasmIndices.find(ResolvedSym)->second;
1320 WasmIndices[&WS] = WasmIndex;
1322 }
else if (WS.isData()) {
1323 assert(DataLocations.count(ResolvedSym) > 0);
1325 DataLocations.find(ResolvedSym)->second;
1326 DataLocations[&WS] =
Ref;
1334 for (
const MCSymbol &S : Asm.symbols()) {
1347 if (!WS.isExternal() && WS.isDefined())
1349 if (WS.isUndefined())
1353 Info.
Name = WS.getName();
1354 Info.
Kind = WS.getType();
1357 assert(WasmIndices.count(&WS) > 0);
1359 }
else if (WS.isDefined()) {
1360 assert(DataLocations.count(&WS) > 0);
1361 Info.
DataRef = DataLocations.find(&WS)->second;
1363 WS.setIndex(SymbolInfos.
size());
1368 auto HandleReloc = [&](
const WasmRelocationEntry &Rel) {
1372 if (Rel.Type != wasm::R_WEBASSEMBLY_TABLE_INDEX_I32 &&
1373 Rel.Type != wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB)
1375 assert(Rel.Symbol->isFunction());
1377 uint32_t FunctionIndex = WasmIndices.find(&WS)->second;
1378 uint32_t TableIndex = TableElems.
size() + kInitialTableOffset;
1379 if (TableIndices.try_emplace(&WS, TableIndex).second) {
1381 <<
" to table: " << TableIndex <<
"\n");
1383 registerFunctionType(WS);
1387 for (
const WasmRelocationEntry &RelEntry : CodeRelocations)
1388 HandleReloc(RelEntry);
1389 for (
const WasmRelocationEntry &RelEntry : DataRelocations)
1390 HandleReloc(RelEntry);
1396 if (WS.getSectionName().startswith(
".fini_array"))
1398 if (!WS.getSectionName().startswith(
".init_array"))
1400 if (WS.getFragmentList().empty())
1404 if (WS.getFragmentList().size() != 3)
1407 auto IT = WS.begin();
1416 if (cast<MCAlignFragment>(AlignFrag).getAlignment() != (
is64Bit() ? 8 : 4))
1423 uint16_t Priority = UINT16_MAX;
1424 unsigned PrefixLength = strlen(
".init_array");
1425 if (WS.getSectionName().size() > PrefixLength) {
1426 if (WS.getSectionName()[PrefixLength] !=
'.')
1428 if (WS.getSectionName()
1429 .substr(PrefixLength + 1)
1430 .getAsInteger(10, Priority))
1433 const auto &DataFrag = cast<MCDataFragment>(Frag);
1435 for (
const uint8_t *p = (
const uint8_t *)Contents.data(),
1436 *
end = (
const uint8_t *)Contents.data() + Contents.size();
1441 for (
const MCFixup &Fixup : DataFrag.getFixups()) {
1449 if (Sym->getSymbol().getIndex() == INVALID_INDEX)
1452 std::make_pair(Priority, Sym->getSymbol().getIndex()));
1459 writeTypeSection(FunctionTypes);
1460 writeImportSection(Imports, DataSize, TableElems.
size());
1461 writeFunctionSection(Functions);
1464 writeGlobalSection();
1465 writeExportSection(Exports);
1466 writeElemSection(TableElems);
1467 writeCodeSection(Asm, Layout, Functions);
1469 writeCustomSections(Asm, Layout);
1470 writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats);
1471 writeRelocSection(CodeSectionIndex,
"CODE", CodeRelocations);
1472 writeRelocSection(DataSectionIndex,
"DATA", DataRelocations);
1473 writeCustomRelocSections();
1476 return W.OS.tell() - StartOffset;
1479 std::unique_ptr<MCObjectWriter>
1482 return llvm::make_unique<WasmObjectWriter>(std::move(MOTW), OS);
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
static const MCSymbolWasm * ResolveSymbol(const MCSymbolWasm &Symbol)
const_iterator end(StringRef path)
Get end iterator over path.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
SectionKind getKind() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
bool isVariable() const
isVariable - Check if this is a variable symbol.
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static void WriteI32(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset)
const unsigned WASM_SYMBOL_BINDING_LOCAL
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
const StringRef getModuleName() const
const uint32_t WasmMetadataVersion
StringRef getSectionName() const
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
FragmentType getKind() const
void write32le(void *P, uint32_t V)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
unsigned getAlignment() const
Export information to summary.
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
MCContext & getContext() const
static void WritePatchableSLEB(raw_pwrite_stream &Stream, int32_t X, uint64_t Offset)
const unsigned WASM_SYMBOL_UNDEFINED
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Encapsulates the layout of an assembly file at a particular point in time.
Base class for the full range of assembler expressions which are needed for parsing.
The access may reference the value stored in memory.
Represent a reference to a symbol from inside an expression.
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
const uint32_t WasmVersion
Context object for machine code objects.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static bool isEqual(const Function &Caller, const Function &Callee)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
std::string relocTypetoString(uint32_t type)
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Import information from summary.
The instances of the Type class are immutable: once they are created, they are never changed...
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN
size_t size() const
size - Get the array size.
This represents a section on wasm.
static bool is64Bit(const char *name)
virtual void reset()
lifetime management
const unsigned WASM_SYMBOL_BINDING_WEAK
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
std::unique_ptr< MCObjectWriter > createWasmObjectWriter(std::unique_ptr< MCWasmObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
Construct a new Wasm writer instance.
const MCSymbolRefExpr * getSymA() const
void reportError(SMLoc L, const Twine &Msg)
const SmallVector< wasm::ValType, 1 > & getReturns() const
static void addData(SmallVectorImpl< char > &DataBytes, MCSectionWasm &DataSection)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
uint32_t getOffset() const
void writeSectionData(raw_ostream &OS, const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents to OS.
const MCExpr * getSize() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
PowerPC TLS Dynamic Call Fixup
MCAsmBackend & getBackend() const
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
const MCSymbol & getSymbol() const
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
MCSymbol * getBeginSymbol()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Target - Wrapper for Target specific information.
MCSection * getParent() const
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
iterator insert(iterator I, T &&Elt)
bool isUsedInReloc() const
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
Adapter to write values to a stream in a particular byte order.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void emplace_back(ArgTypes &&... Args)
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
StringRef getName() const
getName - Get the symbol name.
An abstract base class for streams implementations that also support a pwrite operation.
const SmallVector< wasm::ValType, 4 > & getParams() const
static void WritePatchableLEB(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
WasmDataReference DataRef
LLVM Value Representation.
Generic interface to target specific assembler backends.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
const MCExpr * getValue() const
const uint32_t WasmPageSize
StringRef - Represent a constant reference to a string, i.e.
bool operator==(uint64_t V1, const APInt &V2)
static bool isInSymtab(const MCSymbolWasm &Sym)
void setIndex(uint32_t Value) const
Set the (implementation defined) index.
MCFixupKind getKind() const
bool empty() const
empty - Check if the array is empty.