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

Compilation fails on FreeBSD < 12 #873

Closed
past-due opened this issue Mar 14, 2021 · 3 comments
Closed

Compilation fails on FreeBSD < 12 #873

past-due opened this issue Mar 14, 2021 · 3 comments

Comments

@past-due
Copy link
Contributor

Using commit: aeffa9b

FreeBSD 11.4:
-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0

FAILED: 3rdparty/zlib-ng/CMakeFiles/zlib.dir/zutil.c.o 
/usr/bin/cc -DHAVE_BUILTIN_CTZ -DHAVE_BUILTIN_CTZLL -DHAVE_VISIBILITY_HIDDEN -DHAVE_VISIBILITY_INTERNAL -DUNALIGNED64_OK -DUNALIGNED_OK -DWITH_GZFILEOP -DX86_AVX2 -DX86_AVX2_ADLER32 -DX86_AVX_CHUNKSET -DX86_FEATURES -DX86_PCLMULQDQ_CRC -DX86_SSE2 -DX86_SSE2_CHUNKSET -DX86_SSE2_SLIDEHASH -DX86_SSE42_CMP_STR -DX86_SSE42_CRC_HASH -DX86_SSE42_CRC_INTRIN -DX86_SSSE3 -DX86_SSSE3_ADLER32 -D_LARGEFILE64_SOURCE=1 -D__USE_LARGEFILE64 -I3rdparty/zlib-ng -I../../3rdparty/zlib-ng -fstack-protector-strong -Wall -Wno-implicit-fallthrough -O2 -g -DNDEBUG -fPIC -std=c99 -MD -MT 3rdparty/zlib-ng/CMakeFiles/zlib.dir/zutil.c.o -MF 3rdparty/zlib-ng/CMakeFiles/zlib.dir/zutil.c.o.d -o 3rdparty/zlib-ng/CMakeFiles/zlib.dir/zutil.c.o -c ../../3rdparty/zlib-ng/zutil.c
In file included from ../../3rdparty/zlib-ng/zutil.c:8:
In file included from ../../3rdparty/zlib-ng/zutil_p.h:11:
/usr/include/malloc.h:3:2: error: "<malloc.h> has been replaced by <stdlib.h>"
#error "<malloc.h> has been replaced by <stdlib.h>"
 ^
In file included from ../../3rdparty/zlib-ng/zutil.c:8:
../../3rdparty/zlib-ng/zutil_p.h:21:20: warning: implicit declaration of function 'memalign' is invalid in C99 [-Wimplicit-function-declaration]
    return (void *)memalign(64, size);
                   ^
../../3rdparty/zlib-ng/zutil_p.h:21:12: warning: cast to 'void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast]
    return (void *)memalign(64, size);
           ^
2 warnings and 1 error generated.

Although interestingly, zero issues on FreeBSD 12.2. In case it matters (for the warnings), 12.2 has a slightly newer version of Clang:
-- The C compiler identification is Clang 10.0.1
-- The CXX compiler identification is Clang 10.0.1

@past-due
Copy link
Contributor Author

past-due commented Mar 14, 2021

Reference: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=155429

On Linux/glibc <malloc.h> defines extensions (e.g., memalign, malloc_usable_size, mallinfo) that FreeBSD provides via <malloc_np.h> (e.g., *allocx, malloc_usable_size, mallctl) while similar to upstream jemalloc.

Reference: https://svnweb.freebsd.org/base?view=revision&revision=360984

It may be desirable to detect FreeBSD, and do something like:

  #ifdef __APPLE__
  #  include <stdlib.h>
+ #elif defined(__FreeBSD__)
+ #  include <stdlib.h>
+ #  include <malloc_np.h>
  #else
  #  include <malloc.h>
  #endif

@past-due past-due changed the title Compilation fails on FreeBSD 11.4 Compilation fails on FreeBSD < 12 Mar 14, 2021
@Dead2
Copy link
Member

Dead2 commented Mar 18, 2021

It may be desirable to detect FreeBSD, and do something like:

  #ifdef __APPLE__
  #  include <stdlib.h>
+ #elif defined(__FreeBSD__)
+ #  include <stdlib.h>
+ #  include <malloc_np.h>
  #else
  #  include <malloc.h>
  #endif

I guess this would also need an #elif defined(__FreeBSD__) to use __posix_memalign.

This sounds like something I could pull as a fix without waiting for a future stable release branch, since it is a minimal change that is (very) unlikely to have unknown effects on other platforms.
#884 is turning into a bigger refactoring PR that I will have to postpone merging until we open the develop branch for developing the next feature version.

nmoinvaz added a commit to nmoinvaz/zlib-ng that referenced this issue Mar 20, 2021
Co-authored-by: Hans Kristian Rosbach <hk-git@circlestorm.org>
Co-authored-by: concatime <concatime@users.noreply@github.com>
Dead2 added a commit that referenced this issue Mar 20, 2021
Co-authored-by: Hans Kristian Rosbach <hk-git@circlestorm.org>
Co-authored-by: concatime <concatime@users.noreply@github.com>
@Dead2
Copy link
Member

Dead2 commented Mar 23, 2021

This should be fixed in 2.0.2.

@Dead2 Dead2 closed this as completed Mar 23, 2021
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.

2 participants