Skip to content

Commit b17a74b

Browse files
aheejinmemfrob
authored andcommitted
[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
1 parent 47d0d67 commit b17a74b

File tree

23 files changed

+68
-165
lines changed

23 files changed

+68
-165
lines changed

lld/include/lld/Common/LLVM.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class WasmSymbol;
4545

4646
namespace wasm {
4747
struct WasmTag;
48-
struct WasmTagType;
4948
struct WasmFunction;
5049
struct WasmGlobal;
5150
struct WasmGlobalType;
@@ -97,7 +96,6 @@ using llvm::wasm::WasmSignature;
9796
using llvm::wasm::WasmTable;
9897
using llvm::wasm::WasmTableType;
9998
using llvm::wasm::WasmTag;
100-
using llvm::wasm::WasmTagType;
10199
} // end namespace lld.
102100

103101
namespace std {

lld/test/wasm/tag-section.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ define void @_start() {
3030
; CHECK-NEXT: ReturnTypes: []
3131

3232
; CHECK: - Type: TAG
33-
; CHECK-NEXT: Tags:
34-
; CHECK-NEXT: - Index: 0
35-
; CHECK-NEXT: Attribute: 0
36-
; CHECK-NEXT: SigIndex: 1
33+
; CHECK-NEXT: TagTypes: [ 1 ]
3734

3835
; Global section has to come after tag section
3936
; CHECK: - Type: GLOBAL

lld/wasm/InputElement.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ class InputGlobal : public InputElement {
7474
class InputTag : public InputElement {
7575
public:
7676
InputTag(const WasmSignature &s, const WasmTag &t, ObjFile *f)
77-
: InputElement(t.SymbolName, f), signature(s), type(t.Type) {}
78-
79-
const WasmTagType &getType() const { return type; }
77+
: InputElement(t.SymbolName, f), signature(s) {}
8078

8179
const WasmSignature &signature;
82-
83-
private:
84-
WasmTagType type;
8580
};
8681

8782
class InputTable : public InputElement {

lld/wasm/InputFiles.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,9 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
336336
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info->Name
337337
<< "\n");
338338
const WasmGlobalType *globalType = nullptr;
339-
const WasmTagType *tagType = nullptr;
340339
const WasmSignature *signature = nullptr;
341-
auto *wasmSym = make<WasmSymbol>(*info, globalType, &tableImport->Table,
342-
tagType, signature);
340+
auto *wasmSym =
341+
make<WasmSymbol>(*info, globalType, &tableImport->Table, signature);
343342
Symbol *sym = createUndefined(*wasmSym, false);
344343
// We're only sure it's a TableSymbol if the createUndefined succeeded.
345344
if (errorCount())
@@ -516,7 +515,7 @@ void ObjFile::parse(bool ignoreComdats) {
516515

517516
// Populate `Tags`.
518517
for (const WasmTag &t : wasmObj->tags())
519-
tags.emplace_back(make<InputTag>(types[t.Type.SigIndex], t, this));
518+
tags.emplace_back(make<InputTag>(types[t.SigIndex], t, this));
520519

521520
// Populate `Symbols` based on the symbols in the object.
522521
symbols.reserve(wasmObj->getNumberOfSymbols());

lld/wasm/SymbolTable.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,14 @@ static void checkGlobalType(const Symbol *existing, const InputFile *file,
169169
}
170170

171171
static void checkTagType(const Symbol *existing, const InputFile *file,
172-
const WasmTagType *newType,
173172
const WasmSignature *newSig) {
174173
const auto *existingTag = dyn_cast<TagSymbol>(existing);
175174
if (!isa<TagSymbol>(existing)) {
176175
reportTypeError(existing, file, WASM_SYMBOL_TYPE_TAG);
177176
return;
178177
}
179178

180-
const WasmTagType *oldType = cast<TagSymbol>(existing)->getTagType();
181179
const WasmSignature *oldSig = existingTag->signature;
182-
if (newType->Attribute != oldType->Attribute)
183-
error("Tag type mismatch: " + existing->getName() + "\n>>> defined as " +
184-
toString(*oldType) + " in " + toString(existing->getFile()) +
185-
"\n>>> defined as " + toString(*newType) + " in " + toString(file));
186180
if (*newSig != *oldSig)
187181
warn("Tag signature mismatch: " + existing->getName() +
188182
"\n>>> defined as " + toString(*oldSig) + " in " +
@@ -430,7 +424,7 @@ Symbol *SymbolTable::addDefinedTag(StringRef name, uint32_t flags,
430424
return s;
431425
}
432426

433-
checkTagType(s, file, &tag->getType(), &tag->signature);
427+
checkTagType(s, file, &tag->signature);
434428

435429
if (shouldReplace(s, file, flags))
436430
replaceSym();

lld/wasm/Symbols.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ bool TagSymbol::hasTagIndex() const {
369369
DefinedTag::DefinedTag(StringRef name, uint32_t flags, InputFile *file,
370370
InputTag *tag)
371371
: TagSymbol(name, DefinedTagKind, flags, file,
372-
tag ? &tag->getType() : nullptr,
373372
tag ? &tag->signature : nullptr),
374373
tag(tag) {}
375374

lld/wasm/Symbols.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,6 @@ class TagSymbol : public Symbol {
439439
public:
440440
static bool classof(const Symbol *s) { return s->kind() == DefinedTagKind; }
441441

442-
const WasmTagType *getTagType() const { return tagType; }
443-
444442
// Get/set the tag index
445443
uint32_t getTagIndex() const;
446444
void setTagIndex(uint32_t index);
@@ -450,10 +448,9 @@ class TagSymbol : public Symbol {
450448

451449
protected:
452450
TagSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f,
453-
const WasmTagType *tagType, const WasmSignature *sig)
454-
: Symbol(name, k, flags, f), signature(sig), tagType(tagType) {}
451+
const WasmSignature *sig)
452+
: Symbol(name, k, flags, f), signature(sig) {}
455453

456-
const WasmTagType *tagType;
457454
uint32_t tagIndex = INVALID_INDEX;
458455
};
459456

lld/wasm/SyntheticSections.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ void ImportSection::writeBody() {
226226
import.Global = *globalSym->getGlobalType();
227227
} else if (auto *tagSym = dyn_cast<TagSymbol>(sym)) {
228228
import.Kind = WASM_EXTERNAL_TAG;
229-
import.Tag.Attribute = tagSym->getTagType()->Attribute;
230-
import.Tag.SigIndex = out.typeSec->lookupType(*tagSym->signature);
229+
import.SigIndex = out.typeSec->lookupType(*tagSym->signature);
231230
} else {
232231
auto *tableSym = cast<TableSymbol>(sym);
233232
import.Kind = WASM_EXTERNAL_TABLE;
@@ -332,9 +331,8 @@ void TagSection::writeBody() {
332331

333332
writeUleb128(os, inputTags.size(), "tag count");
334333
for (InputTag *t : inputTags) {
335-
WasmTagType type = t->getType();
336-
type.SigIndex = out.typeSec->lookupType(t->signature);
337-
writeTagType(os, type);
334+
writeUleb128(os, 0, "tag attribute"); // Reserved "attribute" field
335+
writeUleb128(os, out.typeSec->lookupType(t->signature), "sig index");
338336
}
339337
}
340338

lld/wasm/WriterUtils.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ std::string toString(const WasmGlobalType &type) {
5858
toString(static_cast<ValType>(type.Type));
5959
}
6060

61-
std::string toString(const WasmTagType &type) {
62-
if (type.Attribute == WASM_TAG_ATTRIBUTE_EXCEPTION)
63-
return "exception";
64-
return "unknown";
65-
}
66-
6761
static std::string toString(const llvm::wasm::WasmLimits &limits) {
6862
std::string ret;
6963
ret += "flags=0x" + std::to_string(limits.Flags);
@@ -204,15 +198,6 @@ void writeGlobalType(raw_ostream &os, const WasmGlobalType &type) {
204198
writeU8(os, type.Mutable, "global mutable");
205199
}
206200

207-
void writeTagType(raw_ostream &os, const WasmTagType &type) {
208-
writeUleb128(os, type.Attribute, "tag attribute");
209-
writeUleb128(os, type.SigIndex, "sig index");
210-
}
211-
212-
void writeTag(raw_ostream &os, const WasmTag &tag) {
213-
writeTagType(os, tag.Type);
214-
}
215-
216201
void writeTableType(raw_ostream &os, const WasmTableType &type) {
217202
writeValueType(os, ValType(type.ElemType), "table type");
218203
writeLimits(os, type.Limits);
@@ -230,7 +215,8 @@ void writeImport(raw_ostream &os, const WasmImport &import) {
230215
writeGlobalType(os, import.Global);
231216
break;
232217
case WASM_EXTERNAL_TAG:
233-
writeTagType(os, import.Tag);
218+
writeUleb128(os, 0, "tag attribute"); // Reserved "attribute" field
219+
writeUleb128(os, import.SigIndex, "import sig index");
234220
break;
235221
case WASM_EXTERNAL_MEMORY:
236222
writeLimits(os, import.Memory);

lld/wasm/WriterUtils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ void writeLimits(raw_ostream &os, const llvm::wasm::WasmLimits &limits);
5555

5656
void writeGlobalType(raw_ostream &os, const llvm::wasm::WasmGlobalType &type);
5757

58-
void writeTagType(raw_ostream &os, const llvm::wasm::WasmTagType &type);
59-
60-
void writeTag(raw_ostream &os, const llvm::wasm::WasmTag &tag);
61-
6258
void writeTableType(raw_ostream &os, const llvm::wasm::WasmTableType &type);
6359

6460
void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import);
@@ -70,7 +66,6 @@ void writeExport(raw_ostream &os, const llvm::wasm::WasmExport &export_);
7066
std::string toString(llvm::wasm::ValType type);
7167
std::string toString(const llvm::wasm::WasmSignature &sig);
7268
std::string toString(const llvm::wasm::WasmGlobalType &type);
73-
std::string toString(const llvm::wasm::WasmTagType &type);
7469
std::string toString(const llvm::wasm::WasmTableType &type);
7570

7671
} // namespace lld

0 commit comments

Comments
 (0)