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

xxhash.h->XXH_STATIC_ASSERT: potential build failure due to missing static_assert macro #664

Closed
aeolio opened this issue Dec 15, 2021 · 3 comments · Fixed by #670
Closed

Comments

@aeolio
Copy link

aeolio commented Dec 15, 2021

I just reported this to lighttpd; they directed me to this project.

Cross-compiling with a uClibc toolchain results in a build failure, because uClibc does not define the static_assert macro.
Including the macro definition in case it is not defined by <assert.h> fixes this issue

/* note: use after variable declarations */
#ifndef XXH_STATIC_ASSERT
#  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)    /* C11 */
#    include <assert.h>

/* uClibc does not define static_assert, but provides _Static_assert */
#    ifndef static_assert
#      define static_assert _Static_assert
#    endif

#    define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
#  elif defined(__cplusplus) && (__cplusplus >= 201103L)            /* C++11 */
#    define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
#  else
#    define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
#  endif
#  define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
#endif

@t-mat
Copy link
Contributor

t-mat commented Dec 15, 2021

Hi @aeolio,

I'm really sorry. But I believe we should not support uClibc with C11 or later C standard compilers. Because

(1) uClibc's <assert.h> is not compatible with C11. Their comment claims that it's compatible with C99. https://git.uclibc.org/uClibc/tree/include/assert.h#n19
(2) Therefore, you should not use uClibc's <assert.h> with C11 or later C standard compilers.
(3) If you want to use uClibc with modern C compiler, you must indicate C standard version explicitly. e.g. -std=c99

Also,

(4) If you really want to use xxhash.h with uClibc and C11 or later compiler, you must define XXH_STATIC_ASSERT(x) externally with compiler option, etc.
(5) If we need to implement something special for uClibc, we must check their special macro __UCLIBC__. https://git.uclibc.org/uClibc/tree/README#n68

@easyaspi314
Copy link
Contributor

easyaspi314 commented Dec 15, 2021

I ran into a similar issue when messing with an old version of the NDK. (Side note: 310/130/190 MB/s on an actual 600MHz ARM1136)

We should use _Static_assert on C11.

@aeolio
Copy link
Author

aeolio commented Dec 15, 2021

Hi Takayuki,

Using _Static_assert would definitely help - it is supported by the compiler, and not dependent on the library implementation. As to the missing macro, I understand that I should rather follow this up with the library project (this is uclibc-ng - I always forget that this is a separate project, not an evolution).

Kind regards, Andreas

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

Successfully merging a pull request may close this issue.

3 participants