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)
This commit is contained in:
David Gibson 2025-08-06 13:37:03 +10:00
parent 617f3d9b60
commit 28bdb653cb
3 changed files with 9 additions and 2 deletions

View file

@ -68,7 +68,7 @@ else
CFLAGS += $(shell $(PKG_CONFIG) --cflags yaml-0.1) CFLAGS += $(shell $(PKG_CONFIG) --cflags yaml-0.1)
endif 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) ifeq ($(HOSTOS),darwin)
SHAREDLIB_EXT = dylib SHAREDLIB_EXT = dylib

View file

@ -1,5 +1,6 @@
version_script = '-Wl,--version-script=@0@'.format(meson.current_source_dir() / 'version.lds') 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 = [] version_script = []
endif endif

6
libfdt/test.lds Normal file
View file

@ -0,0 +1,6 @@
TEST {
global:
test_func;
local:
*;
};