Skip to content

wasm32-freestanding target missing errno values #13890

@marler8997

Description

@marler8997

Zig Version

0.11.0-dev.715+cffbb32d3

Steps to Reproduce and Observed Behavior

Create this file bug.c:

#include <errno.h>
int main() { return ENOMEM; }

Compile with:

$ zig build-exe bug.c -lc -target wasm32-freestanding -mcpu generic
error(compilation): clang failed with stderr: bug.c:2:21: error: use of undeclared identifier 'ENOMEM'

bug.c:1:1: error: unable to build C object: clang exited with code 1

Expected Behavior

Compiles successfully.

Extra Notes

Note that the wasm32-wasi target does compile succesfully. Looking at the diff of errno.h between these 2 targets would be a good start to figure out what the correct fix is. In particular the wasi target has a few extra includes like #include <bits/errno.h>, #include <__erno.h> and #include <__errno_values.h>:

$ diff lib/libc/include/wasm-freestanding-musl/errno.h lib/libc/include/wasm-wasi-musl/errno.h 
8,14c8,14
< #ifdef WASM_THREAD_MODEL_SINGLE
< extern int errno;
< #else
< #ifdef __cplusplus
< extern thread_local int errno;
< #else
< extern _Thread_local int errno;
---
> #include <features.h>
> 
> #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
> #include <bits/errno.h>
> 
> #ifdef __GNUC__
> __attribute__((const))
15a16,20
> int *__errno_location(void);
> #define errno (*__errno_location())
> #else
> #include <__errno.h>
> #include <__errno_values.h>
18c23,25
< #define errno errno
---
> #ifdef _GNU_SOURCE
> extern char *program_invocation_short_name, *program_invocation_name;
> #endif
24a32
> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasm32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions