Skip to content

Commit

Permalink
[WebAssembly] Rename event to tag
Browse files Browse the repository at this point in the history
We recently decided to change 'event' to 'tag', and 'event section' to
'tag section', out of the rationale that the section contains a
generalized tag that references a type, which may be used for something
other than exceptions, and the name 'event' can be confusing in the web
context.

See
- WebAssembly/exception-handling#159 (comment)
- WebAssembly/exception-handling#161

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D104423
  • Loading branch information
aheejin authored and arichardson committed Sep 13, 2021
2 parents 6cfc3ba + 1d891d4 commit d9ec2f0
Show file tree
Hide file tree
Showing 52 changed files with 440 additions and 444 deletions.
8 changes: 4 additions & 4 deletions lld/include/lld/Common/LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class WasmSymbol;
} // namespace object

namespace wasm {
struct WasmEvent;
struct WasmEventType;
struct WasmTag;
struct WasmTagType;
struct WasmFunction;
struct WasmGlobal;
struct WasmGlobalType;
Expand Down Expand Up @@ -87,8 +87,6 @@ using llvm::object::WasmObjectFile;
using llvm::object::WasmSection;
using llvm::object::WasmSegment;
using llvm::object::WasmSymbol;
using llvm::wasm::WasmEvent;
using llvm::wasm::WasmEventType;
using llvm::wasm::WasmFunction;
using llvm::wasm::WasmGlobal;
using llvm::wasm::WasmGlobalType;
Expand All @@ -98,6 +96,8 @@ using llvm::wasm::WasmRelocation;
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 {
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions lld/test/wasm/event-section.ll → lld/test/wasm/tag-section.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/event-section1.ll -o %t1.o
; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/event-section2.ll -o %t2.o
; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/tag-section1.ll -o %t1.o
; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/tag-section2.ll -o %t2.o
; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %s -o %t.o
; RUN: wasm-ld -o %t.wasm %t.o %t1.o %t2.o
; RUN: wasm-ld --export-all -o %t-export-all.wasm %t.o %t1.o %t2.o
Expand Down Expand Up @@ -29,17 +29,17 @@ define void @_start() {
; CHECK-NEXT: - I32
; CHECK-NEXT: ReturnTypes: []

; CHECK: - Type: EVENT
; CHECK-NEXT: Events:
; CHECK: - Type: TAG
; CHECK-NEXT: Tags:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Attribute: 0
; CHECK-NEXT: SigIndex: 1

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

; EXPORT-ALL: - Type: EXPORT
; EXPORT-ALL-NEXT Exports:
; EXPORT-ALL: - Name: __cpp_exception
; EXPORT-ALL: Kind: EVENT
; EXPORT-ALL: Kind: TAG
; EXPORT-ALL: Index: 0
6 changes: 3 additions & 3 deletions lld/wasm/InputChunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void InputChunk::relocate(uint8_t *buf) const {
case R_WASM_TYPE_INDEX_LEB:
case R_WASM_FUNCTION_INDEX_LEB:
case R_WASM_GLOBAL_INDEX_LEB:
case R_WASM_EVENT_INDEX_LEB:
case R_WASM_TAG_INDEX_LEB:
case R_WASM_MEMORY_ADDR_LEB:
case R_WASM_TABLE_NUMBER_LEB:
encodeULEB128(value, loc, 5);
Expand Down Expand Up @@ -208,7 +208,7 @@ static unsigned writeCompressedReloc(uint8_t *buf, const WasmRelocation &rel,
case R_WASM_TYPE_INDEX_LEB:
case R_WASM_FUNCTION_INDEX_LEB:
case R_WASM_GLOBAL_INDEX_LEB:
case R_WASM_EVENT_INDEX_LEB:
case R_WASM_TAG_INDEX_LEB:
case R_WASM_MEMORY_ADDR_LEB:
case R_WASM_MEMORY_ADDR_LEB64:
case R_WASM_TABLE_NUMBER_LEB:
Expand All @@ -228,7 +228,7 @@ static unsigned getRelocWidthPadded(const WasmRelocation &rel) {
case R_WASM_TYPE_INDEX_LEB:
case R_WASM_FUNCTION_INDEX_LEB:
case R_WASM_GLOBAL_INDEX_LEB:
case R_WASM_EVENT_INDEX_LEB:
case R_WASM_TAG_INDEX_LEB:
case R_WASM_MEMORY_ADDR_LEB:
case R_WASM_TABLE_NUMBER_LEB:
case R_WASM_TABLE_INDEX_SLEB:
Expand Down
12 changes: 6 additions & 6 deletions lld/wasm/InputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace lld {
namespace wasm {

// Represents a single element (Global, Event, Table, etc) within an input
// Represents a single element (Global, Tag, Table, etc) within an input
// file.
class InputElement {
protected:
Expand Down Expand Up @@ -71,17 +71,17 @@ class InputGlobal : public InputElement {
WasmInitExpr initExpr;
};

class InputEvent : public InputElement {
class InputTag : public InputElement {
public:
InputEvent(const WasmSignature &s, const WasmEvent &e, ObjFile *f)
: InputElement(e.SymbolName, f), signature(s), type(e.Type) {}
InputTag(const WasmSignature &s, const WasmTag &t, ObjFile *f)
: InputElement(t.SymbolName, f), signature(s), type(t.Type) {}

const WasmEventType &getType() const { return type; }
const WasmTagType &getType() const { return type; }

const WasmSignature &signature;

private:
WasmEventType type;
WasmTagType type;
};

class InputTable : public InputElement {
Expand Down
29 changes: 14 additions & 15 deletions lld/wasm/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ObjFile::dumpInfo() const {
"\n Symbols : " + Twine(symbols.size()) +
"\n Function Imports : " + Twine(wasmObj->getNumImportedFunctions()) +
"\n Global Imports : " + Twine(wasmObj->getNumImportedGlobals()) +
"\n Event Imports : " + Twine(wasmObj->getNumImportedEvents()) +
"\n Tag Imports : " + Twine(wasmObj->getNumImportedTags()) +
"\n Table Imports : " + Twine(wasmObj->getNumImportedTables()));
}

Expand Down Expand Up @@ -209,8 +209,8 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
if (auto gs = dyn_cast<GlobalSymbol>(sym))
return gs->getGlobalIndex();
return sym->getGOTIndex();
case R_WASM_EVENT_INDEX_LEB:
return getEventSymbol(reloc.Index)->getEventIndex();
case R_WASM_TAG_INDEX_LEB:
return getTagSymbol(reloc.Index)->getTagIndex();
case R_WASM_FUNCTION_OFFSET_I32:
case R_WASM_FUNCTION_OFFSET_I64: {
auto *f = cast<DefinedFunction>(sym);
Expand Down Expand Up @@ -343,10 +343,10 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info->Name
<< "\n");
const WasmGlobalType *globalType = nullptr;
const WasmEventType *eventType = nullptr;
const WasmTagType *tagType = nullptr;
const WasmSignature *signature = nullptr;
auto *wasmSym = make<WasmSymbol>(*info, globalType, &tableImport->Table,
eventType, signature);
tagType, signature);
Symbol *sym = createUndefined(*wasmSym, false);
// We're only sure it's a TableSymbol if the createUndefined succeeded.
if (errorCount())
Expand Down Expand Up @@ -515,9 +515,9 @@ void ObjFile::parse(bool ignoreComdats) {
for (const WasmGlobal &g : wasmObj->globals())
globals.emplace_back(make<InputGlobal>(g, this));

// Populate `Events`.
for (const WasmEvent &e : wasmObj->events())
events.emplace_back(make<InputEvent>(types[e.Type.SigIndex], e, this));
// Populate `Tags`.
for (const WasmTag &t : wasmObj->tags())
tags.emplace_back(make<InputTag>(types[t.Type.SigIndex], t, this));

// Populate `Symbols` based on the symbols in the object.
symbols.reserve(wasmObj->getNumberOfSymbols());
Expand Down Expand Up @@ -556,8 +556,8 @@ GlobalSymbol *ObjFile::getGlobalSymbol(uint32_t index) const {
return cast<GlobalSymbol>(symbols[index]);
}

EventSymbol *ObjFile::getEventSymbol(uint32_t index) const {
return cast<EventSymbol>(symbols[index]);
TagSymbol *ObjFile::getTagSymbol(uint32_t index) const {
return cast<TagSymbol>(symbols[index]);
}

TableSymbol *ObjFile::getTableSymbol(uint32_t index) const {
Expand Down Expand Up @@ -612,12 +612,11 @@ Symbol *ObjFile::createDefined(const WasmSymbol &sym) {
return nullptr;
return make<SectionSymbol>(flags, section, this);
}
case WASM_SYMBOL_TYPE_EVENT: {
InputEvent *event =
events[sym.Info.ElementIndex - wasmObj->getNumImportedEvents()];
case WASM_SYMBOL_TYPE_TAG: {
InputTag *tag = tags[sym.Info.ElementIndex - wasmObj->getNumImportedTags()];
if (sym.isBindingLocal())
return make<DefinedEvent>(name, flags, this, event);
return symtab->addDefinedEvent(name, flags, this, event);
return make<DefinedTag>(name, flags, this, tag);
return symtab->addDefinedTag(name, flags, this, tag);
}
case WASM_SYMBOL_TYPE_TABLE: {
InputTable *table =
Expand Down
6 changes: 3 additions & 3 deletions lld/wasm/InputFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InputChunk;
class InputFunction;
class InputSegment;
class InputGlobal;
class InputEvent;
class InputTag;
class InputTable;
class InputSection;

Expand Down Expand Up @@ -139,7 +139,7 @@ class ObjFile : public InputFile {
std::vector<InputChunk *> segments;
std::vector<InputFunction *> functions;
std::vector<InputGlobal *> globals;
std::vector<InputEvent *> events;
std::vector<InputTag *> tags;
std::vector<InputTable *> tables;
std::vector<InputChunk *> customSections;
llvm::DenseMap<uint32_t, InputChunk *> customSectionsByIndex;
Expand All @@ -149,7 +149,7 @@ class ObjFile : public InputFile {
DataSymbol *getDataSymbol(uint32_t index) const;
GlobalSymbol *getGlobalSymbol(uint32_t index) const;
SectionSymbol *getSectionSymbol(uint32_t index) const;
EventSymbol *getEventSymbol(uint32_t index) const;
TagSymbol *getTagSymbol(uint32_t index) const;
TableSymbol *getTableSymbol(uint32_t index) const;

private:
Expand Down
6 changes: 3 additions & 3 deletions lld/wasm/MarkLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ void markLive() {
for (InputGlobal *g : obj->globals)
if (!g->live)
message("removing unused section " + toString(g));
for (InputEvent *e : obj->events)
if (!e->live)
message("removing unused section " + toString(e));
for (InputTag *t : obj->tags)
if (!t->live)
message("removing unused section " + toString(t));
for (InputTable *t : obj->tables)
if (!t->live)
message("removing unused section " + toString(t));
Expand Down
4 changes: 2 additions & 2 deletions lld/wasm/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static StringRef sectionTypeToString(uint32_t sectionType) {
return "MEMORY";
case WASM_SEC_GLOBAL:
return "GLOBAL";
case WASM_SEC_EVENT:
return "EVENT";
case WASM_SEC_TAG:
return "TAG";
case WASM_SEC_EXPORT:
return "EXPORT";
case WASM_SEC_START:
Expand Down
30 changes: 15 additions & 15 deletions lld/wasm/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ static void checkGlobalType(const Symbol *existing, const InputFile *file,
}
}

static void checkEventType(const Symbol *existing, const InputFile *file,
const WasmEventType *newType,
const WasmSignature *newSig) {
auto existingEvent = dyn_cast<EventSymbol>(existing);
if (!isa<EventSymbol>(existing)) {
reportTypeError(existing, file, WASM_SYMBOL_TYPE_EVENT);
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)) {
reportTypeError(existing, file, WASM_SYMBOL_TYPE_TAG);
return;
}

const WasmEventType *oldType = cast<EventSymbol>(existing)->getEventType();
const WasmSignature *oldSig = existingEvent->signature;
const WasmTagType *oldType = cast<TagSymbol>(existing)->getTagType();
const WasmSignature *oldSig = existingTag->signature;
if (newType->Attribute != oldType->Attribute)
error("Event type mismatch: " + existing->getName() + "\n>>> defined as " +
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("Event signature mismatch: " + existing->getName() +
warn("Tag signature mismatch: " + existing->getName() +
"\n>>> defined as " + toString(*oldSig) + " in " +
toString(existing->getFile()) + "\n>>> defined as " +
toString(*newSig) + " in " + toString(file));
Expand Down Expand Up @@ -413,24 +413,24 @@ Symbol *SymbolTable::addDefinedGlobal(StringRef name, uint32_t flags,
return s;
}

Symbol *SymbolTable::addDefinedEvent(StringRef name, uint32_t flags,
InputFile *file, InputEvent *event) {
LLVM_DEBUG(dbgs() << "addDefinedEvent:" << name << "\n");
Symbol *SymbolTable::addDefinedTag(StringRef name, uint32_t flags,
InputFile *file, InputTag *tag) {
LLVM_DEBUG(dbgs() << "addDefinedTag:" << name << "\n");

Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(name, file);

auto replaceSym = [&]() {
replaceSymbol<DefinedEvent>(s, name, flags, file, event);
replaceSymbol<DefinedTag>(s, name, flags, file, tag);
};

if (wasInserted || s->isLazy()) {
replaceSym();
return s;
}

checkEventType(s, file, &event->getType(), &event->signature);
checkTagType(s, file, &tag->getType(), &tag->signature);

if (shouldReplace(s, file, flags))
replaceSym();
Expand Down
4 changes: 2 additions & 2 deletions lld/wasm/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class SymbolTable {
InputChunk *segment, uint64_t address, uint64_t size);
Symbol *addDefinedGlobal(StringRef name, uint32_t flags, InputFile *file,
InputGlobal *g);
Symbol *addDefinedEvent(StringRef name, uint32_t flags, InputFile *file,
InputEvent *e);
Symbol *addDefinedTag(StringRef name, uint32_t flags, InputFile *file,
InputTag *t);
Symbol *addDefinedTable(StringRef name, uint32_t flags, InputFile *file,
InputTable *t);

Expand Down
Loading

0 comments on commit d9ec2f0

Please sign in to comment.