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:
upstream wasi-libc does not have this problem since more of sched.h including the definitions of memset and memcpy is blocked by #ifdef __wasi_unmodified_upstream
upstream musl does not have this problem since all of its definitions of memcpy and memset don't use attributes
I see three potential solutions, none ideal. I would be happy to do any if anyone suggests which solution is best:
remove the definitions of sched.h and include string.h from sched.h (probably the best solution)
remove the attributes in __functions_memcpy.h
add the attributes to sched.h
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
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 :)
When compiling a file that includes string.h after sched.h, it fails to compile. minimum reproducable example:
Error (make sure to compile with -DGNU_SOURCE=1:
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:
#ifdef __wasi_unmodified_upstream
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