Skip to content

Commit 50c3b02

Browse files
committed
[libc] Add wasm support for some submodules in
llvm-libc
1 parent 28f2fb2 commit 50c3b02

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

libc/src/__support/StringUtil/platform_errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_PLATFORM_ERRORS_H
1010
#define LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_PLATFORM_ERRORS_H
1111

12-
#if defined(__linux__) || defined(__Fuchsia__)
12+
#if defined(__linux__) || defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
1313
#include "tables/linux_platform_errors.h"
1414
#else
1515
#include "tables/minimal_platform_errors.h"

libc/src/__support/StringUtil/tables/posix_errors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ LIBC_INLINE_VAR constexpr MsgTable<76> POSIX_ERRORS = {
6363
MsgMapping(EPROTO, "Protocol error"),
6464
MsgMapping(EMULTIHOP, "Multihop attempted"),
6565
MsgMapping(EBADMSG, "Bad message"),
66+
#ifdef __EMSCRIPTEN__
67+
// For now, match the musl string
68+
MsgMapping(EOVERFLOW, "Value too large for data type"),
69+
#else
6670
MsgMapping(EOVERFLOW, "Value too large for defined data type"),
71+
#endif
6772
MsgMapping(ENOTSOCK, "Socket operation on non-socket"),
6873
MsgMapping(EDESTADDRREQ, "Destination address required"),
6974
MsgMapping(EMSGSIZE, "Message too long"),

libc/src/__support/StringUtil/tables/stdc_errors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
namespace LIBC_NAMESPACE_DECL {
1717

1818
LIBC_INLINE_VAR constexpr const MsgTable<4> STDC_ERRORS = {
19+
#ifdef __EMSCRIPTEN__
20+
// For now, match the musl name for errno 0.
21+
MsgMapping(0, "No error information"),
22+
#else
1923
MsgMapping(0, "Success"),
24+
#endif
2025
MsgMapping(EDOM, "Numerical argument out of domain"),
2126
MsgMapping(ERANGE, "Numerical result out of range"),
2227
MsgMapping(EILSEQ, "Invalid or incomplete multibyte or wide character"),

libc/src/__support/macros/properties/architectures.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#define LIBC_TARGET_ARCH_IS_ARM
4242
#endif
4343

44+
#if defined(__wasm__)
45+
#define LIBC_TARGET_ARCH_IS_WASM
46+
#endif
47+
4448
#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
4549
#define LIBC_TARGET_ARCH_IS_AARCH64
4650
#endif

libc/src/setjmp/wasm/sigsetjmp.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "src/setjmp/sigsetjmp.h"
2+
#include "hdr/offsetof_macros.h"
3+
#include "src/__support/common.h"
4+
#include "src/__support/macros/config.h"
5+
6+
#if !defined(LIBC_TARGET_ARCH_IS_WASM)
7+
#error "Invalid file include"
8+
#endif
9+
10+
namespace LIBC_NAMESPACE_DECL {
11+
[[gnu::returns_twice]] int sigsetjmp(jmp_buf sigjmp_buf, int savesigs) {
12+
return setjmp(sigjmp_buf);
13+
}
14+
}

0 commit comments

Comments
 (0)