Subject: cmocka: ftbfs with LTO (link time optimization) enabled

From: Matthias Klose <[email-masked]>
Date: Tue, 19 Jul 2022 16:50:59 +0000

Package: src:cmocka
Version: 1.1.5-2
Severity: minor
Tags: sid bookworm
User: [email-masked]
Usertags: ftbfs-lto

This package currently fails to build (at least on the amd64
architecture) with link time optimizations enabled.  For a background
for LTO please see

https://wiki.debian.org/ToolChain/LTO

The goal is to enable this optimization by default in an upcoming
Debian release in dpkg-buildflags for 64bit architectures.  The goal
is to get this package to build with link time optimizations, or to
explicitly disable link time optimizations for this package build.

To reproduce the build failure, enable the lto optimization in
testing/unstable by adding "optimize=+lto" to DEB_BUILD_MAINT_OPTIONS
in the debian/rules file, or if this macro is unset, just set it:

export DEB_BUILD_MAINT_OPTIONS = optimize=+lto

Please try to fix the build with lto enabled, fixing the packaging or
forwarding the issue upstream. If the issue cannot be fixed,
explicitly disallow building the package with lto by adding to your
rules file:

export DEB_BUILD_MAINT_OPTIONS = optimize=-lto

or adding that string to your existing setting of DEB_BUILD_MAINT_OPTIONS.

The full build log can be found at:
http://qa-logs.debian.net/2022/06/09/dpkglto/cmocka_1.1.5-2_unstable_dpkglto.log
The last lines of the build log are at the end of this report.

