1+ diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
2+ index b5fa5760a46a..a8687ef88878 100644
3+ --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
4+ +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
5+ @@ -34,6 +34,12 @@ std::string WebAssembly::getMultiarchTriple(const Driver &D,
6+ TargetTriple.getOSAndEnvironmentName()).str();
7+ }
8+
9+ + static std::string GetCXXExceptionsDir(const ArgList &DriverArgs) {
10+ + if (DriverArgs.getLastArg(options::OPT_fwasm_exceptions))
11+ + return "eh";
12+ + return "noeh";
13+ + }
14+ +
15+ std::string wasm::Linker::getLinkerPath(const ArgList &Args) const {
16+ const ToolChain &ToolChain = getToolChain();
17+ if (const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
18+ @@ -232,10 +238,13 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
19+
20+ /// Given a base library directory, append path components to form the
21+ /// LTO directory.
22+ - static std::string AppendLTOLibDir(const std::string &Dir) {
23+ + static void AppendLibDirAndLTODir(ToolChain::path_list &Paths, const Driver &D, const std::string &Dir) {
24+ + if (D.isUsingLTO()) {
25+ // The version allows the path to be keyed to the specific version of
26+ // LLVM in used, as the bitcode format is not stable.
27+ - return Dir + "/llvm-lto/" LLVM_VERSION_STRING;
28+ + Paths.push_back(Dir + "/llvm-lto/" LLVM_VERSION_STRING);
29+ + }
30+ + Paths.push_back(Dir);
31+ }
32+
33+ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
34+ @@ -256,14 +265,9 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
35+ } else {
36+ const std::string MultiarchTriple =
37+ getMultiarchTriple(getDriver(), Triple, SysRoot);
38+ - if (D.isUsingLTO()) {
39+ - // For LTO, enable use of lto-enabled sysroot libraries too, if available.
40+ - // Note that the directory is keyed to the LLVM revision, as LLVM's
41+ - // bitcode format is not stable.
42+ - auto Dir = AppendLTOLibDir(SysRoot + "/lib/" + MultiarchTriple);
43+ - getFilePaths().push_back(Dir);
44+ - }
45+ - getFilePaths().push_back(SysRoot + "/lib/" + MultiarchTriple);
46+ + std::string TripleLibDir = SysRoot + "/lib/" + MultiarchTriple;
47+ + AppendLibDirAndLTODir(getFilePaths(), D, TripleLibDir + "/" + GetCXXExceptionsDir(Args));
48+ + AppendLibDirAndLTODir(getFilePaths(), D, TripleLibDir);
49+ }
50+
51+ if (getTriple().getOS() == llvm::Triple::WASI) {
52+ @@ -580,13 +584,16 @@ void WebAssembly::addLibCxxIncludePaths(
53+ if (Version.empty())
54+ return;
55+
56+ - // First add the per-target include path if the OS is known.
57+ + // First add the per-target-per-exception-handling include path if the
58+ + // OS is known, then second add the per-target include path.
59+ if (IsKnownOs) {
60+ - std::string TargetDir = LibPath + "/" + MultiarchTriple + "/c++/" + Version;
61+ - addSystemInclude(DriverArgs, CC1Args, TargetDir);
62+ + std::string TargetDir = LibPath + "/" + MultiarchTriple;
63+ + std::string Suffix = "/c++/" + Version;
64+ + addSystemInclude(DriverArgs, CC1Args, TargetDir + "/" + GetCXXExceptionsDir(DriverArgs) + Suffix);
65+ + addSystemInclude(DriverArgs, CC1Args, TargetDir + Suffix);
66+ }
67+
68+ - // Second add the generic one.
69+ + // Third add the generic one.
70+ addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
71+ }
72+
73+ @@ -630,8 +637,10 @@ void WebAssembly::addLibStdCXXIncludePaths(
74+
75+ // First add the per-target include path if the OS is known.
76+ if (IsKnownOs) {
77+ - std::string TargetDir = LibPath + "/c++/" + Version + "/" + MultiarchTriple;
78+ - addSystemInclude(DriverArgs, CC1Args, TargetDir);
79+ + std::string TargetDir = LibPath + "/" + MultiarchTriple;
80+ + std::string Suffix = "/c++/" + Version;
81+ + addSystemInclude(DriverArgs, CC1Args, TargetDir + "/" + GetCXXExceptionsDir(DriverArgs) + Suffix);
82+ + addSystemInclude(DriverArgs, CC1Args, TargetDir + Suffix);
83+ }
84+
85+ // Second add the generic one.
86+ diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
87+ index b0d6cd2d00fc..7218f78d6c9d 100644
88+ --- a/libunwind/src/Unwind-wasm.c
89+ +++ b/libunwind/src/Unwind-wasm.c
90+ @@ -69,6 +69,18 @@ _Unwind_RaiseException(_Unwind_Exception *exception_object) {
91+ __builtin_wasm_throw(0, exception_object);
92+ }
93+
94+ + __asm__(
95+ + ".globl __cpp_exception\n"
96+ + #if defined(__wasm32__)
97+ + ".tagtype __cpp_exception i32\n"
98+ + #elif defined(__wasm64__)
99+ + ".tagtype __cpp_exception i64\n"
100+ + #else
101+ + # error "Unsupported Wasm architecture"
102+ + #endif
103+ + "__cpp_exception:\n"
104+ + );
105+ +
106+ /// Called by __cxa_end_catch.
107+ _LIBUNWIND_EXPORT void
108+ _Unwind_DeleteException(_Unwind_Exception *exception_object) {
1109diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
2- index f8e83e138eff..c5097d25b0c6 100644
110+ index 84c9d526f1d7..2167326605b8 100644
3111--- a/libunwind/src/assembly.h
4112+++ b/libunwind/src/assembly.h
5- @@ -249 ,6 +249 ,9 @@ aliasname: \
113+ @@ -253 ,6 +253 ,9 @@ aliasname: \
6114 #define WEAK_ALIAS(name, aliasname)
7115 #define NO_EXEC_STACK_DIRECTIVE
8116
@@ -13,10 +121,10 @@ index f8e83e138eff..c5097d25b0c6 100644
13121 #else
14122
15123diff --git a/libunwind/src/config.h b/libunwind/src/config.h
16- index deb5a4d4d73d..23c9f012cbcf 100644
124+ index f017403fa223..6014a37e2721 100644
17125--- a/libunwind/src/config.h
18126+++ b/libunwind/src/config.h
19- @@ -66 ,7 +66 ,8 @@
127+ @@ -75 ,7 +75 ,8 @@
20128 #define _LIBUNWIND_EXPORT
21129 #define _LIBUNWIND_HIDDEN
22130 #else
0 commit comments