wasi-sdk icon indicating copy to clipboard operation
wasi-sdk copied to clipboard

undeclared identifier 'max_align_t' when compiling libgit2

Open jendrikw opened this issue 5 years ago • 3 comments
trafficstars

I'm not sure if the issue is with wasi-sdk or libgit2. I'm not super experienced in C programming but the error message is from wasi-sysroot/include/__struct_sockaddress_in.h, so I'm posting it here. Any hints?

(There is a port to emscripten at https://github.com/petersalomonsen/wasm-git/, but I'd like to compile it without emscripten.)

I use the following bash script to download and compile libgit2:

#!/usr/bin/bash
set -e
cd "$(dirname "$0")" || exit 1
rm -rf libgit2 build
git clone https://github.com/libgit2/libgit2 --depth 1

cd libgit2
# with NODEFS we can't open a file for writing if mode is set to 0444
sed -i 's/GIT_PACK_FILE_MODE 0444/GIT_PACK_FILE_MODE 0644/g' src/pack.h
sed -i 's/GIT_OBJECT_FILE_MODE 0444/GIT_OBJECT_FILE_MODE 0644/g' src/odb.h
cd ..

mkdir build
cd build

export CC=../../wasi-sdk-8.0/bin/clang
export CXX=../../wasi-sdk-8.0/bin/clang++
cmake \
    -DCMAKE_C_COMPILER_TARGET=wasm32-unkown-wasi -DCMAKE_C_FLAGS="-v --sysroot=$(pwd)/../../wasi-sdk-8.0/share/wasi-sysroot -Wno-incompatible-pointer-types" \
    -DCMAKE_VERBOSE_MAKEFILE=true \
    -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON \
    -DUSE_BUNDLED_ZLIB=ON \
    ../libgit2
cmake -build ../libgit2
make
wasm2wat examples/lg2.wasm -o examples/lg2.wat

the output:

Cloning into 'libgit2'...
remote: Enumerating objects: 5989, done.
remote: Counting objects: 100% (5989/5989), done.
remote: Compressing objects: 100% (4599/4599), done.
remote: Total 5989 (delta 225), reused 4935 (delta 182), pack-reused 0
Receiving objects: 100% (5989/5989), 4.21 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (225/225), done.
-- The C compiler identification is Clang 9.0.0
-- Check for working C compiler: /home/MYUSER/SOMEPATH/wasi-sdk-8.0/bin/clang
-- Check for working C compiler: /home/MYUSER/SOMEPATH/wasi-sdk-8.0/bin/clang - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.6.3") 
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Could NOT find Threads (missing: Threads_FOUND) 
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM - Success
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC - Failed
-- Performing Test HAVE_STRUCT_STAT_MTIME_NSEC
-- Performing Test HAVE_STRUCT_STAT_MTIME_NSEC - Failed
-- Performing Test HAVE_STRUCT_STAT_NSEC
-- Performing Test HAVE_STRUCT_STAT_NSEC - Success
-- Performing Test IS_WALL_SUPPORTED
-- Performing Test IS_WALL_SUPPORTED - Success
-- Performing Test IS_WEXTRA_SUPPORTED
-- Performing Test IS_WEXTRA_SUPPORTED - Success
-- Performing Test IS_WDOCUMENTATION_SUPPORTED
-- Performing Test IS_WDOCUMENTATION_SUPPORTED - Success
-- Performing Test IS_WNO_MISSING_FIELD_INITIALIZERS_SUPPORTED
-- Performing Test IS_WNO_MISSING_FIELD_INITIALIZERS_SUPPORTED - Success
-- Performing Test IS_WSTRICT_ALIASING_SUPPORTED
-- Performing Test IS_WSTRICT_ALIASING_SUPPORTED - Success
-- Performing Test IS_WSTRICT_PROTOTYPES_SUPPORTED
-- Performing Test IS_WSTRICT_PROTOTYPES_SUPPORTED - Success
-- Performing Test IS_WDECLARATION_AFTER_STATEMENT_SUPPORTED
-- Performing Test IS_WDECLARATION_AFTER_STATEMENT_SUPPORTED - Success
-- Performing Test IS_WSHIFT_COUNT_OVERFLOW_SUPPORTED
-- Performing Test IS_WSHIFT_COUNT_OVERFLOW_SUPPORTED - Success
-- Performing Test IS_WUNUSED_CONST_VARIABLE_SUPPORTED
-- Performing Test IS_WUNUSED_CONST_VARIABLE_SUPPORTED - Success
-- Performing Test IS_WUNUSED_FUNCTION_SUPPORTED
-- Performing Test IS_WUNUSED_FUNCTION_SUPPORTED - Success
-- Performing Test IS_WINT_CONVERSION_SUPPORTED
-- Performing Test IS_WINT_CONVERSION_SUPPORTED - Success
-- Performing Test IS_WFORMAT_SUPPORTED
-- Performing Test IS_WFORMAT_SUPPORTED - Success
-- Performing Test IS_WFORMAT_SECURITY_SUPPORTED
-- Performing Test IS_WFORMAT_SECURITY_SUPPORTED - Success
-- Performing Test IS_WNO_DOCUMENTATION_DEPRECATED_SYNC_SUPPORTED
-- Performing Test IS_WNO_DOCUMENTATION_DEPRECATED_SYNC_SUPPORTED - Success
-- Looking for futimens
-- Looking for futimens - found
-- Checking prototype qsort_r for HAVE_QSORT_R_BSD - False
-- Checking prototype qsort_r for HAVE_QSORT_R_GNU - False
-- Looking for qsort_s
-- Looking for qsort_s - not found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Found OpenSSL: /usr/lib32/libcrypto.so (found version "1.1.1e")  
-- Found mbedTLS:
--   version 2.16.5
--   TLS: /usr/lib/libmbedtls.so
--   X509: /usr/lib/libmbedx509.so
--   Crypto: /usr/lib/libmbedcrypto.so
-- Found PCRE: /usr/lib32/libpcre.so  
-- http-parser version 2 was not found or disabled; using bundled 3rd-party sources.
-- Performing Test IS_WIMPLICIT_FALLTHROUGH_1_SUPPORTED
-- Performing Test IS_WIMPLICIT_FALLTHROUGH_1_SUPPORTED - Failed
-- Performing Test IS_WNO_IMPLICIT_FALLTHROUGH_SUPPORTED
-- Performing Test IS_WNO_IMPLICIT_FALLTHROUGH_SUPPORTED - Success
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
-- Found GSSAPI: /usr/lib32/libgssapi_krb5.so;/usr/lib32/libkrb5.so;/usr/lib32/libk5crypto.so;/usr/lib32/libcom_err.so  
-- Enabled features:
 * nanoseconds, whether to use sub-second file mtimes and ctimes
 * tracing, tracing support
 * SHA, using CollisionDetection
 * regex, using system regcomp
 * http-parser, http-parser support (bundled)
 * zlib, using bundled zlib

-- Disabled features:
 * debugpool, debug pool allocator
 * threadsafe, threadsafe support
 * HTTPS
 * SSH, SSH transport support
 * ntlmclient, NTLM authentication support for Unix
 * SPNEGO, SPNEGO authentication support
 * iconv, iconv encoding conversion support

-- Configuring done
-- Generating done
-- Build files have been written to: /home/MYUSER/SOMEPATH/libgit2/build
-- Could NOT find Threads (missing: Threads_FOUND) 
-- Checking prototype qsort_r for HAVE_QSORT_R_BSD - False
-- Checking prototype qsort_r for HAVE_QSORT_R_GNU - False
-- Found mbedTLS:
--   version 2.16.5
--   TLS: /usr/lib/libmbedtls.so
--   X509: /usr/lib/libmbedx509.so
--   Crypto: /usr/lib/libmbedcrypto.so
-- http-parser version 2 was not found or disabled; using bundled 3rd-party sources.
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
-- Enabled features:
 * nanoseconds, whether to use sub-second file mtimes and ctimes
 * tracing, tracing support
 * SHA, using CollisionDetection
 * regex, using system regcomp
 * http-parser, http-parser support (bundled)
 * zlib, using bundled zlib

-- Disabled features:
 * debugpool, debug pool allocator
 * threadsafe, threadsafe support
 * HTTPS
 * SSH, SSH transport support
 * ntlmclient, NTLM authentication support for Unix
 * SPNEGO, SPNEGO authentication support
 * iconv, iconv encoding conversion support

-- Configuring done
-- Generating done
-- Build files have been written to: /home/MYUSER/SOMEPATH/libgit2/build
/usr/bin/cmake -S/home/MYUSER/SOMEPATH/libgit2/libgit2 -B/home/MYUSER/SOMEPATH/libgit2/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/MYUSER/SOMEPATH/libgit2/build/CMakeFiles /home/MYUSER/SOMEPATH/libgit2/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/MYUSER/SOMEPATH/libgit2/build'
make -f src/CMakeFiles/git2internal.dir/build.make src/CMakeFiles/git2internal.dir/depend
make[2]: Entering directory '/home/MYUSER/SOMEPATH/libgit2/build'
cd /home/MYUSER/SOMEPATH/libgit2/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/MYUSER/SOMEPATH/libgit2/libgit2 /home/MYUSER/SOMEPATH/libgit2/libgit2/src /home/MYUSER/SOMEPATH/libgit2/build /home/MYUSER/SOMEPATH/libgit2/build/src /home/MYUSER/SOMEPATH/libgit2/build/src/CMakeFiles/git2internal.dir/DependInfo.cmake --color=
Scanning dependencies of target git2internal
make[2]: Leaving directory '/home/MYUSER/SOMEPATH/libgit2/build'
make -f src/CMakeFiles/git2internal.dir/build.make src/CMakeFiles/git2internal.dir/build
make[2]: Entering directory '/home/MYUSER/SOMEPATH/libgit2/build'
[  1%] Building C object src/CMakeFiles/git2internal.dir/alloc.c.o
cd /home/MYUSER/SOMEPATH/libgit2/build/src && /home/MYUSER/SOMEPATH/wasi-sdk-8.0/bin/clang --target=wasm32-unkown-wasi -DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\" -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\" -DSHA1DC_NO_STANDARD_INCLUDES=1 -D_FILE_OFFSET_BITS=64 -I/home/MYUSER/SOMEPATH/libgit2/build/src -I/home/MYUSER/SOMEPATH/libgit2/libgit2/src -I/home/MYUSER/SOMEPATH/libgit2/libgit2/include -I/home/MYUSER/SOMEPATH/libgit2/libgit2/deps/http-parser -I/home/MYUSER/SOMEPATH/libgit2/libgit2/deps/zlib  -D_GNU_SOURCE -v --sysroot=/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot -Wno-incompatible-pointer-types -Wall -Wextra -Wdocumentation -Wno-missing-field-initializers -Wstrict-aliasing -Wstrict-prototypes -Wdeclaration-after-statement -Wshift-count-overflow -Wunused-const-variable -Wunused-function -Wint-conversion -Wformat -Wformat-security -Wno-documentation-deprecated-sync -g -D_DEBUG -O0   -std=gnu90 -o CMakeFiles/git2internal.dir/alloc.c.o   -c /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c
clang version 9.0.0 (https://github.com/llvm/llvm-project 0399d5a9682b3cef71c653373e38890c63c4c365)
Target: wasm32-unkown-wasi
Thread model: posix
InstalledDir: /home/MYUSER/SOMEPATH/wasi-sdk-8.0/bin
 "/home/MYUSER/SOMEPATH/wasi-sdk-8.0/bin/clang-9" -cc1 -triple wasm32-unkown-wasi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name alloc.c -mrelocation-model static -mthread-model posix -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu generic -fvisibility hidden -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/MYUSER/SOMEPATH/libgit2/build/src/CMakeFiles/git2internal.dir/alloc.c.gcno -resource-dir /home/MYUSER/SOMEPATH/wasi-sdk-8.0/lib/clang/9.0.0 -D "SHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" -D "SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" -D SHA1DC_NO_STANDARD_INCLUDES=1 -D _FILE_OFFSET_BITS=64 -I /home/MYUSER/SOMEPATH/libgit2/build/src -I /home/MYUSER/SOMEPATH/libgit2/libgit2/src -I /home/MYUSER/SOMEPATH/libgit2/libgit2/include -I /home/MYUSER/SOMEPATH/libgit2/libgit2/deps/http-parser -I /home/MYUSER/SOMEPATH/libgit2/libgit2/deps/zlib -D _GNU_SOURCE -D _DEBUG -isysroot /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot -internal-isystem /home/MYUSER/SOMEPATH/wasi-sdk-8.0/lib/clang/9.0.0/include -internal-isystem /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/wasm32-wasi -internal-isystem /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include -O0 -Wno-incompatible-pointer-types -Wall -Wextra -Wdocumentation -Wno-missing-field-initializers -Wstrict-aliasing -Wstrict-prototypes -Wdeclaration-after-statement -Wshift-count-overflow -Wunused-const-variable -Wunused-function -Wint-conversion -Wformat -Wformat-security -Wno-documentation-deprecated-sync -std=gnu90 -fdebug-compilation-dir /home/MYUSER/SOMEPATH/libgit2/build/src -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gnustep -fno-common -fdiagnostics-show-option -o CMakeFiles/git2internal.dir/alloc.c.o -x c /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target wasm32-wasi
ignoring nonexistent directory "/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/wasm32-wasi"
#include "..." search starts here:
#include <...> search starts here:
 /home/MYUSER/SOMEPATH/libgit2/build/src
 /home/MYUSER/SOMEPATH/libgit2/libgit2/src
 /home/MYUSER/SOMEPATH/libgit2/libgit2/include
 /home/MYUSER/SOMEPATH/libgit2/libgit2/deps/http-parser
 /home/MYUSER/SOMEPATH/libgit2/libgit2/deps/zlib
 /home/MYUSER/SOMEPATH/wasi-sdk-8.0/lib/clang/9.0.0/include
 /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include
End of search list.
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/allocators/stdalloc.h:11:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/common.h:74:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/arpa/inet.h:9:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/netinet/in.h:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/sys/socket.h:5:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__header_sys_socket.h:5:
/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__struct_sockaddr.h:10:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t sa_family;
             ^
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/allocators/stdalloc.h:11:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/common.h:74:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/arpa/inet.h:9:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/netinet/in.h:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/sys/socket.h:5:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__header_sys_socket.h:6:
/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__struct_sockaddr_storage.h:10:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t ss_family;
             ^
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/allocators/stdalloc.h:11:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/common.h:74:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/arpa/inet.h:9:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/netinet/in.h:13:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__header_netinet_in.h:6:
/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__struct_sockaddr_in.h:12:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t sin_family;
             ^
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/alloc.c:10:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/allocators/stdalloc.h:11:
In file included from /home/MYUSER/SOMEPATH/libgit2/libgit2/src/common.h:74:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/arpa/inet.h:9:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/netinet/in.h:13:
In file included from /home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__header_netinet_in.h:7:
/home/MYUSER/SOMEPATH/libgit2/build/../../wasi-sdk-8.0/share/wasi-sysroot/include/__struct_sockaddr_in6.h:12:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t sin6_family;
             ^
4 errors generated.
make[2]: *** [src/CMakeFiles/git2internal.dir/build.make:83: src/CMakeFiles/git2internal.dir/alloc.c.o] Error 1
make[2]: Leaving directory '/home/MYUSER/SOMEPATH/libgit2/build'
make[1]: *** [CMakeFiles/Makefile2:178: src/CMakeFiles/git2internal.dir/all] Error 2
make[1]: Leaving directory '/home/MYUSER/SOMEPATH/libgit2/build'
make: *** [Makefile:150: all] Error 2

jendrikw avatar Apr 01 '20 15:04 jendrikw

This is quite easily reproducible with:

$ echo "#include <sys/socket.h>" > test.c
$ ./bin/clang --sysroot share/wasi-sysroot/ -std=c90 test.c
In file included from test.c:1:
In file included from share/wasi-sysroot//include/sys/socket.h:5:
In file included from share/wasi-sysroot//include/__header_sys_socket.h:5:
share/wasi-sysroot//include/__struct_sockaddr.h:10:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t sa_family;

The problem looks like max_align_t type doesn't get defined with -std=c90. clang''s stddef.h only includes it for C11 and above:

https://github.com/llvm/llvm-project/blob/3a7865df626c061fa72cb731f0af763254ed3beb/clang/lib/Headers/stddef.h#L102

We probably need to fix __struct_sockaddr.h not to rely on it..

sbc100 avatar Apr 01 '20 17:04 sbc100

Thanks, I tried to minimize the example by trying to include different things, but I didn't try sys/socket.h. Would the error go away I passed -std=c11 to clang?

jendrikw avatar Apr 01 '20 17:04 jendrikw

Yup, or just dropping c90 (since c11 is the default). But still we need to fix the actual issue in the SDK.

sbc100 avatar Apr 01 '20 18:04 sbc100

Any news on this?

cprecioso avatar Oct 10 '22 07:10 cprecioso

I've now submitted https://github.com/WebAssembly/wasi-libc/pull/335 to fix this.

sunfishcode avatar Oct 10 '22 17:10 sunfishcode