diff -ruN a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp --- a/lib/Support/CrashRecoveryContext.cpp 2018-07-31 04:41:25.000000000 +0900 +++ b/lib/Support/CrashRecoveryContext.cpp 2026-11-14 14:53:56.924156130 +0900 @@ -13,7 +13,9 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/ThreadLocal.h" +#ifndef __wasi__ #include +#endif using namespace llvm; namespace { @@ -31,7 +33,9 @@ const CrashRecoveryContextImpl *Next; CrashRecoveryContext *CRC; +#ifndef __wasi__ ::jmp_buf JumpBuffer; +#endif volatile unsigned Failed : 1; unsigned SwitchedThread : 1; @@ -66,7 +70,11 @@ // FIXME: Stash the backtrace. // Jump back to the RunSafely we were called under. +#ifndef __wasi__ longjmp(JumpBuffer, 1); +#else + abort(); +#endif } }; @@ -272,6 +280,12 @@ } } +#elif defined(__wasi__) + +// WASI has no signals: crash recovery is a no-op. +static void installExceptionOrSignalHandlers() {} +static void uninstallExceptionOrSignalHandlers() {} + #else // !_WIN32 // Generic POSIX implementation. @@ -351,9 +365,11 @@ CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl(this); Impl = CRCI; +#ifndef __wasi__ if (setjmp(CRCI->JumpBuffer) != 0) { return false; } +#endif } Fn(); diff -ruN a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp --- a/lib/Support/LockFileManager.cpp 2018-08-23 18:42:58.000000000 +0900 +++ b/lib/Support/LockFileManager.cpp 2026-11-14 14:53:11.337360098 +0900 @@ -108,7 +108,7 @@ } bool LockFileManager::processStillExecuting(StringRef HostID, int PID) { -#if LLVM_ON_UNIX && !defined(__ANDROID__) +#if LLVM_ON_UNIX && !defined(__ANDROID__) && !defined(__wasi__) SmallString<256> StoredHostID; if (getHostID(StoredHostID)) return true; // Conservatively assume it's executing on error. diff -ruN a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc --- a/lib/Support/Unix/Path.inc 2018-12-18 10:38:20.000000000 +0900 +++ b/lib/Support/Unix/Path.inc 2026-11-14 14:56:17.250604105 +0900 @@ -222,6 +222,8 @@ char link_path[MAXPATHLEN]; if (realpath(DLInfo.dli_fname, link_path)) return link_path; +#elif defined(__wasi__) + return ""; #else #error GetMainExecutable is not implemented on this host yet. #endif @@ -395,6 +397,8 @@ #elif defined(__CYGWIN__) // Cygwin doesn't expose this information; would need to use Win32 API. return false; +#elif defined(__wasi__) + return true; #elif defined(__Fuchsia__) // Fuchsia doesn't yet support remote filesystem mounts. return true; diff -ruN a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc --- a/lib/Support/Unix/Process.inc 2018-08-28 00:55:39.000000000 +0900 +++ b/lib/Support/Unix/Process.inc 2026-11-14 14:54:11.128039086 +0900 @@ -220,13 +220,21 @@ if (NullFD == StandardFD) FDC.keepOpen(); +#ifndef __wasi__ else if (dup2(NullFD, StandardFD) < 0) return std::error_code(errno, std::generic_category()); +#endif } return std::error_code(); } std::error_code Process::SafelyCloseFileDescriptor(int FD) { +#ifdef __wasi__ + if (::close(FD) < 0) + return std::error_code(errno, std::generic_category()); + return std::error_code(); +#endif +#ifndef __wasi__ // Create a signal set filled with *all* signals. sigset_t FullSet; if (sigfillset(&FullSet) < 0) @@ -259,6 +267,7 @@ if (ErrnoFromClose) return std::error_code(ErrnoFromClose, std::generic_category()); return std::error_code(EC, std::generic_category()); +#endif } bool Process::StandardInIsUserInput() { diff -ruN a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc --- a/lib/Support/Unix/Program.inc 2018-06-13 02:43:52.000000000 +0900 +++ b/lib/Support/Unix/Program.inc 2026-11-14 15:28:24.728517624 +0900 @@ -94,6 +94,29 @@ return errc::no_such_file_or_directory; } +#ifdef __wasi__ +// WASI cannot spawn processes. +} // namespace llvm +// Must be at global scope to match the declaration in Program.cpp. +static bool Execute(ProcessInfo &PI, StringRef Program, + ArrayRef Args, Optional> Env, + ArrayRef> Redirects, + unsigned MemoryLimit, std::string *ErrMsg) { + if (ErrMsg) + *ErrMsg = "process execution is not supported on WASI"; + return false; +} +namespace llvm { + +ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, + bool WaitUntilTerminates, std::string *ErrMsg) { + ProcessInfo WaitResult; + WaitResult.ReturnCode = -2; + if (ErrMsg) + *ErrMsg = "process execution is not supported on WASI"; + return WaitResult; +} +#else static bool RedirectIO(Optional Path, int FD, std::string* ErrMsg) { if (!Path) // Noop return false; @@ -427,6 +450,8 @@ return WaitResult; } +#endif // __wasi__ + std::error_code sys::ChangeStdinToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); diff -ruN a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc --- a/lib/Support/Unix/Signals.inc 2018-10-13 02:22:07.000000000 +0900 +++ b/lib/Support/Unix/Signals.inc 2026-11-14 14:56:09.190241306 +0900 @@ -227,7 +227,9 @@ static std::atomic NumRegisteredSignals = ATOMIC_VAR_INIT(0); static struct { +#ifndef __wasi__ struct sigaction SA; +#endif int SigNo; } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)]; @@ -262,6 +264,14 @@ static void CreateSigAltStack() {} #endif +#ifdef __wasi__ +// WASI has no signals: nothing to register. +static void RegisterHandlers() {} +static void UnregisterHandlers() {} +static void RemoveFilesToRemove() { + FileToRemoveList::removeAllFiles(FilesToRemove); +} +#else static void RegisterHandlers() { // Not signal-safe. // The mutex prevents other threads from registering handlers while we're // doing it. We also have to protect the handlers and their count because @@ -356,6 +366,7 @@ raise(Sig); #endif } +#endif // __wasi__ void llvm::sys::RunInterruptHandlers() { RemoveFilesToRemove(); diff -ruN a/lib/Support/Unix/Unix.h b/lib/Support/Unix/Unix.h --- a/lib/Support/Unix/Unix.h 2018-05-02 01:10:38.000000000 +0900 +++ b/lib/Support/Unix/Unix.h 2026-11-14 14:53:11.336832425 +0900 @@ -30,7 +30,9 @@ #include #include #include +#ifndef __wasi__ #include +#endif #ifdef HAVE_UNISTD_H #include diff -ruN a/lib/Support/Unix/Watchdog.inc b/lib/Support/Unix/Watchdog.inc --- a/lib/Support/Unix/Watchdog.inc 2018-04-30 23:59:11.000000000 +0900 +++ b/lib/Support/Unix/Watchdog.inc 2026-11-14 14:53:11.337503958 +0900 @@ -20,13 +20,13 @@ namespace llvm { namespace sys { Watchdog::Watchdog(unsigned int seconds) { -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) && !defined(__wasi__) alarm(seconds); #endif } Watchdog::~Watchdog() { -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) && !defined(__wasi__) alarm(0); #endif } diff -ruN a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake --- a/cmake/modules/HandleLLVMOptions.cmake 2018-12-20 03:01:42.000000000 +0900 +++ b/cmake/modules/HandleLLVMOptions.cmake 2026-11-14 14:51:44.971698547 +0900 @@ -107,7 +107,7 @@ set(LLVM_ON_UNIX 0) endif(CYGWIN) else(WIN32) - if(FUCHSIA OR UNIX) + if(FUCHSIA OR UNIX OR CMAKE_SYSTEM_NAME STREQUAL "WASI") set(LLVM_ON_WIN32 0) set(LLVM_ON_UNIX 1) if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")