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

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

Open
xbjfk opened this issue Jun 30, 2023 · 1 comment

Comments

@xbjfk
Copy link

xbjfk commented Jun 30, 2023

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

@sunny-g
Copy link

sunny-g commented Jul 24, 2023

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 :)

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

2 participants