-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Add support for the event section
Summary: This adds support for the 'event section' specified in the exception handling proposal. Wasm exception handling binary model spec: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model Reviewers: sbc100, ruiu Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54875 llvm-svn: 348703
- Loading branch information
Showing
19 changed files
with
401 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
| target triple = "wasm32-unknown-unknown" | ||
|
|
||
| declare void @llvm.wasm.throw(i32, i8*) | ||
|
|
||
| define void @foo(i8* %p) { | ||
| call void @llvm.wasm.throw(i32 0, i8* %p) | ||
| ret void | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
| target triple = "wasm32-unknown-unknown" | ||
|
|
||
| declare void @llvm.wasm.throw(i32, i8*) | ||
|
|
||
| define void @bar(i8* %p) { | ||
| call void @llvm.wasm.throw(i32 0, i8* %p) | ||
| ret void | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ; 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 %s -o %t.o | ||
| ; RUN: wasm-ld -o %t.wasm %t.o %t1.o %t2.o | ||
| ; RUN: obj2yaml %t.wasm | FileCheck %s | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
| target triple = "wasm32-unknown-unknown" | ||
|
|
||
| declare void @foo(i8*) | ||
| declare void @bar(i8*) | ||
|
|
||
| define void @_start() { | ||
| call void @foo(i8* null) | ||
| call void @bar(i8* null) | ||
| ret void | ||
| } | ||
|
|
||
| ; CHECK: Sections: | ||
| ; CHECK-NEXT: - Type: TYPE | ||
| ; CHECK-NEXT: Signatures: | ||
| ; CHECK-NEXT: - Index: 0 | ||
| ; CHECK-NEXT: ReturnType: NORESULT | ||
| ; CHECK-NEXT: ParamTypes: [] | ||
| ; CHECK-NEXT: - Index: 1 | ||
| ; CHECK-NEXT: ReturnType: NORESULT | ||
| ; CHECK-NEXT: ParamTypes: | ||
| ; CHECK-NEXT: - I32 | ||
|
|
||
| ; CHECK: - Type: EVENT | ||
| ; CHECK-NEXT: Events: | ||
| ; CHECK-NEXT: - Index: 0 | ||
| ; CHECK-NEXT: Attribute: 0 | ||
| ; CHECK-NEXT: SigIndex: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //===- InputEvent.h ---------------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Linker | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Wasm events are features that suspend the current execution and transfer the | ||
| // control flow to a corresponding handler. Currently the only supported event | ||
| // kind is exceptions. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLD_WASM_INPUT_EVENT_H | ||
| #define LLD_WASM_INPUT_EVENT_H | ||
|
|
||
| #include "Config.h" | ||
| #include "InputFiles.h" | ||
| #include "WriterUtils.h" | ||
| #include "lld/Common/ErrorHandler.h" | ||
| #include "llvm/Object/Wasm.h" | ||
|
|
||
| namespace lld { | ||
| namespace wasm { | ||
|
|
||
| // Represents a single Wasm Event within an input file. These are combined to | ||
| // form the final EVENTS section. | ||
| class InputEvent { | ||
| public: | ||
| InputEvent(const WasmSignature &S, const WasmEvent &E, ObjFile *F) | ||
| : File(F), Event(E), Signature(S), Live(!Config->GcSections) {} | ||
|
|
||
| StringRef getName() const { return Event.SymbolName; } | ||
| const WasmEventType &getType() const { return Event.Type; } | ||
|
|
||
| uint32_t getEventIndex() const { return EventIndex.getValue(); } | ||
| bool hasEventIndex() const { return EventIndex.hasValue(); } | ||
| void setEventIndex(uint32_t Index) { | ||
| assert(!hasEventIndex()); | ||
| EventIndex = Index; | ||
| } | ||
|
|
||
| ObjFile *File; | ||
| WasmEvent Event; | ||
| const WasmSignature &Signature; | ||
|
|
||
| bool Live = false; | ||
|
|
||
| protected: | ||
| llvm::Optional<uint32_t> EventIndex; | ||
| }; | ||
|
|
||
| } // namespace wasm | ||
|
|
||
| inline std::string toString(const wasm::InputEvent *E) { | ||
| return (toString(E->File) + ":(" + E->getName() + ")").str(); | ||
| } | ||
|
|
||
| } // namespace lld | ||
|
|
||
| #endif // LLD_WASM_INPUT_EVENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.