From: Jan Kiszka <[email protected]>

Otherwise, recent ld may leave some other symbols unresolved and cause
NULL pointer jumps during the test. Seen with github's Ubuntu 22.04
toolchain and with OpenSUSE 15.4.

Weakening config_parts and envdata does not work reliably via the
objcopy trick because some compilers already resolve the symbols locally
if they are in the same module, preventing overloading them for the
tests.

Signed-off-by: Jan Kiszka <[email protected]>
---
 env/env_api_fat.c       |  5 +++--
 tools/tests/Makefile.am | 10 +++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 886d2d2..1c01a52 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -129,8 +129,9 @@ bool write_env(CONFIG_PART *part, BG_ENVDATA *env)
        return result;
 }
 
-CONFIG_PART config_parts[ENV_NUM_CONFIG_PARTS];
-BG_ENVDATA envdata[ENV_NUM_CONFIG_PARTS];
+/* Weaken the symbols in order to permit overloading in the test cases. */
+CONFIG_PART __attribute__((weak)) config_parts[ENV_NUM_CONFIG_PARTS];
+BG_ENVDATA __attribute__((weak)) envdata[ENV_NUM_CONFIG_PARTS];
 
 static bool initialized;
 
diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
index 3947ab5..71f7159 100644
--- a/tools/tests/Makefile.am
+++ b/tools/tests/Makefile.am
@@ -48,7 +48,15 @@ check_LIBRARIES = libtest_env_api_fat.a
 libtest_env_api_fat_a_SOURCES = $(libtest_env_api_fat_a_SRC)
 
 libenvapi_testlib_fat.a: libtest_env_api_fat.a
-       $(OBJCOPY) --weaken $^ $@
+       $(OBJCOPY) \
+               --weaken-symbol=read_env \
+               --weaken-symbol=ped_device_probe_all \
+               --weaken-symbol=ped_device_get_next \
+               --weaken-symbol=write_env \
+               --weaken-symbol=get_mountpoint \
+               --weaken-symbol=bgenv_init \
+               --weaken-symbol=bgenv_write \
+               $^ $@
 
 check_PROGRAMS = test_bgenv_init_retval \
                 test_probe_config_partitions \
-- 
2.35.3

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/688b59fbb2241ed49c16945b96d2d303583b6dd8.1658670241.git.jan.kiszka%40siemens.com.

Reply via email to