WasmEdge: Fails to build with GCC 14

Summary

Debian has upgraded GCC version to default to gcc 14. Unfortunately, this makes the wasmedge package failing to build because of newly introduced warnings:

[ 34%] Building CXX object lib/aot/CMakeFiles/wasmedgeAOT.dir/cache.cpp.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/lib/aot && /usr/bin/c++ -DFMT_SHARED -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -DSPDLOG_SHARED_LIB -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/include -I/<<PKGBUILDDIR>>/thirdparty/blake3 -I/<<PKGBUILDDIR>>/include -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/lib/system -isystem /usr/lib/llvm-16/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -std=c++17 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden  -fno-exceptions -Wall -Wextra -Werror -Wno-error=pedantic -Wno-error=dangling-reference -Wno-psabi -MD -MT lib/aot/CMakeFiles/wasmedgeAOT.dir/cache.cpp.o -MF CMakeFiles/wasmedgeAOT.dir/cache.cpp.o.d -o CMakeFiles/wasmedgeAOT.dir/cache.cpp.o -c /<<PKGBUILDDIR>>/lib/aot/cache.cpp
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/spdlog/common.h:16,
                 from /usr/include/spdlog/spdlog.h:12,
                 from /<<PKGBUILDDIR>>/include/common/log.h:18,
                 from /<<PKGBUILDDIR>>/include/common/enum_errcode.hpp:18,
                 from /<<PKGBUILDDIR>>/include/common/errcode.h:16,
                 from /<<PKGBUILDDIR>>/include/loader/filemgr.h:17,
                 from /<<PKGBUILDDIR>>/lib/loader/filemgr.cpp:4:
In destructor ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>]’,
    inlined from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>]’ at /usr/include/c++/14/bits/stl_vector.h:738:7,
    inlined from ‘constexpr void std::_Optional_payload_base<_Tp>::_M_destroy() [with _Tp = std::vector<unsigned char>]’ at /usr/include/c++/14/optional:283:35,
    inlined from ‘constexpr void std::_Optional_payload_base<_Tp>::_M_reset() [with _Tp = std::vector<unsigned char>]’ at /usr/include/c++/14/optional:314:14,
    inlined from ‘constexpr void std::_Optional_base_impl<_Tp, _Dp>::_M_reset() [with _Tp = std::vector<unsigned char>; _Dp = std::_Optional_base<std::vector<unsigned char>, false, false>]’ at /usr/include/c++/14/optional:466:53,
    inlined from ‘std::enable_if_t<((bool)is_constructible_v<_Tp, _Args ...>), _Tp&> std::optional<_Tp>::emplace(_Args&& ...) [with _Args = {std::vector<unsigned char, std::allocator<unsigned char> >}; _Tp = std::vector<unsigned char>]’ at /usr/include/c++/14/optional:915:18,
    inlined from ‘WasmEdge::Expect<void> WasmEdge::FileMgr::setCode(std::vector<unsigned char>)’ at /<<PKGBUILDDIR>>/lib/loader/filemgr.cpp:52:21:
/usr/include/c++/14/bits/stl_vector.h:369:59: error: ‘((std::_Vector_base<unsigned char, std::allocator<unsigned char> >*)((char*)this + 8))[2].std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_impl.std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl::std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl_data.std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl_data::_M_start’ may be used uninitialized [-Werror=maybe-uninitialized]
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                                                   ~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:31: error: ‘((std::_Vector_base<unsigned char, std::allocator<unsigned char> >*)((char*)this + 8))[2].std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_impl.std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl::std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl_data.std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_impl_data::_M_end_of_storage’ may be used uninitialized [-Werror=maybe-uninitialized]
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[3]: *** [lib/loader/CMakeFiles/wasmedgeLoaderFileMgr.dir/build.make:79: lib/loader/CMakeFiles/wasmedgeLoaderFileMgr.dir/filemgr.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....

Seems that gcc14 thinks that the vector in https://github.com/WasmEdge/WasmEdge/blob/0.13.5/lib/loader/filemgr.cpp#L50-L57 could end up uninitialized.

Appendix

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks, @diederikdehaas, for the confirmation.
This patch can also be applied to 0.14.0.

The build now succeeds \o/ https://salsa.debian.org/diederik/wasmedge/-/pipelines/716827

EDIT: Ignore the other issues, it’s not supposed to build on i386, so I need to modify the pipeline config EDIT2: Better pipeline: https://salsa.debian.org/diederik/wasmedge/-/pipelines/716861

FWIW, the CI is building with -DCMAKE_BUILD_TYPE=None and it somehow uses -O2. -DCMAKE_BUILD_TYPE=Release adds -O3. Use -DCMAKE_BUILD_TYPE=None and add CXXFLAGS=-O2 will get the same error.

Modified Dockerfile from above to get the error:

FROM debian:testing

RUN apt update && apt upgrade -y && apt install -y \
	software-properties-common \
	wget \
	cmake \
	ninja-build \
	curl \
	git \
	dpkg-dev \
	llvm-dev \
	liblld-dev \
	gcc \
	g++ \
	rpm \
	dpkg-dev \
	libspdlog-dev

WORKDIR /
RUN git clone --depth 1 --branch 0.13.5 https://github.com/WasmEdge/WasmEdge.git
RUN git config --global --add safe.directory /WasmEdge
WORKDIR /WasmEdge
RUN CXXFLAGS=-O2 cmake -Bbuild \
	-GNinja \
	-DCMAKE_BUILD_TYPE=None \
	-DWASMEDGE_BUILD_PLUGINS=OFF \
	-DWASMEDGE_BUILD_PACKAGE="TGZ" .
RUN cmake --build build
RUN ./build/tools/wasmedge/wasmedge --version

Hi @siretart, Thanks for this. I would like to know which docker image we should use to verify this behavior. We currently use debian:testing, however, it still uses gcc 13 and it doesn’t trigger this error. Is there any choice that we can use for verifying the latest changes that Debian does for the default toolchain?

@q82419 Let’s fix this before 0.14.1-rc.2 release.