Skip to content

[WIP] Merge musl-1.2.1 into #13006 #13007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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: 1 addition & 1 deletion src/lib/libnoderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ addToLibrary({
// generic function for all node creation
cwd() { return process.cwd(); },
chdir(...args) { process.chdir(...args); },
mknod(path, mode) {
mknod(path, mode/*, dev */) {
if (FS.isDir(path)) {
fs.mkdirSync(path, mode);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/libwasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,13 @@ var WasiLibrary = {
var type = stream.tty ? {{{ cDefs.__WASI_FILETYPE_CHARACTER_DEVICE }}} :
FS.isDir(stream.mode) ? {{{ cDefs.__WASI_FILETYPE_DIRECTORY }}} :
FS.isLink(stream.mode) ? {{{ cDefs.__WASI_FILETYPE_SYMBOLIC_LINK }}} :
{{{ cDefs.__WASI_FILETYPE_REGULAR_FILE }}};
FS.isFile(stream.mode) ? {{{ cDefs.__WASI_FILETYPE_REGULAR_FILE }}} :
-1;
if (type === -1) return -{{{ cDefs.EBADF }}};
#else
// Hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0. We support at
// least stdin, stdout, stderr in a simple way.
#if ASSERTIONS
assert(fd == 0 || fd == 1 || fd == 2);
#endif
if (fd < 0 || fd > 2) return -{{{ cDefs.EBADF }}};
var type = {{{ cDefs.__WASI_FILETYPE_CHARACTER_DEVICE }}};
if (fd == 0) {
rightsBase = {{{ cDefs.__WASI_RIGHTS_FD_READ }}};
Expand Down
1 change: 0 additions & 1 deletion src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function exitRuntime() {
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
{{{ runIfWorkerThread('return;') }}} // PThreads reuse the runtime from the main thread.
#if !STANDALONE_WASM
___funcs_on_exit(); // Native atexit() functions
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/struct_info_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"_a_transferredcanvases"
],
"thread_profiler_block": [
"threadStatus",
"timeSpentInStatus",
"name"
"threadStatus",
"timeSpentInStatus",
"name"
]
},
"defines": [
Expand Down
4 changes: 2 additions & 2 deletions system/include/emscripten/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <emscripten/val.h>
#include <emscripten/wire.h>

#if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer)
#if defined(HAS_LSAN) || __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
#endif

Expand Down Expand Up @@ -747,7 +747,7 @@ template<typename T>
inline T* getContext(const T& t) {
// not a leak because this is called once per binding
auto* ret = new T(t);
#if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer)
#if defined(HAS_LSAN) || __has_feature(address_sanitizer)
__lsan_ignore_object(ret);
#endif
return ret;
Expand Down
6 changes: 3 additions & 3 deletions system/lib/compiler-rt/lib/asan/asan_interceptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void InitializePlatformInterceptors();

} // namespace __asan

// There is no general interception at all on Fuchsia.
// There is no general interception at all on Fuchsia and Emscripten.
// Only the functions in asan_interceptors_memintrinsics.h are
// really defined to replace libc functions.
#if !SANITIZER_FUCHSIA
#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN

// Use macro to describe if specific function should be
// intercepted on a given platform.
Expand Down Expand Up @@ -162,6 +162,6 @@ DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
(void) ctx;
#define COMMON_INTERCEPT_FUNCTION(name) ASAN_INTERCEPT_FUNC(name)

#endif // !SANITIZER_FUCHSIA
#endif // !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN

#endif // ASAN_INTERCEPTORS_H
4 changes: 3 additions & 1 deletion system/lib/compiler-rt/lib/lsan/lsan_common_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
// Finally, we can only obtain the stack pointer for the current thread,
// so we scan the full stack for other threads.
static void ProcessThreadsCallback(ThreadContextBase *tctx, void *arg) {
tid_t os_id = tctx->os_id;
LOG_THREADS("Processing thread %llu\n", os_id);
if (tctx->status != ThreadStatusRunning)
return;

Frontier *frontier = reinterpret_cast<Frontier *>(arg);
tid_t os_id = tctx->os_id;

uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
DTLS *dtls;
Expand Down Expand Up @@ -154,6 +155,7 @@ static void ProcessThreadsCallback(ThreadContextBase *tctx, void *arg) {
}

ScanRangeForPointers(stack_begin, stack_end, frontier, "STACK", kReachable);
//ForEachExtraStackRange(os_id, ForEachExtraStackRangeCb, frontier);
}

if (flags()->use_tls && tls_begin) {
Expand Down
13 changes: 5 additions & 8 deletions system/lib/compiler-rt/lib/lsan/lsan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,8 @@ INTERCEPTOR(void, _exit, int status) {
namespace __lsan {

void InitializeInterceptors() {
// Fuchsia doesn't use interceptors that require any setup.
#if !SANITIZER_FUCHSIA
#if !SANITIZER_EMSCRIPTEN
// Fuchsia and Emscripten doesn't use interceptors that require any setup.
#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
__interception::DoesNotSupportStaticLinking();
InitializeSignalInterceptors();

Expand Down Expand Up @@ -596,17 +595,15 @@ void InitializeInterceptors() {
LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;

LSAN_MAYBE_INTERCEPT_STRERROR;
#endif // !SANITIZER_EMSCRIPTEN
#endif // !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN

#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_FUCHSIA
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
Report("LeakSanitizer: failed to create thread key.\n");
Die();
}
#endif

#endif // !SANITIZER_FUCHSIA
}

} // namespace __lsan
#endif // SANITIZER_EMSCRIPTEN
#endif // SANITIZER_POSIX
3 changes: 1 addition & 2 deletions system/lib/libc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ and use a script (`system/lib/update_musl.py`) to pull in updates.

Some changes have been made to the version that was taken from upstream, including:

* Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#if __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary.
* Backporting an operator-precedence warning fix from 6e76e1540fc58a418494bf5eb832b556f9c5763e in the upstream version.
* Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#ifdef __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary.
* Switch to using the wasi `fd_write` syscall instead of `writev`.
* Simplify stdout stream handling: do not support seeking, terminal handling, etc., as it just increases code size and Emscripten doesn't have those features anyhow.
* Setting `_POSIX_REALTIME_SIGNALS` and `_POSIX_SPAWN` macros to -1, to exclude unsupported functions.
Expand Down
18 changes: 1 addition & 17 deletions system/lib/libc/musl/arch/emscripten/bits/fenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
#define FE_TOWARDZERO 0xc00

typedef unsigned short fexcept_t;

typedef struct {
unsigned short __control_word;
unsigned short __unused1;
unsigned short __status_word;
unsigned short __unused2;
unsigned short __tags;
unsigned short __unused3;
unsigned int __eip;
unsigned short __cs_selector;
unsigned int __opcode:11;
unsigned int __unused4:5;
unsigned int __data_offset;
unsigned short __data_selector;
unsigned short __unused5;
unsigned int __mxcsr;
} fenv_t;
typedef unsigned short fenv_t;

#define FE_DFL_ENV ((const fenv_t *) -1)
4 changes: 3 additions & 1 deletion system/lib/libc/musl/arch/emscripten/bits/limits.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#define PAGE_SIZE 65536
// A value used historically in Emscripten, and which we don't have a strong
// reason to change so far.
#define PAGESIZE 65536
4 changes: 4 additions & 0 deletions system/lib/libc/musl/arch/emscripten/bits/mman.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// XXX Emscripten in sync with both:
// - musl/arch/x86_64/bits/mman.h
// - musl/arch/i386/bits/mman.h
#define MAP_32BIT 0x40
7 changes: 7 additions & 0 deletions system/lib/libc/musl/arch/emscripten/bits/posix.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#ifdef __wasm64__
// 64-bit wide pointers under wasm64
#define _POSIX_V6_LP64_OFF64 1
#define _POSIX_V7_LP64_OFF64 1
#else
// 32-bit wide pointers under wasm32
#define _POSIX_V6_ILP32_OFFBIG 1
#define _POSIX_V7_ILP32_OFFBIG 1
#endif
1 change: 1 addition & 0 deletions system/lib/libc/musl/arch/emscripten/bits/setjmp.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// XXX Emscripten in sync with musl/arch/i386/bits/setjmp.h
typedef unsigned long __jmp_buf[6];
58 changes: 39 additions & 19 deletions system/lib/libc/musl/arch/emscripten/bits/signal.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// XXX Emscripten in sync with musl/arch/i386/bits/signal.h
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)

Expand All @@ -7,25 +8,44 @@
#endif

#ifdef _GNU_SOURCE
#define REG_GS 0
#define REG_FS 1
#define REG_ES 2
#define REG_DS 3
#define REG_EDI 4
#define REG_ESI 5
#define REG_EBP 6
#define REG_ESP 7
#define REG_EBX 8
#define REG_EDX 9
#define REG_ECX 10
#define REG_EAX 11
#define REG_TRAPNO 12
#define REG_ERR 13
#define REG_EIP 14
#define REG_CS 15
#define REG_EFL 16
#define REG_UESP 17
#define REG_SS 18
enum { REG_GS = 0 };
#define REG_GS REG_GS
enum { REG_FS = 1 };
#define REG_FS REG_FS
enum { REG_ES = 2 };
#define REG_ES REG_ES
enum { REG_DS = 3 };
#define REG_DS REG_DS
enum { REG_EDI = 4 };
#define REG_EDI REG_EDI
enum { REG_ESI = 5 };
#define REG_ESI REG_ESI
enum { REG_EBP = 6 };
#define REG_EBP REG_EBP
enum { REG_ESP = 7 };
#define REG_ESP REG_ESP
enum { REG_EBX = 8 };
#define REG_EBX REG_EBX
enum { REG_EDX = 9 };
#define REG_EDX REG_EDX
enum { REG_ECX = 10 };
#define REG_ECX REG_ECX
enum { REG_EAX = 11 };
#define REG_EAX REG_EAX
enum { REG_TRAPNO = 12 };
#define REG_TRAPNO REG_TRAPNO
enum { REG_ERR = 13 };
#define REG_ERR REG_ERR
enum { REG_EIP = 14 };
#define REG_EIP REG_EIP
enum { REG_CS = 15 };
#define REG_CS REG_CS
enum { REG_EFL = 16 };
#define REG_EFL REG_EFL
enum { REG_UESP = 17 };
#define REG_UESP REG_UESP
enum { REG_SS = 18 };
#define REG_SS REG_SS
#endif

struct sigaltstack {
Expand Down
12 changes: 9 additions & 3 deletions system/lib/libc/musl/arch/emscripten/bits/stat.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// XXX Emscripten in sync with musl/arch/i386/bits/stat.h except for the padding and 64-bit time_t redirections change.

/* copied from kernel definition, but with padding replaced
* by the corresponding correctly-sized userspace types. */

struct stat
{
struct stat {
dev_t st_dev;
#ifndef __EMSCRIPTEN__
int __st_dev_padding;
Expand All @@ -19,6 +19,12 @@ struct stat
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;
#ifndef __EMSCRIPTEN__ // XXX Emscripten no need to activate the symbol redirections for 64-bit time_t.
struct {
long tv_sec;
long tv_nsec;
} __st_atim32, __st_mtim32, __st_ctim32;
#endif
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
Expand Down
13 changes: 0 additions & 13 deletions system/lib/libc/musl/arch/emscripten/bits/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,9 @@ typedef uint32_t uint_fast32_t;
#define UINT_FAST16_MAX UINT32_MAX
#define UINT_FAST32_MAX UINT32_MAX

#if __LP64__

#define INTPTR_MIN INT64_MIN
#define INTPTR_MAX INT64_MAX
#define UINTPTR_MAX UINT64_MAX
#define PTRDIFF_MIN INT64_MIN
#define PTRDIFF_MAX INT64_MAX
#define SIZE_MAX UINT64_MAX

#else

#define INTPTR_MIN (-1-__INTPTR_MAX__)
#define INTPTR_MAX __INTPTR_MAX__
#define UINTPTR_MAX __UINTPTR_MAX__
#define PTRDIFF_MIN (-1-__PTRDIFF_MAX__)
#define PTRDIFF_MAX __PTRDIFF_MAX__
#define SIZE_MAX __SIZE_MAX__

#endif
48 changes: 0 additions & 48 deletions system/lib/libc/musl/arch/emscripten/bits/user.h
Original file line number Diff line number Diff line change
@@ -1,48 +0,0 @@
#undef __WORDSIZE
#define __WORDSIZE 32

typedef struct user_fpregs_struct
{
long cwd, swd, twd, fip, fcs, foo, fos, st_space[20];
} elf_fpregset_t;

typedef struct user_fpxregs_struct
{
unsigned short cwd, swd, twd, fop;
long fip, fcs, foo, fos, mxcsr, reserved;
long st_space[32], xmm_space[32], padding[56];
} elf_fpxregset_t;

struct user_regs_struct
{
long ebx, ecx, edx, esi, edi, ebp, eax, xds, xes, xfs, xgs;
long orig_eax, eip, xcs, eflags, esp, xss;
};

#define ELF_NGREG 17
typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];

struct user
{
struct user_regs_struct regs;
int u_fpvalid;
struct user_fpregs_struct i387;
unsigned long u_tsize;
unsigned long u_dsize;
unsigned long u_ssize;
unsigned long start_code;
unsigned long start_stack;
long signal;
int reserved;
struct user_regs_struct *u_ar0;
struct user_fpregs_struct *u_fpstate;
unsigned long magic;
char u_comm[32];
int u_debugreg[8];
};

#define PAGE_MASK (~(PAGE_SIZE-1))
#define NBPG PAGE_SIZE
#define UPAGES 1
#define HOST_TEXT_START_ADDR (u.start_code)
#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
2 changes: 2 additions & 0 deletions system/lib/libc/musl/arch/generic/bits/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ struct ipc_perm {
long __pad1;
long __pad2;
};

#define IPC_64 0x100
2 changes: 1 addition & 1 deletion system/lib/libc/musl/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct __jmp_buf_tag {
|| defined(_BSD_SOURCE)
typedef jmp_buf sigjmp_buf;
/* XXX EMSCRIPTEN: No signals support, alias sigsetjmp and siglongjmp to their non-signals counterparts. */
#if __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
#define sigsetjmp(buf, x) setjmp((buf))
#define siglongjmp(buf, val) longjmp(buf, val)
#else
Expand Down
Loading
Loading