From 43a10f4806def7fd7d099777b965be022a7f3475 Mon Sep 17 00:00:00 2001 From: Ingo Franzki Date: Thu, 27 Nov 2025 08:49:22 +0100 Subject: [PATCH] common.mak: Add '-Wl,--as-needed' to DEFAULT_LDFLAGS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many distros and buildsystems use '-Wl,--as-needed' default-wise anyway. For example, Ubuntu, Fedora, and Meson default to '-Wl,--as-needed'. Considering some of the projects that use/support Meson, e.g. util-linux, systemd, libvirt, or git, are all built with '-Wl,--as-needed' as well. So add '-Wl,--as-needed' to DEFAULT_LDFLAGS to also default to that. Note that with '-Wl,--as-needed' the order of flags, objects, and libraries matters for the link step. The link rule in common.mak already has the correct order, so using '-Wl,--as-needed' will not hurt. %: %.o $(LINK) $(ALL_LDFLAGS) $^ $(LDLIBS) -o $@ Signed-off-by: Ingo Franzki Reviewed-by: Jan Höppner Signed-off-by: Jan Höppner --- common.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.mak b/common.mak index e5f13430..f21d4cd4 100644 --- a/common.mak +++ b/common.mak @@ -165,7 +165,7 @@ ifeq ("${ENABLE_WERROR}", "1") endif DEFAULT_CPPFLAGS = -D_GNU_SOURCE -DEFAULT_LDFLAGS = -rdynamic +DEFAULT_LDFLAGS = -rdynamic -Wl,--as-needed ifeq ("${ASAN}","1") DEFAULT_CFLAGS += -fsanitize=address -fno-omit-frame-pointer