From 28bdb653cbbc91a49aa06457cacaf1ab94a911e1 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 6 Aug 2025 13:37:03 +1000 Subject: [PATCH] build: Fix linker version script support detection The tests for linker version script support were incorrect in both make and meson build systems. The problem was that the script needs to match the object it's used with, whereas the tests used dummy objects with no matching symbols. Updated both systems to test with proper symbol matching between the test object and version script using a dedicated test.lds file. Generated-by: Claude Code 1.0.65 (claude-sonnet-4@20250514) --- Makefile | 2 +- libfdt/meson.build | 3 ++- libfdt/test.lds | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 libfdt/test.lds diff --git a/Makefile b/Makefile index 83d8220..c9dc5eb 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ else CFLAGS += $(shell $(PKG_CONFIG) --cflags yaml-0.1) endif -HAS_VERSION_SCRIPT := $(shell echo 'int main(){}' | $(CC) -Wl,--version-script=/dev/null -x c - -o /dev/null 2>/dev/null && echo y) +HAS_VERSION_SCRIPT := $(shell printf 'void test_func(){}\nint main(){}' | $(CC) -Wl,--version-script=libfdt/test.lds -x c - && echo y || echo n) ifeq ($(HOSTOS),darwin) SHAREDLIB_EXT = dylib diff --git a/libfdt/meson.build b/libfdt/meson.build index 68d4c1d..46a5b3a 100644 --- a/libfdt/meson.build +++ b/libfdt/meson.build @@ -1,5 +1,6 @@ version_script = '-Wl,--version-script=@0@'.format(meson.current_source_dir() / 'version.lds') -if not cc.has_link_argument(version_script) +test_code = 'void test_func(){} int main(){}' +if not cc.links(test_code, args: ['-Wl,--version-script=' + meson.current_source_dir() / 'test.lds']) version_script = [] endif diff --git a/libfdt/test.lds b/libfdt/test.lds new file mode 100644 index 0000000..2e7b5d6 --- /dev/null +++ b/libfdt/test.lds @@ -0,0 +1,6 @@ +TEST { + global: + test_func; + local: + *; +}; \ No newline at end of file