From 078445658c506f2df54c7362ac9f810dfe0eff3c Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 23 Apr 2024 23:30:35 +0200 Subject: [PATCH] configure.ac: update ldflags args Attach -Wl,-z,relro,-z,now,-z,pack-relative-relocs,--as-needed to LDFLAGS, but only if LDFLAGS already doesn't contain 'relro' (so it's not given repeatedly). Also start to use -z,now linkage also when building libraries with default compilation - this avoid calling symbol resolver while library function are using function needing resolving. Note: Fedora or RHEL rpm building is using: CFLAGS=$(rpm --eval %{build_cflags}) LDFLAGS=$(rpm --eval %{build_ldflags}) Also split -DUSE_SD_NOTIFY into DEFS from CFLAGS. --- configure.ac | 2 +- daemons/lvmlockd/Makefile.in | 3 ++- libdm/make.tmpl.in | 9 +++++++-- make.tmpl.in | 11 +++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index b8bcfbb60..c8d81e16c 100644 --- a/configure.ac +++ b/configure.ac @@ -199,7 +199,7 @@ AC_MSG_RESULT([$SHARED_LINK]) dnl -- Check if compiler/linker supports PIE and RELRO AC_TRY_CCFLAG([-pie], [HAVE_PIE], [], []) AC_SUBST(HAVE_PIE) -AC_TRY_LDFLAGS([-Wl,-z,relro,-z,now], [HAVE_FULL_RELRO], [], []) +AC_TRY_LDFLAGS([-Wl,-z,relro,-z,now,-z,pack-relative-relocs,--as-needed], [HAVE_FULL_RELRO], [], []) AC_SUBST(HAVE_FULL_RELRO) ################################################################################ diff --git a/daemons/lvmlockd/Makefile.in b/daemons/lvmlockd/Makefile.in index 7b8af8fe5..61dae4e9b 100644 --- a/daemons/lvmlockd/Makefile.in +++ b/daemons/lvmlockd/Makefile.in @@ -51,7 +51,8 @@ LDFLAGS += -L$(top_builddir)/libdaemon/server $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) LIBS += $(DAEMON_LIBS) $(PTHREAD_LIBS) ifneq (,$(firstword $(LIBSYSTEMD_LIBS))) - CFLAGS += $(LIBSYSTEMD_CFLAGS) -DUSE_SD_NOTIFY + DEFS += -DUSE_SD_NOTIFY + CFLAGS += $(LIBSYSTEMD_CFLAGS) LIBS += $(LIBSYSTEMD_LIBS) endif diff --git a/libdm/make.tmpl.in b/libdm/make.tmpl.in index 5c6b2160f..a4d4ca731 100644 --- a/libdm/make.tmpl.in +++ b/libdm/make.tmpl.in @@ -233,11 +233,16 @@ endif endif ifneq ("@STATIC_LINK@", "yes") +ifeq (,$(findstring relro,$(LDFLAGS))) +ifeq ("@HAVE_FULL_RELRO@", "yes") + LDFLAGS += -Wl,-z,relro,-z,now,-z,pack-relative-relocs,--as-needed +endif +endif + ifeq ("@HAVE_PIE@", "yes") ifeq ("@HAVE_FULL_RELRO@", "yes") EXTRA_EXEC_CFLAGS += -fPIE - EXTRA_EXEC_LDFLAGS += -Wl,-z,relro,-z,now -pie -fPIE - CLDFLAGS += -Wl,-z,relro + EXTRA_EXEC_LDFLAGS += -pie -fPIE endif endif endif diff --git a/make.tmpl.in b/make.tmpl.in index 238f690b9..a1c62513f 100644 --- a/make.tmpl.in +++ b/make.tmpl.in @@ -270,13 +270,16 @@ endif endif ifneq ("@STATIC_LINK@", "yes") -ifeq ("@HAVE_PIE@", "yes") +ifeq (,$(findstring relro,$(LDFLAGS))) ifeq ("@HAVE_FULL_RELRO@", "yes") - EXTRA_EXEC_CFLAGS += -fPIE - EXTRA_EXEC_LDFLAGS += -Wl,-z,relro,-z,now -pie -fPIE - CLDFLAGS += -Wl,-z,relro + LDFLAGS += -Wl,-z,relro,-z,now,-z,pack-relative-relocs,--as-needed endif endif + +ifeq ("@HAVE_PIE@", "yes") + EXTRA_EXEC_CFLAGS += -fPIE + EXTRA_EXEC_LDFLAGS += -pie -fPIE +endif endif #WFLAGS += -W -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers