[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
This commit is contained in:
Heejin Ahn 2021-10-01 19:07:41 -07:00
parent d51f57c23c
commit 3ec1760d91
23 changed files with 68 additions and 165 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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());

View File

@ -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();

View File

@ -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) {}

View File

@ -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;
};

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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

View File

@ -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;
};
};

View File

@ -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

View File

@ -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;

View File

@ -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);
};

View File

@ -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 =

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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.

View File

@ -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 ]

View File

@ -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:

View File

@ -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

View File

@ -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;