All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] build: check first before enabling -D_FORTIFY_SOURCE=3
@ 2025-02-08  9:33 Pauli Virtanen
  2025-02-08 11:06 ` [BlueZ] " bluez.test.bot
  2025-02-10 22:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Pauli Virtanen @ 2025-02-08  9:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

With --disable-optimization, _FORTIFY_SOURCE=3 produces compiler
warnings/errors:

/usr/include/features.h:422:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  422 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)

Before enabling it for --enable-maintainer-mode, check the compiler
doesn't fail when using the flag.
---
 acinclude.m4 | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 9f2dc302e..168117840 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -65,7 +65,6 @@ AC_DEFUN([COMPILER_FLAGS], [
 		with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
 		with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
 		with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
-		with_cflags="$with_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
 	fi
 	AC_SUBST([WARNING_CFLAGS], $with_cflags)
 ])
@@ -136,6 +135,21 @@ AC_DEFUN([MISC_FLAGS], [
 		misc_cflags="$misc_cflags --coverage"
 		misc_ldflags="$misc_ldflags --coverage"
 	fi
+	if (test "$USE_MAINTAINER_MODE" = "yes"); then
+		AC_CACHE_CHECK([whether ${CC-cc} accepts -D_FORTIFY_SOURCE=3],
+						ac_cv_prog_cc_fortify_source_3, [
+			echo '#include <errno.h>' > fortify.c
+			if test -z "`${CC-cc} ${CFLAGS} ${misc_cflags} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -c fortify.c  2>&1`"; then
+				ac_cv_prog_cc_fortify_source_3=yes
+			else
+				ac_cv_prog_cc_fortify_source_3=no
+			fi
+			rm -f fortify.c fortify.o
+		])
+		if test "${ac_cv_prog_cc_fortify_source_3}" = "yes"; then
+			misc_cflags="$misc_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
+		fi
+	fi
 	misc_cflags="$misc_cflags -ffunction-sections -fdata-sections"
 	misc_ldflags="$misc_ldflags -Wl,--gc-sections"
 	AC_SUBST([MISC_CFLAGS], $misc_cflags)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-10 22:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-08  9:33 [PATCH BlueZ] build: check first before enabling -D_FORTIFY_SOURCE=3 Pauli Virtanen
2025-02-08 11:06 ` [BlueZ] " bluez.test.bot
2025-02-10 22:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.