wasix-org / wasix-libc

wasix libc implementation for WebAssembly
https://wasi.dev
Other
114 stars 19 forks source link

compiling a file that includes sched.h then string.h with DGNU_SOURCE=1 fails. #11

Open xbjfk opened 1 year ago

xbjfk commented 1 year ago

When compiling a file that includes string.h after sched.h, it fails to compile. minimum reproducable example:

#include <sched.h>
#include <string.h>

Error (make sure to compile with -DGNU_SOURCE=1:

In file included from test.c++:2:
In file included from /tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/string.h:6:
In file included from /tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/__header_string.h:8:
/tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/__functions_memcpy.h:12:7: error: exception specification in declaration does not match previous declaration
void *memcpy(void *__restrict__ __dst, const void *__restrict__ __src, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2)));
      ^
/tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/sched.h:84:7: note: previous declaration is here
void *memcpy(void *__restrict, const void *__restrict, size_t);
      ^
In file included from test.c++:2:
In file included from /tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/string.h:6:
In file included from /tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/__header_string.h:8:
/tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/__functions_memcpy.h:14:7: error: exception specification in declaration does not match previous declaration
void *memset(void *__dst, int __c, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1)));
      ^
/tmp/mkcross/out/wasm32-wasix-wasi/etc/mkcross/clang/../../../include/sched.h:86:7: note: previous declaration is here
void *memset (void *, int, size_t);
      ^
2 errors generated.

this happens because musl has definitions of memset and memcpy behind #ifdef GNU_SORUCE in sched.h, and those dont have attributes, while the ones in __functions_memcpy.h (included by string.h) do have attributes.

The reason this only happens in wasix-libc is:

I see three potential solutions, none ideal. I would be happy to do any if anyone suggests which solution is best:

I consider this pretty severe, since you can't compile libcxx (at least with certain compile options), which by extension means it is impossible to use C++ at all with wasix libc

sunny-g commented 1 year ago

I put them behind __wasi_unmodified_upstream defs here - not sure if its correct but I'm also trying to build a C++ project and these changes are getting me somewhere :)