aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-10-01 19:07:41 -0700
committerHeejin Ahn <aheejin@gmail.com>2021-10-05 17:11:22 -0700
commit3ec1760d91a38e30d9535c313e4231e332910dd3 (patch)
tree9b060fbb8da43ced700af5b9332543822c395761
parentd51f57c23ca95f4b9b383f0942fee2957d36fd4f (diff)
downloadllvm-3ec1760d91a38e30d9535c313e4231e332910dd3.zip
llvm-3ec1760d91a38e30d9535c313e4231e332910dd3.tar.gz
llvm-3ec1760d91a38e30d9535c313e4231e332910dd3.tar.bz2
[WebAssembly] Remove WasmTagType
This removes `WasmTagType`. `WasmTagType` contained an attribute and a signature index: ``` struct WasmTagType { uint8_t Attribute; uint32_t SigIndex; }; ``` Currently the attribute field is not used and reserved for future use, and always 0. And that this class contains `SigIndex` as its property is a little weird in the place, because the tag type's signature index is not an inherent property of a tag but rather a reference to another section that changes after linking. This makes tag handling in the linker also weird that tag-related methods are taking both `WasmTagType` and `WasmSignature` even though `WasmTagType` contains a signature index. This is because the signature index changes in linking so it doesn't have any info at this point. This instead moves `SigIndex` to `struct WasmTag` itself, as we did for `struct WasmFunction` in D111104. In this CL, in lib/MC and lib/Object, this now treats tag types in the same way as function types. Also in YAML, this removes `struct Tag`, because now it only contains the tag index. Also tags set `SigIndex` in `WasmImport` union, as functions do. I think this makes things simpler and makes tag handling more in line with function handling. These two shares similar properties in that both of them have signatures, but they are kind of nominal so having the same signature doesn't mean they are the same element. Also a drive-by fix: the reserved 'attirubute' part's encoding changed from uleb32 to uint8 a while ago. This was fixed in lib/MC and lib/Object but not in YAML. This doesn't change object files because the field's value is always 0 and its encoding is the same for the both encoding. This is effectively NFC; I didn't mark it as such just because it changed YAML test results. Reviewed By: sbc100, tlively Differential Revision: https://reviews.llvm.org/D111086
-rw-r--r--lld/include/lld/Common/LLVM.h2
-rw-r--r--lld/test/wasm/tag-section.ll5
-rw-r--r--lld/wasm/InputElement.h7
-rw-r--r--lld/wasm/InputFiles.cpp7
-rw-r--r--lld/wasm/SymbolTable.cpp8
-rw-r--r--lld/wasm/Symbols.cpp1
-rw-r--r--lld/wasm/Symbols.h7
-rw-r--r--lld/wasm/SyntheticSections.cpp8
-rw-r--r--lld/wasm/WriterUtils.cpp18
-rw-r--r--lld/wasm/WriterUtils.h5
-rw-r--r--llvm/include/llvm/BinaryFormat/Wasm.h9
-rw-r--r--llvm/include/llvm/MC/MCSymbolWasm.h7
-rw-r--r--llvm/include/llvm/Object/Wasm.h5
-rw-r--r--llvm/include/llvm/ObjectYAML/WasmYAML.h15
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp33
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp31
-rw-r--r--llvm/lib/ObjectYAML/WasmEmitter.cpp18
-rw-r--r--llvm/lib/ObjectYAML/WasmYAML.cpp14
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp4
-rw-r--r--llvm/test/MC/WebAssembly/tag-section-decoding.ll5
-rw-r--r--llvm/test/MC/WebAssembly/tag-section.ll5
-rw-r--r--llvm/test/ObjectYAML/wasm/event_section.yaml10
-rw-r--r--llvm/tools/obj2yaml/wasm2yaml.cpp9
23 files changed, 68 insertions, 165 deletions
diff --git a/lld/include/lld/Common/LLVM.h b/lld/include/lld/Common/LLVM.h
index c19364a..6872adf 100644
--- a/lld/include/lld/Common/LLVM.h
+++ b/lld/include/lld/Common/LLVM.h
@@ -45,7 +45,6 @@ class WasmSymbol;
namespace wasm {
struct WasmTag;
-struct WasmTagType;
struct WasmFunction;
struct WasmGlobal;
struct WasmGlobalType;
@@ -97,7 +96,6 @@ using llvm::wasm::WasmSignature;
using llvm::wasm::WasmTable;
using llvm::wasm::WasmTableType;
using llvm::wasm::WasmTag;
-using llvm::wasm::WasmTagType;
} // end namespace lld.
namespace std {
diff --git a/lld/test/wasm/tag-section.ll b/lld/test/wasm/tag-section.ll
index a2db662..1f6aa9d 100644
--- a/lld/test/wasm/tag-section.ll
+++ b/lld/test/wasm/tag-section.ll
@@ -30,10 +30,7 @@ define void @_start() {
; CHECK-NEXT: ReturnTypes: []
; CHECK: - Type: TAG
-; CHECK-NEXT: Tags:
-; CHECK-NEXT: - Index: 0
-; CHECK-NEXT: Attribute: 0
-; CHECK-NEXT: SigIndex: 1
+; CHECK-NEXT: TagTypes: [ 1 ]
; Global section has to come after tag section
; CHECK: - Type: GLOBAL
diff --git a/lld/wasm/InputElement.h b/lld/wasm/InputElement.h
index d00e60b..d1262de 100644
--- a/lld/wasm/InputElement.h
+++ b/lld/wasm/InputElement.h
@@ -74,14 +74,9 @@ private:
class InputTag : public InputElement {
public:
InputTag(const WasmSignature &s, const WasmTag &t, ObjFile *f)
- : InputElement(t.SymbolName, f), signature(s), type(t.Type) {}
-
- const WasmTagType &getType() const { return type; }
+ : InputElement(t.SymbolName, f), signature(s) {}
const WasmSignature &signature;
-
-private:
- WasmTagType type;
};
class InputTable : public InputElement {
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 5775258..9e7f1ca 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -336,10 +336,9 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info->Name
<< "\n");
const WasmGlobalType *globalType = nullptr;
- const WasmTagType *tagType = nullptr;
const WasmSignature *signature = nullptr;
- auto *wasmSym = make<WasmSymbol>(*info, globalType, &tableImport->Table,
- tagType, signature);
+ auto *wasmSym =
+ make<WasmSymbol>(*info, globalType, &tableImport->Table, signature);
Symbol *sym = createUndefined(*wasmSym, false);
// We're only sure it's a TableSymbol if the createUndefined succeeded.
if (errorCount())
@@ -516,7 +515,7 @@ void ObjFile::parse(bool ignoreComdats) {
// Populate `Tags`.
for (const WasmTag &t : wasmObj->tags())
- tags.emplace_back(make<InputTag>(types[t.Type.SigIndex], t, this));
+ tags.emplace_back(make<InputTag>(types[t.SigIndex], t, this));
// Populate `Symbols` based on the symbols in the object.
symbols.reserve(wasmObj->getNumberOfSymbols());
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index a0e59e2..877909c 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -169,7 +169,6 @@ static void checkGlobalType(const Symbol *existing, const InputFile *file,
}
static void checkTagType(const Symbol *existing, const InputFile *file,
- const WasmTagType *newType,
const WasmSignature *newSig) {
const auto *existingTag = dyn_cast<TagSymbol>(existing);
if (!isa<TagSymbol>(existing)) {
@@ -177,12 +176,7 @@ static void checkTagType(const Symbol *existing, const InputFile *file,
return;
}
- const WasmTagType *oldType = cast<TagSymbol>(existing)->getTagType();
const WasmSignature *oldSig = existingTag->signature;
- if (newType->Attribute != oldType->Attribute)
- error("Tag type mismatch: " + existing->getName() + "\n>>> defined as " +
- toString(*oldType) + " in " + toString(existing->getFile()) +
- "\n>>> defined as " + toString(*newType) + " in " + toString(file));
if (*newSig != *oldSig)
warn("Tag signature mismatch: " + existing->getName() +
"\n>>> defined as " + toString(*oldSig) + " in " +
@@ -430,7 +424,7 @@ Symbol *SymbolTable::addDefinedTag(StringRef name, uint32_t flags,
return s;
}
- checkTagType(s, file, &tag->getType(), &tag->signature);
+ checkTagType(s, file, &tag->signature);
if (shouldReplace(s, file, flags))
replaceSym();
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index 319d60c..4658b82 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -369,7 +369,6 @@ bool TagSymbol::hasTagIndex() const {
DefinedTag::DefinedTag(StringRef name, uint32_t flags, InputFile *file,
InputTag *tag)
: TagSymbol(name, DefinedTagKind, flags, file,
- tag ? &tag->getType() : nullptr,
tag ? &tag->signature : nullptr),
tag(tag) {}
diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h
index eebe4fd..54f7b61 100644
--- a/lld/wasm/Symbols.h
+++ b/lld/wasm/Symbols.h
@@ -439,8 +439,6 @@ class TagSymbol : public Symbol {
public:
static bool classof(const Symbol *s) { return s->kind() == DefinedTagKind; }
- const WasmTagType *getTagType() const { return tagType; }
-
// Get/set the tag index
uint32_t getTagIndex() const;
void setTagIndex(uint32_t index);
@@ -450,10 +448,9 @@ public:
protected:
TagSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f,
- const WasmTagType *tagType, const WasmSignature *sig)
- : Symbol(name, k, flags, f), signature(sig), tagType(tagType) {}
+ const WasmSignature *sig)
+ : Symbol(name, k, flags, f), signature(sig) {}
- const WasmTagType *tagType;
uint32_t tagIndex = INVALID_INDEX;
};
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 549af5b..d70ade4 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -226,8 +226,7 @@ void ImportSection::writeBody() {
import.Global = *globalSym->getGlobalType();
} else if (auto *tagSym = dyn_cast<TagSymbol>(sym)) {
import.Kind = WASM_EXTERNAL_TAG;
- import.Tag.Attribute = tagSym->getTagType()->Attribute;
- import.Tag.SigIndex = out.typeSec->lookupType(*tagSym->signature);
+ import.SigIndex = out.typeSec->lookupType(*tagSym->signature);
} else {
auto *tableSym = cast<TableSymbol>(sym);
import.Kind = WASM_EXTERNAL_TABLE;
@@ -332,9 +331,8 @@ void TagSection::writeBody() {
writeUleb128(os, inputTags.size(), "tag count");
for (InputTag *t : inputTags) {
- WasmTagType type = t->getType();
- type.SigIndex = out.typeSec->lookupType(t->signature);
- writeTagType(os, type);
+ writeUleb128(os, 0, "tag attribute"); // Reserved "attribute" field
+ writeUleb128(os, out.typeSec->lookupType(t->signature), "sig index");
}
}
diff --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp
index da7b2eb..c0e908f 100644
--- a/lld/wasm/WriterUtils.cpp
+++ b/lld/wasm/WriterUtils.cpp
@@ -58,12 +58,6 @@ std::string toString(const WasmGlobalType &type) {
toString(static_cast<ValType>(type.Type));
}
-std::string toString(const WasmTagType &type) {
- if (type.Attribute == WASM_TAG_ATTRIBUTE_EXCEPTION)
- return "exception";
- return "unknown";
-}
-
static std::string toString(const llvm::wasm::WasmLimits &limits) {
std::string ret;
ret += "flags=0x" + std::to_string(limits.Flags);
@@ -204,15 +198,6 @@ void writeGlobalType(raw_ostream &os, const WasmGlobalType &type) {
writeU8(os, type.Mutable, "global mutable");
}
-void writeTagType(raw_ostream &os, const WasmTagType &type) {
- writeUleb128(os, type.Attribute, "tag attribute");
- writeUleb128(os, type.SigIndex, "sig index");
-}
-
-void writeTag(raw_ostream &os, const WasmTag &tag) {
- writeTagType(os, tag.Type);
-}
-
void writeTableType(raw_ostream &os, const WasmTableType &type) {
writeValueType(os, ValType(type.ElemType), "table type");
writeLimits(os, type.Limits);
@@ -230,7 +215,8 @@ void writeImport(raw_ostream &os, const WasmImport &import) {
writeGlobalType(os, import.Global);
break;
case WASM_EXTERNAL_TAG:
- writeTagType(os, import.Tag);
+ writeUleb128(os, 0, "tag attribute"); // Reserved "attribute" field
+ writeUleb128(os, import.SigIndex, "import sig index");
break;
case WASM_EXTERNAL_MEMORY:
writeLimits(os, import.Memory);
diff --git a/lld/wasm/WriterUtils.h b/lld/wasm/WriterUtils.h
index f270cad..4cbd9a4 100644
--- a/lld/wasm/WriterUtils.h
+++ b/lld/wasm/WriterUtils.h
@@ -55,10 +55,6 @@ void writeLimits(raw_ostream &os, const llvm::wasm::WasmLimits &limits);
void writeGlobalType(raw_ostream &os, const llvm::wasm::WasmGlobalType &type);
-void writeTagType(raw_ostream &os, const llvm::wasm::WasmTagType &type);
-
-void writeTag(raw_ostream &os, const llvm::wasm::WasmTag &tag);
-
void writeTableType(raw_ostream &os, const llvm::wasm::WasmTableType &type);
void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import);
@@ -70,7 +66,6 @@ void writeExport(raw_ostream &os, const llvm::wasm::WasmExport &export_);
std::string toString(llvm::wasm::ValType type);
std::string toString(const llvm::wasm::WasmSignature &sig);
std::string toString(const llvm::wasm::WasmGlobalType &type);
-std::string toString(const llvm::wasm::WasmTagType &type);
std::string toString(const llvm::wasm::WasmTableType &type);
} // namespace lld
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index 1fd3f9a..de5b3b4 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -107,15 +107,9 @@ struct WasmGlobal {
StringRef SymbolName; // from the "linking" section
};
-struct WasmTagType {
- // Kind of tag. Currently only WASM_TAG_ATTRIBUTE_EXCEPTION is possible.
- uint8_t Attribute;
- uint32_t SigIndex;
-};
-
struct WasmTag {
uint32_t Index;
- WasmTagType Type;
+ uint32_t SigIndex;
StringRef SymbolName; // from the "linking" section
};
@@ -128,7 +122,6 @@ struct WasmImport {
WasmGlobalType Global;
WasmTableType Table;
WasmLimits Memory;
- WasmTagType Tag;
};
};
diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h
index 7feffb4..5a4852e 100644
--- a/llvm/include/llvm/MC/MCSymbolWasm.h
+++ b/llvm/include/llvm/MC/MCSymbolWasm.h
@@ -27,7 +27,6 @@ class MCSymbolWasm : public MCSymbol {
wasm::WasmSignature *Signature = nullptr;
Optional<wasm::WasmGlobalType> GlobalType;
Optional<wasm::WasmTableType> TableType;
- Optional<wasm::WasmTagType> TagType;
/// An expression describing how to calculate the size of a symbol. If a
/// symbol has no size this field will be NULL.
@@ -147,12 +146,6 @@ public:
wasm::WasmLimits Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
setTableType({uint8_t(VT), Limits});
}
-
- const wasm::WasmTagType &getTagType() const {
- assert(TagType.hasValue());
- return TagType.getValue();
- }
- void setTagType(wasm::WasmTagType ET) { TagType = ET; }
};
} // end namespace llvm
diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index 7b26c42..69ae0dc 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -37,15 +37,13 @@ public:
WasmSymbol(const wasm::WasmSymbolInfo &Info,
const wasm::WasmGlobalType *GlobalType,
const wasm::WasmTableType *TableType,
- const wasm::WasmTagType *TagType,
const wasm::WasmSignature *Signature)
: Info(Info), GlobalType(GlobalType), TableType(TableType),
- TagType(TagType), Signature(Signature) {}
+ Signature(Signature) {}
const wasm::WasmSymbolInfo &Info;
const wasm::WasmGlobalType *GlobalType;
const wasm::WasmTableType *TableType;
- const wasm::WasmTagType *TagType;
const wasm::WasmSignature *Signature;
bool isTypeFunction() const {
@@ -274,7 +272,6 @@ private:
wasm::WasmProducerInfo ProducerInfo;
std::vector<wasm::WasmFeatureEntry> TargetFeatures;
std::vector<wasm::WasmSignature> Signatures;
- std::vector<uint32_t> FunctionTypes;
std::vector<wasm::WasmTable> Tables;
std::vector<wasm::WasmLimits> Memories;
std::vector<wasm::WasmGlobal> Globals;
diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h
index e1b4883..bfae481 100644
--- a/llvm/include/llvm/ObjectYAML/WasmYAML.h
+++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h
@@ -77,12 +77,6 @@ struct Global {
wasm::WasmInitExpr InitExpr;
};
-struct Tag {
- uint32_t Index;
- uint32_t Attribute;
- uint32_t SigIndex;
-};
-
struct Import {
StringRef Module;
StringRef Field;
@@ -92,7 +86,7 @@ struct Import {
Global GlobalImport;
Table TableImport;
Limits Memory;
- Tag TagImport;
+ uint32_t TagIndex;
};
};
@@ -329,7 +323,7 @@ struct TagSection : Section {
return S->Type == wasm::WASM_SEC_TAG;
}
- std::vector<Tag> Tags;
+ std::vector<uint32_t> TagTypes;
};
struct GlobalSection : Section {
@@ -431,7 +425,6 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
-LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Tag)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DylinkExport)
namespace llvm {
@@ -577,10 +570,6 @@ template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
};
-template <> struct MappingTraits<WasmYAML::Tag> {
- static void mapping(IO &IO, WasmYAML::Tag &Tag);
-};
-
template <> struct MappingTraits<WasmYAML::DylinkExport> {
static void mapping(IO &IO, WasmYAML::DylinkExport &Export);
};
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 25400c3..707a3f6 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -317,7 +317,7 @@ private:
uint32_t writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout,
ArrayRef<WasmFunction> Functions);
uint32_t writeDataSection(const MCAsmLayout &Layout);
- void writeTagSection(ArrayRef<wasm::WasmTagType> Tags);
+ void writeTagSection(ArrayRef<uint32_t> TagTypes);
void writeGlobalSection(ArrayRef<wasm::WasmGlobal> Globals);
void writeTableSection(ArrayRef<wasm::WasmTable> Tables);
void writeRelocSection(uint32_t SectionIndex, StringRef Name,
@@ -831,8 +831,8 @@ void WasmObjectWriter::writeImportSection(ArrayRef<wasm::WasmImport> Imports,
encodeULEB128(NumElements, W->OS); // initial
break;
case wasm::WASM_EXTERNAL_TAG:
- W->OS << char(Import.Tag.Attribute);
- encodeULEB128(Import.Tag.SigIndex, W->OS);
+ W->OS << char(0); // Reserved 'attribute' field
+ encodeULEB128(Import.SigIndex, W->OS);
break;
default:
llvm_unreachable("unsupported import kind");
@@ -856,17 +856,17 @@ void WasmObjectWriter::writeFunctionSection(ArrayRef<WasmFunction> Functions) {
endSection(Section);
}
-void WasmObjectWriter::writeTagSection(ArrayRef<wasm::WasmTagType> Tags) {
- if (Tags.empty())
+void WasmObjectWriter::writeTagSection(ArrayRef<uint32_t> TagTypes) {
+ if (TagTypes.empty())
return;
SectionBookkeeping Section;
startSection(Section, wasm::WASM_SEC_TAG);
- encodeULEB128(Tags.size(), W->OS);
- for (const wasm::WasmTagType &Tag : Tags) {
- W->OS << char(Tag.Attribute);
- encodeULEB128(Tag.SigIndex, W->OS);
+ encodeULEB128(TagTypes.size(), W->OS);
+ for (uint32_t Index : TagTypes) {
+ W->OS << char(0); // Reserved 'attribute' field
+ encodeULEB128(Index, W->OS);
}
endSection(Section);
@@ -1346,8 +1346,7 @@ void WasmObjectWriter::prepareImports(
Import.Module = WS.getImportModule();
Import.Field = WS.getImportName();
Import.Kind = wasm::WASM_EXTERNAL_TAG;
- Import.Tag.Attribute = wasm::WASM_TAG_ATTRIBUTE_EXCEPTION;
- Import.Tag.SigIndex = getTagType(WS);
+ Import.SigIndex = getTagType(WS);
Imports.push_back(Import);
assert(WasmIndices.count(&WS) == 0);
WasmIndices[&WS] = NumTagImports++;
@@ -1415,7 +1414,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
SmallVector<uint32_t, 4> TableElems;
SmallVector<wasm::WasmImport, 4> Imports;
SmallVector<wasm::WasmExport, 4> Exports;
- SmallVector<wasm::WasmTagType, 1> Tags;
+ SmallVector<uint32_t, 2> TagTypes;
SmallVector<wasm::WasmGlobal, 1> Globals;
SmallVector<wasm::WasmTable, 1> Tables;
SmallVector<wasm::WasmSymbolInfo, 4> SymbolInfos;
@@ -1654,13 +1653,11 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
// (__c_longjmp)
unsigned Index;
if (WS.isDefined()) {
- Index = NumTagImports + Tags.size();
- wasm::WasmTagType Tag;
- Tag.SigIndex = getTagType(WS);
- Tag.Attribute = wasm::WASM_TAG_ATTRIBUTE_EXCEPTION;
+ Index = NumTagImports + TagTypes.size();
+ uint32_t SigIndex = getTagType(WS);
assert(WasmIndices.count(&WS) == 0);
WasmIndices[&WS] = Index;
- Tags.push_back(Tag);
+ TagTypes.push_back(SigIndex);
} else {
// An import; the index was assigned above.
assert(WasmIndices.count(&WS) > 0);
@@ -1878,7 +1875,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
writeFunctionSection(Functions);
writeTableSection(Tables);
// Skip the "memory" section; we import the memory instead.
- writeTagSection(Tags);
+ writeTagSection(TagTypes);
writeGlobalSection(Globals);
writeExportSection(Exports);
const MCSymbol *IndirectFunctionTable =
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 8dcd9af..a6a4748 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -582,7 +582,6 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
const wasm::WasmSignature *Signature = nullptr;
const wasm::WasmGlobalType *GlobalType = nullptr;
const wasm::WasmTableType *TableType = nullptr;
- const wasm::WasmTagType *TagType = nullptr;
Info.Kind = readUint8(Ctx);
Info.Flags = readVaruint32(Ctx);
@@ -727,8 +726,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
Info.Name = readString(Ctx);
unsigned TagIndex = Info.ElementIndex - NumImportedTags;
wasm::WasmTag &Tag = Tags[TagIndex];
- Signature = &Signatures[Tag.Type.SigIndex];
- TagType = &Tag.Type;
+ Signature = &Signatures[Tag.SigIndex];
if (Tag.SymbolName.empty())
Tag.SymbolName = Info.Name;
@@ -740,8 +738,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
} else {
Info.Name = Import.Field;
}
- TagType = &Import.Tag;
- Signature = &Signatures[TagType->SigIndex];
+ Signature = &Signatures[Import.SigIndex];
if (!Import.Module.empty()) {
Info.ImportModule = Import.Module;
}
@@ -763,7 +760,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
object_error::parse_failed);
LinkingData.SymbolTable.emplace_back(Info);
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType,
- TagType, Signature);
+ Signature);
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
}
@@ -1090,6 +1087,7 @@ Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) {
Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
uint32_t Count = readVaruint32(Ctx);
+ uint32_t NumTypes = Signatures.size();
Imports.reserve(Count);
for (uint32_t I = 0; I < Count; I++) {
wasm::WasmImport Im;
@@ -1100,6 +1098,9 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
case wasm::WASM_EXTERNAL_FUNCTION:
NumImportedFunctions++;
Im.SigIndex = readVaruint32(Ctx);
+ if (Im.SigIndex >= NumTypes)
+ return make_error<GenericBinaryError>("invalid function type",
+ object_error::parse_failed);
break;
case wasm::WASM_EXTERNAL_GLOBAL:
NumImportedGlobals++;
@@ -1123,8 +1124,10 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
}
case wasm::WASM_EXTERNAL_TAG:
NumImportedTags++;
- Im.Tag.Attribute = readUint8(Ctx);
- Im.Tag.SigIndex = readVarint32(Ctx);
+ Im.SigIndex = readVaruint32(Ctx);
+ if (Im.SigIndex >= NumTypes)
+ return make_error<GenericBinaryError>("invalid tag type",
+ object_error::parse_failed);
break;
default:
return make_error<GenericBinaryError>("unexpected import kind",
@@ -1198,11 +1201,19 @@ Error WasmObjectFile::parseTagSection(ReadContext &Ctx) {
TagSection = Sections.size();
uint32_t Count = readVaruint32(Ctx);
Tags.reserve(Count);
+ uint32_t NumTypes = Signatures.size();
while (Count--) {
+ char Attr = readUint8(Ctx); // Reserved 'attribute' field
+ if (Attr != 0)
+ return make_error<GenericBinaryError>("invalid attribute",
+ object_error::parse_failed);
+ uint32_t Type = readVaruint32(Ctx);
+ if (Type >= NumTypes)
+ return make_error<GenericBinaryError>("invalid tag type",
+ object_error::parse_failed);
wasm::WasmTag Tag;
Tag.Index = NumImportedTags + Tags.size();
- Tag.Type.Attribute = readUint8(Ctx);
- Tag.Type.SigIndex = readVaruint32(Ctx);
+ Tag.SigIndex = Type;
Tags.push_back(Tag);
}
diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp
index 86d4bc0..80a8c56 100644
--- a/llvm/lib/ObjectYAML/WasmEmitter.cpp
+++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp
@@ -397,8 +397,8 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
NumImportedGlobals++;
break;
case wasm::WASM_EXTERNAL_TAG:
- writeUint32(OS, Import.TagImport.Attribute);
- writeUint32(OS, Import.TagImport.SigIndex);
+ writeUint8(OS, 0); // Reserved 'attribute' field
+ encodeULEB128(Import.SigIndex, OS);
NumImportedTags++;
break;
case wasm::WASM_EXTERNAL_MEMORY:
@@ -462,16 +462,10 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
void WasmWriter::writeSectionContent(raw_ostream &OS,
WasmYAML::TagSection &Section) {
- encodeULEB128(Section.Tags.size(), OS);
- uint32_t ExpectedIndex = NumImportedTags;
- for (auto &Tag : Section.Tags) {
- if (Tag.Index != ExpectedIndex) {
- reportError("unexpected tag index: " + Twine(Tag.Index));
- return;
- }
- ++ExpectedIndex;
- encodeULEB128(Tag.Attribute, OS);
- encodeULEB128(Tag.SigIndex, OS);
+ encodeULEB128(Section.TagTypes.size(), OS);
+ for (uint32_t TagType : Section.TagTypes) {
+ writeUint8(OS, 0); // Reserved 'attribute' field
+ encodeULEB128(TagType, OS);
}
}
diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp
index 133a2bc..f84a809 100644
--- a/llvm/lib/ObjectYAML/WasmYAML.cpp
+++ b/llvm/lib/ObjectYAML/WasmYAML.cpp
@@ -123,7 +123,7 @@ static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) {
static void sectionMapping(IO &IO, WasmYAML::TagSection &Section) {
commonSectionMapping(IO, Section);
- IO.mapOptional("Tags", Section.Tags);
+ IO.mapOptional("TagTypes", Section.TagTypes);
}
static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) {
@@ -392,14 +392,12 @@ void MappingTraits<WasmYAML::Import>::mapping(IO &IO,
IO.mapRequired("Module", Import.Module);
IO.mapRequired("Field", Import.Field);
IO.mapRequired("Kind", Import.Kind);
- if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
+ if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION ||
+ Import.Kind == wasm::WASM_EXTERNAL_TAG) {
IO.mapRequired("SigIndex", Import.SigIndex);
} else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
IO.mapRequired("GlobalType", Import.GlobalImport.Type);
IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable);
- } else if (Import.Kind == wasm::WASM_EXTERNAL_TAG) {
- IO.mapRequired("TagAttribute", Import.TagImport.Attribute);
- IO.mapRequired("TagSigIndex", Import.TagImport.SigIndex);
} else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) {
IO.mapRequired("Table", Import.TableImport);
} else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) {
@@ -526,12 +524,6 @@ void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
}
}
-void MappingTraits<WasmYAML::Tag>::mapping(IO &IO, WasmYAML::Tag &Tag) {
- IO.mapRequired("Index", Tag.Index);
- IO.mapRequired("Attribute", Tag.Attribute);
- IO.mapRequired("SigIndex", Tag.SigIndex);
-}
-
void MappingTraits<WasmYAML::DylinkExport>::mapping(
IO &IO, WasmYAML::DylinkExport &Export) {
IO.mapRequired("Name", Export.Name);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 17a9f3ea8..91d480e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -238,10 +238,6 @@ MCSymbol *WebAssemblyAsmPrinter::getOrCreateWasmSymbol(StringRef Name) {
SmallVector<wasm::ValType, 4> Params;
if (Name == "__cpp_exception" || Name == "__c_longjmp") {
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TAG);
- // We can't confirm its signature index for now because there can be
- // imported exceptions. Set it to be 0 for now.
- WasmSym->setTagType(
- {wasm::WASM_TAG_ATTRIBUTE_EXCEPTION, /* SigIndex */ 0});
// We may have multiple C++ compilation units to be linked together, each of
// which defines the exception symbol. To resolve them, we declare them as
// weak.
diff --git a/llvm/test/MC/WebAssembly/tag-section-decoding.ll b/llvm/test/MC/WebAssembly/tag-section-decoding.ll
index 111d5ec..605cae8 100644
--- a/llvm/test/MC/WebAssembly/tag-section-decoding.ll
+++ b/llvm/test/MC/WebAssembly/tag-section-decoding.ll
@@ -339,7 +339,4 @@ define i32 @test_throw(i8* %p) {
; number with which its LEB128 and ULEB128 encodings are different, because its
; 7th least significant bit is not 0.
; CHECK: - Type: TAG
-; CHECK-NEXT: Tags:
-; CHECK-NEXT: - Index: 0
-; CHECK-NEXT: Attribute: 0
-; CHECK-NEXT: SigIndex: 64
+; CHEC-NEXT: TagTypes: [ 64 ]
diff --git a/llvm/test/MC/WebAssembly/tag-section.ll b/llvm/test/MC/WebAssembly/tag-section.ll
index 0514a59..d9eb62d 100644
--- a/llvm/test/MC/WebAssembly/tag-section.ll
+++ b/llvm/test/MC/WebAssembly/tag-section.ll
@@ -29,10 +29,7 @@ define i32 @test_throw1(i8* %p) {
; CHECK-NEXT: ReturnTypes: []
; CHECK: - Type: TAG
-; CHECK-NEXT: Tags:
-; CHECK-NEXT: - Index: 0
-; CHECK-NEXT: Attribute: 0
-; CHECK-NEXT: SigIndex: 1
+; CHECK-NEXT: TagTypes: [ 1 ]
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Relocations:
diff --git a/llvm/test/ObjectYAML/wasm/event_section.yaml b/llvm/test/ObjectYAML/wasm/event_section.yaml
index 2eeaa73..55e28d1 100644
--- a/llvm/test/ObjectYAML/wasm/event_section.yaml
+++ b/llvm/test/ObjectYAML/wasm/event_section.yaml
@@ -18,10 +18,7 @@ Sections:
- Type: FUNCTION
FunctionTypes: [ 0 ]
- Type: TAG
- Tags:
- - Index: 0
- Attribute: 0
- SigIndex: 1
+ TagTypes: [ 1 ]
- Type: CODE
Relocations:
- Type: R_WASM_TAG_INDEX_LEB
@@ -68,10 +65,7 @@ Sections:
# CHECK-NEXT: - Type: FUNCTION
# CHECK-NEXT: FunctionTypes: [ 0 ]
# CHECK-NEXT: - Type: TAG
-# CHECK-NEXT: Tags:
-# CHECK-NEXT: - Index: 0
-# CHECK-NEXT: Attribute: 0
-# CHECK-NEXT: SigIndex: 1
+# CHECK-NEXT: TagTypes: [ 1 ]
# CHECK-NEXT: - Type: CODE
# CHECK-NEXT: Relocations:
# CHECK-NEXT: - Type: R_WASM_TAG_INDEX_LEB
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index 61a48c5..189ca0b 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -241,8 +241,7 @@ ErrorOr<WasmYAML::Object *> WasmDumper::dump() {
Im.GlobalImport.Mutable = Import.Global.Mutable;
break;
case wasm::WASM_EXTERNAL_TAG:
- Im.TagImport.Attribute = Import.Tag.Attribute;
- Im.TagImport.SigIndex = Import.Tag.SigIndex;
+ Im.SigIndex = Import.SigIndex;
break;
case wasm::WASM_EXTERNAL_TABLE:
// FIXME: Currently we always output an index of 0 for any imported
@@ -285,11 +284,7 @@ ErrorOr<WasmYAML::Object *> WasmDumper::dump() {
case wasm::WASM_SEC_TAG: {
auto TagSec = std::make_unique<WasmYAML::TagSection>();
for (auto &Tag : Obj.tags()) {
- WasmYAML::Tag T;
- T.Index = Tag.Index;
- T.Attribute = Tag.Type.Attribute;
- T.SigIndex = Tag.Type.SigIndex;
- TagSec->Tags.push_back(T);
+ TagSec->TagTypes.push_back(Tag.SigIndex);
}
S = std::move(TagSec);
break;