From 922c51596fdeb042356bc6e0e5021f7d59a344ca Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Wed, 5 Feb 2025 16:16:17 +0100 Subject: [PATCH] [#3729] Added check for environ vs shlib --- compiler-checks/environ-in-shlib.cc | 5 +++++ meson.build | 12 ++++++++++++ src/lib/asiolink/meson.build | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 compiler-checks/environ-in-shlib.cc diff --git a/compiler-checks/environ-in-shlib.cc b/compiler-checks/environ-in-shlib.cc new file mode 100644 index 0000000000..d50947a378 --- /dev/null +++ b/compiler-checks/environ-in-shlib.cc @@ -0,0 +1,5 @@ +extern char **environ; + +char** fn() { + return environ; +} diff --git a/meson.build b/meson.build index 14cfb33e5d..a66738c211 100644 --- a/meson.build +++ b/meson.build @@ -269,6 +269,18 @@ result = cpp.run( ) conf_data.set('HAVE_STREAM_TRUNCATED_ERROR', result.returncode() == 0) +ENVIRON_SHLIB_FLAGS = [] +if cpp.has_link_argument('-Wl,--no-undefined') + result = cpp.links( + fs.read('compiler-checks/environ-in-shlib.cc'), + name: 'ENVIRON_SHLIB_FLAGS', + args: ['--shared', '-fPIC', '-Wl,--no-undefined'], + ) + if not result + ENVIRON_SHLIB_FLAGS += ['b_lundef=false'] + endif +endif + #### System-specific Variables SYSTEM = build_machine.system() diff --git a/src/lib/asiolink/meson.build b/src/lib/asiolink/meson.build index 6c271a2b56..6dbfa4928e 100644 --- a/src/lib/asiolink/meson.build +++ b/src/lib/asiolink/meson.build @@ -19,8 +19,7 @@ kea_asiolink_lib = library( install: true, install_dir: 'lib', link_with: LIBS_BUILT_SO_FAR, - # The only way to avoid on FreeBSD: ld: error: undefined symbol: environ - override_options: ['b_lundef=false'], + override_options: ENVIRON_SHLIB_FLAGS, ) LIBS_BUILT_SO_FAR = [kea_asiolink_lib] + LIBS_BUILT_SO_FAR subdir('testutils')