[llvm] b76100e - WasmObjectWriter: replace the MCAsmLayout parameter with MCAssembler
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 17:18:29 PDT 2024
Author: Fangrui Song
Date: 2024-07-01T17:18:24-07:00
New Revision: b76100e220591fab2bf0a4917b216439f7aa4b09
URL: https://github.com/llvm/llvm-project/commit/b76100e220591fab2bf0a4917b216439f7aa4b09
DIFF: https://github.com/llvm/llvm-project/commit/b76100e220591fab2bf0a4917b216439f7aa4b09.diff
LOG: WasmObjectWriter: replace the MCAsmLayout parameter with MCAssembler
Added:
Modified:
llvm/lib/MC/WasmObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 187851bb693d8..f25dc92fa235a 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -15,7 +15,6 @@
#include "llvm/BinaryFormat/WasmTraits.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/MC/MCAsmBackend.h"
-#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
@@ -299,11 +298,10 @@ class WasmObjectWriter : public MCObjectWriter {
void executePostLayoutBinding(MCAssembler &Asm) override;
void prepareImports(SmallVectorImpl<wasm::WasmImport> &Imports,
- MCAssembler &Asm, const MCAsmLayout &Layout);
+ MCAssembler &Asm);
uint64_t writeObject(MCAssembler &Asm) override;
- uint64_t writeOneObject(MCAssembler &Asm, const MCAsmLayout &Layout,
- DwoMode Mode);
+ uint64_t writeOneObject(MCAssembler &Asm, DwoMode Mode);
void writeString(const StringRef Str) {
encodeULEB128(Str.size(), W->OS);
@@ -334,9 +332,9 @@ class WasmObjectWriter : public MCObjectWriter {
void writeElemSection(const MCSymbolWasm *IndirectFunctionTable,
ArrayRef<uint32_t> TableElems);
void writeDataCountSection();
- uint32_t writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout,
+ uint32_t writeCodeSection(const MCAssembler &Asm,
ArrayRef<WasmFunction> Functions);
- uint32_t writeDataSection(const MCAsmLayout &Layout);
+ uint32_t writeDataSection(const MCAssembler &Asm);
void writeTagSection(ArrayRef<uint32_t> TagTypes);
void writeGlobalSection(ArrayRef<wasm::WasmGlobal> Globals);
void writeTableSection(ArrayRef<wasm::WasmTable> Tables);
@@ -347,13 +345,13 @@ class WasmObjectWriter : public MCObjectWriter {
ArrayRef<std::pair<uint16_t, uint32_t>> InitFuncs,
const std::map<StringRef, std::vector<WasmComdatEntry>> &Comdats);
void writeCustomSection(WasmCustomSection &CustomSection,
- const MCAssembler &Asm, const MCAsmLayout &Layout);
+ const MCAssembler &Asm);
void writeCustomRelocSections();
uint64_t getProvisionalValue(const MCAssembler &Asm,
const WasmRelocationEntry &RelEntry);
void applyRelocations(ArrayRef<WasmRelocationEntry> Relocations,
- uint64_t ContentsOffset, const MCAsmLayout &Layout);
+ uint64_t ContentsOffset, const MCAssembler &Asm);
uint32_t getRelocationIndexValue(const WasmRelocationEntry &RelEntry);
uint32_t getFunctionType(const MCSymbolWasm &Symbol);
@@ -764,7 +762,7 @@ WasmObjectWriter::getRelocationIndexValue(const WasmRelocationEntry &RelEntry) {
// directly.
void WasmObjectWriter::applyRelocations(
ArrayRef<WasmRelocationEntry> Relocations, uint64_t ContentsOffset,
- const MCAsmLayout &Layout) {
+ const MCAssembler &Asm) {
auto &Stream = static_cast<raw_pwrite_stream &>(W->OS);
for (const WasmRelocationEntry &RelEntry : Relocations) {
uint64_t Offset = ContentsOffset +
@@ -772,7 +770,7 @@ void WasmObjectWriter::applyRelocations(
RelEntry.Offset;
LLVM_DEBUG(dbgs() << "applyRelocation: " << RelEntry << "\n");
- uint64_t Value = getProvisionalValue(Layout.getAssembler(), RelEntry);
+ uint64_t Value = getProvisionalValue(Asm, RelEntry);
switch (RelEntry.Type) {
case wasm::R_WASM_FUNCTION_INDEX_LEB:
@@ -1049,7 +1047,6 @@ void WasmObjectWriter::writeDataCountSection() {
}
uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm,
- const MCAsmLayout &Layout,
ArrayRef<WasmFunction> Functions) {
if (Functions.empty())
return 0;
@@ -1069,13 +1066,13 @@ uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm,
}
// Apply fixups.
- applyRelocations(CodeRelocations, Section.ContentsOffset, Layout);
+ applyRelocations(CodeRelocations, Section.ContentsOffset, Asm);
endSection(Section);
return Section.Index;
}
-uint32_t WasmObjectWriter::writeDataSection(const MCAsmLayout &Layout) {
+uint32_t WasmObjectWriter::writeDataSection(const MCAssembler &Asm) {
if (DataSegments.empty())
return 0;
@@ -1100,7 +1097,7 @@ uint32_t WasmObjectWriter::writeDataSection(const MCAsmLayout &Layout) {
}
// Apply fixups.
- applyRelocations(DataRelocations, Section.ContentsOffset, Layout);
+ applyRelocations(DataRelocations, Section.ContentsOffset, Asm);
endSection(Section);
return Section.Index;
@@ -1239,8 +1236,7 @@ void WasmObjectWriter::writeLinkingMetaDataSection(
}
void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection,
- const MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+ const MCAssembler &Asm) {
SectionBookkeeping Section;
auto *Sec = CustomSection.Section;
startCustomSection(Section, CustomSection.Name);
@@ -1255,7 +1251,7 @@ void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection,
// Apply fixups.
auto &Relocations = CustomSectionsRelocations[CustomSection.Section];
- applyRelocations(Relocations, CustomSection.OutputContentsOffset, Layout);
+ applyRelocations(Relocations, CustomSection.OutputContentsOffset, Asm);
}
uint32_t WasmObjectWriter::getFunctionType(const MCSymbolWasm &Symbol) {
@@ -1331,8 +1327,7 @@ static bool isInSymtab(const MCSymbolWasm &Sym) {
}
void WasmObjectWriter::prepareImports(
- SmallVectorImpl<wasm::WasmImport> &Imports, MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+ SmallVectorImpl<wasm::WasmImport> &Imports, MCAssembler &Asm) {
// For now, always emit the memory import, since loads and stores are not
// valid without it. In the future, we could perhaps be more clever and omit
// it if there are no loads or stores.
@@ -1437,22 +1432,20 @@ void WasmObjectWriter::prepareImports(
}
uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm) {
- auto &Layout = *Asm.getLayout();
support::endian::Writer MainWriter(*OS, llvm::endianness::little);
W = &MainWriter;
if (IsSplitDwarf) {
- uint64_t TotalSize = writeOneObject(Asm, Layout, DwoMode::NonDwoOnly);
+ uint64_t TotalSize = writeOneObject(Asm, DwoMode::NonDwoOnly);
assert(DwoOS);
support::endian::Writer DwoWriter(*DwoOS, llvm::endianness::little);
W = &DwoWriter;
- return TotalSize + writeOneObject(Asm, Layout, DwoMode::DwoOnly);
+ return TotalSize + writeOneObject(Asm, DwoMode::DwoOnly);
} else {
- return writeOneObject(Asm, Layout, DwoMode::AllSections);
+ return writeOneObject(Asm, DwoMode::AllSections);
}
}
uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
- const MCAsmLayout &Layout,
DwoMode Mode) {
uint64_t StartOffset = W->OS.tell();
SectionCount = 0;
@@ -1472,9 +1465,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
SmallVector<std::pair<uint16_t, uint32_t>, 2> InitFuncs;
std::map<StringRef, std::vector<WasmComdatEntry>> Comdats;
uint64_t DataSize = 0;
- if (Mode != DwoMode::DwoOnly) {
- prepareImports(Imports, Asm, Layout);
- }
+ if (Mode != DwoMode::DwoOnly)
+ prepareImports(Imports, Asm);
// Populate DataSegments and CustomSections, which must be done before
// populating DataLocations.
@@ -1926,8 +1918,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
TableElems);
writeDataCountSection();
- CodeSectionIndex = writeCodeSection(Asm, Layout, Functions);
- DataSectionIndex = writeDataSection(Layout);
+ CodeSectionIndex = writeCodeSection(Asm, Functions);
+ DataSectionIndex = writeDataSection(Asm);
}
// The Sections in the COMDAT list have placeholder indices (their index among
@@ -1940,7 +1932,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
}
}
for (auto &CustomSection : CustomSections)
- writeCustomSection(CustomSection, Asm, Layout);
+ writeCustomSection(CustomSection, Asm);
if (Mode != DwoMode::DwoOnly) {
writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats);
@@ -1950,9 +1942,9 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
}
writeCustomRelocSections();
if (ProducersSection)
- writeCustomSection(*ProducersSection, Asm, Layout);
+ writeCustomSection(*ProducersSection, Asm);
if (TargetFeaturesSection)
- writeCustomSection(*TargetFeaturesSection, Asm, Layout);
+ writeCustomSection(*TargetFeaturesSection, Asm);
// TODO: Translate the .comment section to the output.
return W->OS.tell() - StartOffset;
More information about the llvm-commits
mailing list