The test suite mocks internal functions by weakening their symbols with
objcopy (see libenvapi_testlib_fat.a rule below) so test-provided fake
implementations can override them at link time. LTO resolves symbols from
GIMPLE bytecode ignoring this post-hoc weakening, which causes "multiple
definition" link errors. Strip any global LTO flags and force LTO off for
this test directory so the weak-symbol override technique keeps working.
Signed-off-by: Hector Cao <
hecto...@canonical.com>
---
tools/tests/Makefile.am | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
index 7e3ac1e..0d38cb7 100644
--- a/tools/tests/Makefile.am
+++ b/tools/tests/Makefile.am
@@ -15,6 +15,15 @@ if BUILD_TESTS
OBJCOPY ?= objcopy
+# The test suite mocks internal functions by weakening their symbols with
+# objcopy (see libenvapi_testlib_fat.a rule below) so test-provided fake
+# implementations can override them at link time. LTO resolves symbols from
+# GIMPLE bytecode ignoring this post-hoc weakening, which causes "multiple
+# definition" link errors. Strip any global LTO flags and force LTO off for
+# this test directory so the weak-symbol override technique keeps working
+override CFLAGS := $(filter-out -flto -flto=% -ffat-lto-objects,$(CFLAGS)) -fno-lto
+override LDFLAGS := $(filter-out -flto -flto=%,$(LDFLAGS)) -fno-lto
+
AM_CFLAGS = \
$(LIBCHECK_CFLAGS) \
-I$(top_srcdir)/include \
--
2.43.0