Skip to content
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

errno.h constants regression (wasi types vs preprocessor) #9996

Closed
bvibber opened this issue Dec 9, 2019 · 7 comments
Closed

errno.h constants regression (wasi types vs preprocessor) #9996

bvibber opened this issue Dec 9, 2019 · 7 comments

Comments

@bvibber
Copy link
Collaborator

bvibber commented Dec 9, 2019

As of cffcd70 the definitions of EPERM etc in errno.h changed from untyped integers to typed references to wasi constants, such as:

#define EPERM              __WASI_ERRNO_PERM
...
#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)

This breaks preprocessor code like this in the dav1d AV1 decoder:

#if EPERM > 0
#define DAV1D_ERR(e) (-(e)) ///< Negate POSIX error code.
#else
#define DAV1D_ERR(e) (e)
#endif

Test case:

#include <stdio.h>
#include <errno.h>

#if EPERM > 0
#endif

int main(int argc, const char **argv) {
    printf("Hello, world\n");
    return 0;
}

Output:

$ emcc -o explode.js explode.c
cache:INFO: generating system asset: is_vanilla.txt... (this will be cached in "/home/brion/.emscripten_cache/is_vanilla.txt" for subsequent builds)
cache:INFO:  - ok
explode.c:4:5: error: token is not a valid binary operator in a preprocessor subexpression
#if EPERM > 0
    ^~~~~
/home/brion/src/emscripten/emscripten/system/lib/libc/musl/arch/emscripten/bits/errno.h:3:28: note: expanded from macro 'EPERM'
#define EPERM              __WASI_ERRNO_PERM
                           ^~~~~~~~~~~~~~~~~
/home/brion/src/emscripten/emscripten/system/include/wasi/api.h:414:44: note: expanded from macro '__WASI_ERRNO_PERM'
#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
                           ~~~~~~~~~~~~~~~~^
1 error generated.
shared:ERROR: '/home/brion/src/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=4 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/home/brion/src/emscripten/emscripten/system/include/libcxx -Xclang -isystem/home/brion/src/emscripten/emscripten/system/lib/libcxxabi/include -Xclang -isystem/home/brion/src/emscripten/emscripten/system/include/compat -Xclang -isystem/home/brion/src/emscripten/emscripten/system/include -Xclang -isystem/home/brion/src/emscripten/emscripten/system/include/libc -Xclang -isystem/home/brion/src/emscripten/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/home/brion/src/emscripten/emscripten/system/local/include -DEMSCRIPTEN explode.c -Xclang -isystem/home/brion/src/emscripten/emscripten/system/include/SDL -c -o /tmp/emscripten_temp_LobRc8/explode_0.o -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)
@bvibber
Copy link
Collaborator Author

bvibber commented Dec 10, 2019

(In a pinch I can work around this by changing dav1d's code to avoid using the #if EPERM > 0 preprocessor comparison, I'm not sure how safe an assumption it was that that should work. Haven't noticed that trick before, but it might be in use elsewhere.)

@bvibber
Copy link
Collaborator Author

bvibber commented Dec 10, 2019

Closing this in favor of trying to fix at the dav1d side: https://code.videolan.org/videolan/dav1d/merge_requests/860

@bvibber bvibber closed this as completed Dec 10, 2019
@sbc100
Copy link
Collaborator

sbc100 commented Dec 10, 2019

Might be worth raising this on in the WASI repo .. I'm also not how common/valid that pattern is.

@bvibber
Copy link
Collaborator Author

bvibber commented Dec 11, 2019

Ok, I'll go ahead and reopen this for further discussion -- is https://github.com/CraneStation/wasi-libc the right repo for that?

@bvibber bvibber reopened this Dec 11, 2019
@kripken
Copy link
Member

kripken commented Dec 11, 2019

Either there or maybe an issue on the main wasi repo, I'm not sure which is better, https://github.com/WebAssembly/WASI

@sbc100
Copy link
Collaborator

sbc100 commented Dec 12, 2019

Yes https://github.com/CraneStation/wasi-libc is the right place.

Lets fix locally at the same time as pushing for an upstream change. @Brion do you have time to whip up a local PR.. along with a simple test i guess?

@bvibber
Copy link
Collaborator Author

bvibber commented Dec 12, 2019

@sbc100 sure, I'll work on that shortly. Shouldn't be too hard to add a compilation test.

bvibber added a commit to bvibber/emscripten that referenced this issue Dec 12, 2019
Uses UINT16_C for backing of errno constants (EPERM etc) as in
previous versions, rather than casting them to __wasm_errno_t.

This fixes some portable codebases that use the C preprocessor
to compare the constant values like this:

```
    #if EPERM > 0
    #define DAV1D_ERR(e) (-(e))
    #else
    #define DAV1D_ERR(e) (e)
    #endif
```

Adds a test case to catch regressions.

Fixes emscripten-core#9996
bvibber added a commit to bvibber/emscripten that referenced this issue Dec 12, 2019
Uses UINT16_C for backing of errno constants (EPERM etc) as in
previous versions, rather than casting them to __wasm_errno_t.

This fixes some portable codebases that use the C preprocessor
to compare the constant values like this:

```
    #if EPERM > 0
    #define DAV1D_ERR(e) (-(e))
    #else
    #define DAV1D_ERR(e) (e)
    #endif
```

Adds a test case to catch regressions.

Fixes emscripten-core#9996
bvibber added a commit to bvibber/emscripten that referenced this issue Dec 12, 2019
Uses UINT16_C for backing of errno constants (EPERM etc) as in
previous versions, rather than casting them to __wasm_errno_t.

This fixes some portable codebases that use the C preprocessor
to compare the constant values like this:

```
    #if EPERM > 0
    #define DAV1D_ERR(e) (-(e))
    #else
    #define DAV1D_ERR(e) (e)
    #endif
```

Adds a test case to catch regressions.

Fixes emscripten-core#9996
kripken pushed a commit that referenced this issue Dec 13, 2019
Uses UINT16_C for backing of errno constants (EPERM etc) as in
previous versions, rather than casting them to __wasm_errno_t.

This fixes some portable codebases that use the C preprocessor
to compare the constant values like this:

```
    #if EPERM > 0
    #define DAV1D_ERR(e) (-(e))
    #else
    #define DAV1D_ERR(e) (e)
    #endif
```

Adds a test case to catch regressions.

Fixes #9996
belraquib pushed a commit to belraquib/emscripten that referenced this issue Dec 23, 2020
…e#10025)

Uses UINT16_C for backing of errno constants (EPERM etc) as in
previous versions, rather than casting them to __wasm_errno_t.

This fixes some portable codebases that use the C preprocessor
to compare the constant values like this:

```
    #if EPERM > 0
    #define DAV1D_ERR(e) (-(e))
    #else
    #define DAV1D_ERR(e) (e)
    #endif
```

Adds a test case to catch regressions.

Fixes emscripten-core#9996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants