Description
Zig Version
0.14.0
Steps to Reproduce and Observed Behavior
Previously, we were using 0.14.0-dev.3188+34644511b
and everything was fine.
After bumping to 0.14.0 i am facing an issue while configuring protobuf
to use zlib, related to ubsan, that seems to get enabled by default even if the build is -O{2,3}
:
| namespace conftest {
| extern "C" int zlibVersion ();
| }
| int
| main (void)
| {
| return conftest::zlibVersion ();
| ;
| return 0;
| }
configure:20813: zig-cxx -o conftest -O2 -std=c++11 -DNDEBUG -I/home/federico/Work/libs/build_zig/zlib-prefix/src/zlib -L/home/federico/Work/libs/build_zig/zlib-prefix/src/zlib conftest.cpp -lz >&5
ld.lld: error: undefined symbol: __ubsan_handle_shift_out_of_bounds
>>> referenced by zutil.c:44
>>> zutil.o:(zlibCompileFlags) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
>>> referenced by zutil.c:50
>>> zutil.o:(zlibCompileFlags) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
>>> referenced by zutil.c:56
>>> zutil.o:(zlibCompileFlags) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
ld.lld: error: undefined symbol: __ubsan_handle_sub_overflow
>>> referenced by zutil.c:132
>>> zutil.o:(zError) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
ld.lld: error: undefined symbol: __ubsan_handle_out_of_bounds
>>> referenced by zutil.c:132
>>> zutil.o:(zError) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
ld.lld: error: undefined symbol: __ubsan_handle_pointer_overflow
>>> referenced by zutil.c:132
>>> zutil.o:(zError) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
ld.lld: error: undefined symbol: __ubsan_handle_type_mismatch_v1
>>> referenced by zutil.c:132
>>> zutil.o:(zError) in archive /home/federico/Work/libs/build_zig/zlib-prefix/src/zlib/libz.a
configure:20813: $? = 1
Note: zig-cxx
is a small wrapper:
#!/bin/bash
exec zig c++ -target $(uname -m)-linux-gnu.2.17 "$@"
What i get is: zlibVersion
has some kind of ubsan. But since i am building protobuf in -O3
i did not expect ubsan to be enabled on the build.
A workaround i found is to use -O5
; at that point probably some conditional somewhere disables ubsan, then the build works fine and clang fallbacks at -O3
:
warning: optimization level '-O5' is not supported; using '-O3' instead
Given this all worked fine until a few weeks ago, i think #22488 perhaps changed anything?
Expected Behavior
The release optimized build should not enforce ubsan.