diff options
author | Sam Clegg <sbc@chromium.org> | 2022-08-30 04:09:44 -0700 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2022-08-31 14:28:56 -0700 |
commit | c5c4ba37b19e14f3f4c9c1bf950d46e90602c084 (patch) | |
tree | 2bff7e182cfcce9d34663a29a185edc02fe70d24 /llvm/lib/MC/WasmObjectWriter.cpp | |
parent | f328922f55fe62a587a3ec0cd7253861cadba85e (diff) | |
download | llvm-c5c4ba37b19e14f3f4c9c1bf950d46e90602c084.zip llvm-c5c4ba37b19e14f3f4c9c1bf950d46e90602c084.tar.gz llvm-c5c4ba37b19e14f3f4c9c1bf950d46e90602c084.tar.bz2 |
[WebAssembly][MC] Avoid the need for .size directives for functions
Warn if `.size` is specified for a function symbol. The size of a
function symbol is determined solely by its content.
I noticed this simplification was possible while debugging #57427, but
this change doesn't fix that specific issue.
Differential Revision: https://reviews.llvm.org/D132929
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 7cc11d2..0404929 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -72,7 +72,7 @@ struct WasmDataSegment { // A wasm function to be written into the function section. struct WasmFunction { uint32_t SigIndex; - const MCSymbolWasm *Sym; + MCSection *Section; }; // A wasm global to be written into the global section. @@ -1058,15 +1058,12 @@ uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, encodeULEB128(Functions.size(), W->OS); for (const WasmFunction &Func : Functions) { - auto &FuncSection = static_cast<MCSectionWasm &>(Func.Sym->getSection()); - - int64_t Size = 0; - if (!Func.Sym->getSize()->evaluateAsAbsolute(Size, Layout)) - report_fatal_error(".size expression must be evaluatable"); + auto *FuncSection = static_cast<MCSectionWasm *>(Func.Section); + int64_t Size = Layout.getSectionAddressSize(FuncSection); encodeULEB128(Size, W->OS); - FuncSection.setSectionOffset(W->OS.tell() - Section.ContentsOffset); - Asm.writeSectionData(W->OS, &FuncSection, Layout); + FuncSection->setSectionOffset(W->OS.tell() - Section.ContentsOffset); + Asm.writeSectionData(W->OS, FuncSection, Layout); } // Apply fixups. @@ -1591,15 +1588,11 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, report_fatal_error( "function sections must contain one function each"); - if (WS.getSize() == nullptr) - report_fatal_error( - "function symbols must have a size set with .size"); - // A definition. Write out the function body. Index = NumFunctionImports + Functions.size(); WasmFunction Func; Func.SigIndex = getFunctionType(WS); - Func.Sym = &WS; + Func.Section = &WS.getSection(); assert(WasmIndices.count(&WS) == 0); WasmIndices[&WS] = Index; Functions.push_back(Func); |