Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/src/__support/StringUtil/platform_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#if defined(__linux__) || defined(__Fuchsia__)
#include "tables/linux_platform_errors.h"
#elif defined(__EMSCRIPTEN__)
#include "tables/emscripten_platform_errors.h"
#else
#include "tables/minimal_platform_errors.h"
#endif
Expand Down
26 changes: 26 additions & 0 deletions libc/src/__support/StringUtil/tables/emscripten_platform_errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Map of error numbers to strings for the Emscripten platform --*- C++ -*-===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is over 80 columns, meaning it's going to get messed up by auto-formatters. Please make it exactly 80 columns

//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_TABLES_EMSCRPITEN_PLATFORM_ERRORS_H
#define LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_TABLES_EMSCRPITEN_PLATFORM_ERRORS_H

#include "posix_errors.h"
#include "src/__support/macros/config.h"
#include "stdc_errors.h"

namespace LIBC_NAMESPACE_DECL {

LIBC_INLINE_VAR constexpr auto PLATFORM_ERRORS =
STDC_ERRORS + POSIX_ERRORS;

LIBC_INLINE_VAR constexpr auto PLATFORM_ERRNO_NAMES =
STDC_ERRNO_NAMES + POSIX_ERRNO_NAMES;

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_STRINGUTIL_TABLES_EMSCRPITEN_PLATFORM_ERRORS_H
5 changes: 5 additions & 0 deletions libc/src/__support/StringUtil/tables/posix_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ LIBC_INLINE_VAR constexpr MsgTable<76> POSIX_ERRORS = {
MsgMapping(EPROTO, "Protocol error"),
MsgMapping(EMULTIHOP, "Multihop attempted"),
MsgMapping(EBADMSG, "Bad message"),
#ifdef __EMSCRIPTEN__
// For now, match the musl string
MsgMapping(EOVERFLOW, "Value too large for data type"),
#else
MsgMapping(EOVERFLOW, "Value too large for defined data type"),
#endif
MsgMapping(ENOTSOCK, "Socket operation on non-socket"),
MsgMapping(EDESTADDRREQ, "Destination address required"),
MsgMapping(EMSGSIZE, "Message too long"),
Expand Down
5 changes: 5 additions & 0 deletions libc/src/__support/StringUtil/tables/stdc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
namespace LIBC_NAMESPACE_DECL {

LIBC_INLINE_VAR constexpr const MsgTable<4> STDC_ERRORS = {
#ifdef __EMSCRIPTEN__
// For now, match the musl name for errno 0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intention for emscripten to use these other error strings long-term or do you intend to switch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that we will clean this up once we can significant real users of llvm-libc on emscripten. @sbc100 probably knows about it more than I do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on the timeline. We have unit tests that currently depend on the explict strings used in musl. We have a new options if we want to remove this patch:

  1. Update the unit tests to accept both string options
  2. Update our musl fork to use the llvm-libc strings
  3. Remove our support for musl completely and switch the tests to expect llvm-libc strings.

BTW, where did these specific string come from? Is there a reason to prefer "No error information" over "Success"? I suppose the former is technically more accurate but the later might be more inline with user expectations?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards (2) since we already maintain a musl fork anyway and have no plans to upstream it (unlike our llvm-libc changed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. That sounds reasonable. But I presume that no users are going to be affected by this musl change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only users whose code is sensitive the these exact strings like our unit tests are. Seems unlikely, but conceivable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the existing strings in LLVM-libc are meant to match glibc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to land the change to update the musl fork in emscripten first so that we no longer need these lines.

MsgMapping(0, "No error information"),
#else
MsgMapping(0, "Success"),
#endif
MsgMapping(EDOM, "Numerical argument out of domain"),
MsgMapping(ERANGE, "Numerical result out of range"),
MsgMapping(EILSEQ, "Invalid or incomplete multibyte or wide character"),
Expand Down
4 changes: 4 additions & 0 deletions libc/src/__support/macros/properties/architectures.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#define LIBC_TARGET_ARCH_IS_ARM
#endif

#if defined(__wasm__)
#define LIBC_TARGET_ARCH_IS_WASM
#endif

#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
#define LIBC_TARGET_ARCH_IS_AARCH64
#endif
Expand Down
22 changes: 22 additions & 0 deletions libc/src/setjmp/wasm/sigsetjmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation of sigsetjmp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/setjmp/sigsetjmp.h"
#include "hdr/offsetof_macros.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

#if !defined(LIBC_TARGET_ARCH_IS_WASM)
#error "Invalid file include"
#endif

namespace LIBC_NAMESPACE_DECL {
[[gnu::returns_twice]] int sigsetjmp(jmp_buf sigjmp_buf, int savesigs) {
return setjmp(sigjmp_buf);
}
}
Loading