Bug 473884

Summary: Build failure when configuring with UBSAN & LTO (using GCC)
Product: [Developer tools] valgrind Reporter: fanquake
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED NOT A BUG    
Severity: normal CC: pjfloyd
Priority: NOR    
Version First Reported In: 3.22 GIT   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description fanquake 2023-08-29 08:53:42 UTC
Building master @ 69ac8e03a2e22175337acf999f8c8814143ba08a, with gcc (Ubuntu 13.1.0-2ubuntu2~23.04) 13.1.0 on Ubuntu 23.04, and configuring with UBSAN & LTO currently fails to link:

./autogen.sh
./configure --enable-ubsan --enable-lto
make
<snip>

make[3]: Entering directory '/home/ubuntu/valgrind/memcheck'
../coregrind/link_tool_exe_linux 0x58000000 gcc     -o memcheck-amd64-linux -flto -flto-partition=one -fuse-linker-plugin -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-signedness -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wenum-conversion -Wimplicit-fallthrough=2 -Wold-style-declaration -finline-functions -fno-stack-protector -fsanitize=undefined -fno-sanitize=alignment -fno-strict-aliasing -fno-builtin   -fomit-frame-pointer -O2 -static -nodefaultlibs -nostartfiles -u _start  -m64 memcheck_amd64_linux-mc_leakcheck.o memcheck_amd64_linux-mc_malloc_wrappers.o memcheck_amd64_linux-mc_main.o memcheck_amd64_linux-mc_main_asm.o memcheck_amd64_linux-mc_translate.o memcheck_amd64_linux-mc_machine.o memcheck_amd64_linux-mc_errors.o ../coregrind/libcoregrind-amd64-linux.a ../VEX/libvex-amd64-linux.a -lgcc ../coregrind/libgcc-sup-amd64-linux.a 
<built-in>: warning: type of ‘__builtin___ubsan_handle_invalid_builtin’ does not match original declaration [-Wlto-type-mismatch]
../coregrind/m_compiler.c:311:6: note: type mismatch in parameter 1
  311 | void __ubsan_handle_invalid_builtin ( void )
      |      ^
../coregrind/m_compiler.c:311:6: note: ‘__ubsan_handle_invalid_builtin’ was previously declared here
<built-in>: warning: type of ‘__builtin___ubsan_handle_divrem_overflow’ does not match original declaration [-Wlto-type-mismatch]
../coregrind/m_compiler.c:262:6: note: type mismatch in parameter 1
  262 | void __ubsan_handle_divrem_overflow ( void )
      |      ^
<built-in>: warning: type of ‘__builtin___ubsan_handle_divrem_overflow’ does not match original declaration [-Wlto-type-mismatch]

<snip>

<built-in>: warning: type of ‘__builtin___ubsan_handle_shift_out_of_bounds’ does not match original declaration [-Wlto-type-mismatch]
../coregrind/m_compiler.c:290:6: note: type mismatch in parameter 1
<built-in>: warning: type of ‘__builtin___ubsan_handle_shift_out_of_bounds’ does not match original declaration [-Wlto-type-mismatch]
../coregrind/m_compiler.c:290:6: note: type mismatch in parameter 1
../coregrind/m_compiler.c:290:6: note: ‘__ubsan_handle_shift_out_of_bounds’ was previously declared here
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `vgPlain_strtoll16':
/home/ubuntu/valgrind/memcheck/../coregrind/m_libcbase.c:168: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `d_number':
/home/ubuntu/valgrind/memcheck/../coregrind/m_demangle/cp-demangle.c:1844: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `vgPlain_strtoll10':
/home/ubuntu/valgrind/memcheck/../coregrind/m_libcbase.c:108: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `vgPlain_debugLog':
/home/ubuntu/valgrind/memcheck/../coregrind/m_debuglog.c:1295: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `vgModuleLocal_canonicaliseTables':
/home/ubuntu/valgrind/memcheck/../coregrind/m_xarray.c:133: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o:/home/ubuntu/valgrind/memcheck/../coregrind/m_xarray.c:133: more undefined references to `__ubsan_handle_mul_overflow' follow
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `dis_Grp4.constprop.0':
/home/ubuntu/valgrind/memcheck/../VEX/priv/guest_amd64_toIR.c:2278: undefined reference to `__ubsan_handle_builtin_unreachable'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `expr2vbits':
/home/ubuntu/valgrind/memcheck/mc_translate.c:1814: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `do_shadow_PUTI':
/home/ubuntu/valgrind/memcheck/mc_translate.c:1765: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o: in function `schemeS':
/home/ubuntu/valgrind/memcheck/mc_translate.c:7435: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /home/ubuntu/valgrind/memcheck/mc_translate.c:7667: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /home/ubuntu/valgrind/memcheck/mc_translate.c:7737: undefined reference to `__ubsan_handle_mul_overflow'
/usr/bin/ld: /tmp/cc66NgSf.ltrans0.ltrans.o:/home/ubuntu/valgrind/memcheck/mc_translate.c:7540: more undefined references to `__ubsan_handle_mul_overflow' follow
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:1135: memcheck-amd64-linux] Error 1
make[3]: Leaving directory '/home/ubuntu/valgrind/memcheck'
Comment 1 Paul Floyd 2023-08-29 20:00:38 UTC
Valgrind tools don't link with any libraries, which I think precludes using any sanitizers.

I don't think that you'll see much benefit with LTO either.