diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-11-19 20:06:13 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-11-19 20:06:13 +0000 |
| commit | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (patch) | |
| tree | f42add1021b9f2ac6a69ac7cf6c4499962739a45 /llvm/lib/CodeGen/AsmPrinter/WasmException.cpp | |
| parent | 344a3780b2e33f6ca763666c380202b18aab72a3 (diff) | |
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/WasmException.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/WasmException.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp b/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp index 352a33e8639d..a17a2ca2790e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp @@ -18,16 +18,25 @@ using namespace llvm; void WasmException::endModule() { - // This is the symbol used in 'throw' and 'catch' instruction to denote this - // is a C++ exception. This symbol has to be emitted somewhere once in the - // module. Check if the symbol has already been created, i.e., we have at - // least one 'throw' or 'catch' instruction in the module, and emit the symbol - // only if so. - SmallString<60> NameStr; - Mangler::getNameWithPrefix(NameStr, "__cpp_exception", Asm->getDataLayout()); - if (Asm->OutContext.lookupSymbol(NameStr)) { - MCSymbol *ExceptionSym = Asm->GetExternalSymbolSymbol("__cpp_exception"); - Asm->OutStreamer->emitLabel(ExceptionSym); + // These are symbols used to throw/catch C++ exceptions and C longjmps. These + // symbols have to be emitted somewhere once in the module. Check if each of + // the symbols has already been created, i.e., we have at least one 'throw' or + // 'catch' instruction with the symbol in the module, and emit the symbol only + // if so. + // + // But in dynamic linking, it is in general not possible to come up with a + // module instantiating order in which tag-defining modules are loaded before + // the importing modules. So we make them undefined symbols here, define tags + // in the JS side, and feed them to each importing module. + if (!Asm->isPositionIndependent()) { + for (const char *SymName : {"__cpp_exception", "__c_longjmp"}) { + SmallString<60> NameStr; + Mangler::getNameWithPrefix(NameStr, SymName, Asm->getDataLayout()); + if (Asm->OutContext.lookupSymbol(NameStr)) { + MCSymbol *ExceptionSym = Asm->GetExternalSymbolSymbol(SymName); + Asm->OutStreamer->emitLabel(ExceptionSym); + } + } } } |