[...]
make  -f example/CMakeFiles/assert_module_test.dir/build.make example/CMakeFiles/assert_module_test.dir/build
make[3]: Entering directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make  -f example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/build.make example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/build
make[3]: Entering directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now CMakeFiles/allocate_module_test.dir/allocate_module.c.o CMakeFiles/allocate_module_test.dir/allocate_module_test.c.o -o allocate_module_test  -Wl,-rpath,/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src ../src/libcmocka.so.0.7.0 /usr/lib/x86_64-linux-gnu/librt.so 
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[ 83%] Building C object example/CMakeFiles/assert_macro_test.dir/assert_macro.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example -I/<<PKGBUILDDIR>>/example -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/CMakeFiles/assert_macro_test.dir/assert_macro.c.o -MF CMakeFiles/assert_macro_test.dir/assert_macro.c.o.d -o CMakeFiles/assert_macro_test.dir/assert_macro.c.o -c /<<PKGBUILDDIR>>/example/assert_macro.c
[ 84%] Building C object example/CMakeFiles/assert_module_test.dir/assert_module.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cc  -DUNIT_TESTING=1 -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example -I/<<PKGBUILDDIR>>/example -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/CMakeFiles/assert_module_test.dir/assert_module.c.o -MF CMakeFiles/assert_module_test.dir/assert_module.c.o.d -o CMakeFiles/assert_module_test.dir/assert_module.c.o -c /<<PKGBUILDDIR>>/example/assert_module.c
[ 86%] Building C object example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/waiter_test_wrap.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/chef_wrap && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/chef_wrap -I/<<PKGBUILDDIR>>/example/mock/chef_wrap -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/waiter_test_wrap.c.o -MF CMakeFiles/waiter_test_wrap.dir/waiter_test_wrap.c.o.d -o CMakeFiles/waiter_test_wrap.dir/waiter_test_wrap.c.o -c /<<PKGBUILDDIR>>/example/mock/chef_wrap/waiter_test_wrap.c
[ 86%] Built target test_exception_handler
make  -f example/mock/uptime/CMakeFiles/test_uptime.dir/build.make example/mock/uptime/CMakeFiles/test_uptime.dir/depend
make[3]: Entering directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /<<PKGBUILDDIR>> /<<PKGBUILDDIR>>/example/mock/uptime /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/uptime /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/uptime/CMakeFiles/test_uptime.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[ 87%] Linking C executable test_strmatch
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/tests && /usr/bin/cmake -E cmake_link_script CMakeFiles/test_strmatch.dir/link.txt --verbose=1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make  -f example/mock/uptime/CMakeFiles/test_uptime.dir/build.make example/mock/uptime/CMakeFiles/test_uptime.dir/build
make[3]: Entering directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[ 87%] Built target simple_test
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now CMakeFiles/test_strmatch.dir/test_strmatch.c.o -o test_strmatch  ../src/libcmocka-static.a 
[ 90%] Building C object example/CMakeFiles/assert_macro_test.dir/assert_macro_test.c.o
[ 90%] Building C object example/CMakeFiles/assert_module_test.dir/assert_module_test.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example -I/<<PKGBUILDDIR>>/example -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/CMakeFiles/assert_module_test.dir/assert_module_test.c.o -MF CMakeFiles/assert_module_test.dir/assert_module_test.c.o.d -o CMakeFiles/assert_module_test.dir/assert_module_test.c.o -c /<<PKGBUILDDIR>>/example/assert_module_test.c
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example -I/<<PKGBUILDDIR>>/example -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/CMakeFiles/assert_macro_test.dir/assert_macro_test.c.o -MF CMakeFiles/assert_macro_test.dir/assert_macro_test.c.o.d -o CMakeFiles/assert_macro_test.dir/assert_macro_test.c.o -c /<<PKGBUILDDIR>>/example/assert_macro_test.c
[ 92%] Building C object example/mock/uptime/CMakeFiles/test_uptime.dir/test_uptime.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/uptime && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/uptime -I/<<PKGBUILDDIR>>/example/mock/uptime -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -std=gnu99 -Wpedantic -Wall -Wshadow -Wmissing-prototypes -Wcast-align -Werror=address -Wstrict-prototypes -Werror=strict-prototypes -Wwrite-strings -Werror=write-strings -Werror-implicit-function-declaration -Wpointer-arith -Werror=pointer-arith -Wdeclaration-after-statement -Werror=declaration-after-statement -Wreturn-type -Werror=return-type -Wuninitialized -Werror=uninitialized -Wimplicit-fallthrough -Werror=strict-overflow -Wstrict-overflow=2 -Wno-format-zero-length -Wmissing-field-initializers -Wformat -Wformat-security -Werror=format-security -fno-common -fstack-protector-strong -fstack-clash-protection -MD -MT example/mock/uptime/CMakeFiles/test_uptime.dir/test_uptime.c.o -MF CMakeFiles/test_uptime.dir/test_uptime.c.o.d -o CMakeFiles/test_uptime.dir/test_uptime.c.o -c /<<PKGBUILDDIR>>/example/mock/uptime/test_uptime.c
[ 93%] Building C object example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/chef.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/chef_wrap && /usr/bin/cc  -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/chef_wrap -I/<<PKGBUILDDIR>>/example/mock/chef_wrap -I/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu -I/<<PKGBUILDDIR>>/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIE -MD -MT example/mock/chef_wrap/CMakeFiles/waiter_test_wrap.dir/chef.c.o -MF CMakeFiles/waiter_test_wrap.dir/chef.c.o.d -o CMakeFiles/waiter_test_wrap.dir/chef.c.o -c /<<PKGBUILDDIR>>/example/mock/chef_wrap/chef.c
[ 95%] Linking C executable assert_macro_test
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cmake -E cmake_link_script CMakeFiles/assert_macro_test.dir/link.txt --verbose=1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[ 96%] Linking C executable assert_module_test
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example && /usr/bin/cmake -E cmake_link_script CMakeFiles/assert_module_test.dir/link.txt --verbose=1
[ 98%] Linking C executable waiter_test_wrap
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now CMakeFiles/assert_macro_test.dir/assert_macro.c.o CMakeFiles/assert_macro_test.dir/assert_macro_test.c.o -o assert_macro_test  -Wl,-rpath,/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src ../src/libcmocka.so.0.7.0 /usr/lib/x86_64-linux-gnu/librt.so 
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/chef_wrap && /usr/bin/cmake -E cmake_link_script CMakeFiles/waiter_test_wrap.dir/link.txt --verbose=1
[ 98%] Built target allocate_module_test
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now CMakeFiles/assert_module_test.dir/assert_module.c.o CMakeFiles/assert_module_test.dir/assert_module_test.c.o -o assert_module_test  -Wl,-rpath,/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src ../src/libcmocka.so.0.7.0 /usr/lib/x86_64-linux-gnu/librt.so 
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now -Wl,--wrap=chef_cook CMakeFiles/waiter_test_wrap.dir/waiter_test_wrap.c.o CMakeFiles/waiter_test_wrap.dir/chef.c.o -o waiter_test_wrap  -Wl,-rpath,/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src ../../../src/libcmocka.so.0.7.0 /usr/lib/x86_64-linux-gnu/librt.so 
[ 98%] Built target test_cmockery
[100%] Linking C executable test_uptime
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/example/mock/uptime && /usr/bin/cmake -E cmake_link_script CMakeFiles/test_uptime.dir/link.txt --verbose=1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
/usr/bin/cc -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now  -Wl,--wrap=uptime CMakeFiles/test_uptime.dir/test_uptime.c.o -o test_uptime  -Wl,-rpath,/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src ../../../src/libcmocka.so.0.7.0 /usr/lib/x86_64-linux-gnu/librt.so 
[100%] Built target assert_macro_test
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[100%] Built target waiter_test_wrap
[100%] Built target assert_module_test
/usr/bin/ld: /tmp/ccRysoKW.ltrans0.ltrans.o: in function `calc_uptime':
./obj-x86_64-linux-gnu/example/mock/uptime/./example/mock/uptime/uptime.c:35: undefined reference to `__wrap_uptime'
collect2: error: ld returned 1 exit status
make[3]: *** [example/mock/uptime/CMakeFiles/test_uptime.dir/build.make:102: example/mock/uptime/test_uptime] Error 1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:1865: example/mock/uptime/CMakeFiles/test_uptime.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
[100%] Built target test_strmatch
make[2]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make[1]: *** [Makefile:169: all] Error 2
make[1]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
dh_auto_build: error: cd obj-x86_64-linux-gnu && make -j8 "INSTALL=install --strip-program=true" VERBOSE=1 returned exit code 2
make: *** [debian/rules:10: build] Error 25
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

---

From: Hefee <[email-masked]>
Date: Tue, 19 Dec 2023 15:38:50 +0100

Control: reassign -1 binutils 2.41.50.20231206-1
Control: affects -1 cmocka
Control: forwarded -1  https://sourceware.org/bugzilla/show_bug.cgi?id=24415
Control: retitle ld.gold - -Wl,--wrap not supported with LTO and optimization

Hey,

this is not a bug in cmocka. It is actually an bug in ld.gold , that does not 
correctly handles - -Wl,--wrap with LTO together correctly:

https://gitlab.com/cmocka/cmocka/-/issues/20

The workaround is to disable building examples, as it is the only place where 
this feature is used. 

Current state is that ld.bfd and ld.lld are fixed. But ld.gold fails :(

https://sourceware.org/bugzilla/show_bug.cgi?id=24415

Regards,

hefee