From 9c20010361854a6034595fdb13cd3583ea13f289 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Sat, 24 May 2025 00:35:21 +0100 Subject: [PATCH] share/mk: pass SHARED_CFLAGS to PIC and PIE from assembly This matches what we do with C sources. Document SHARED_CFLAGS. PR: 286975 Reviewed by: jhb, emaste Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D50466 --- share/mk/bsd.README | 3 +++ share/mk/bsd.suffixes-extra.mk | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/share/mk/bsd.README b/share/mk/bsd.README index c2326a17f03..4820bf12c72 100644 --- a/share/mk/bsd.README +++ b/share/mk/bsd.README @@ -197,6 +197,9 @@ LIBADD Additional libraries. This is for base system libraries LIBADD.${.TARGET:T} Libraries dependent on output file name. +SHARED_CFLAGS Additional compiler flags used when creating shared or + position independent object files. + COMPILER_FEATURES A list of features that the compiler supports. Zero or more of: diff --git a/share/mk/bsd.suffixes-extra.mk b/share/mk/bsd.suffixes-extra.mk index 680abfc88eb..e27c9ad318e 100644 --- a/share/mk/bsd.suffixes-extra.mk +++ b/share/mk/bsd.suffixes-extra.mk @@ -60,12 +60,13 @@ PIEFLAG?=-fpie .asm.pico: ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \ - ${CFLAGS} ${ACFLAGS} \ + ${SHARED_CFLAGS} ${CFLAGS} ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .asm.nossppico: ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \ + ${SHARED_CFLAGS:C/^-fstack-protector.*$//:C/^-fstack-clash-protection.*$//} \ ${CFLAGS:C/^-fstack-protector.*$//:C/^-fstack-clash-protection.*$//} \ ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} @@ -73,18 +74,19 @@ PIEFLAG?=-fpie .asm.pieo: ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PIEFLAG} -DPIC \ - ${CFLAGS} ${ACFLAGS} \ + ${SHARED_CFLAGS} ${CFLAGS} ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .S.pico: ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC \ - ${CFLAGS} ${ACFLAGS} \ + ${SHARED_CFLAGS} ${CFLAGS} ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .S.nossppico: ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC \ + ${SHARED_CFLAGS:C/^-fstack-protector.*$//:C/^-fstack-clash-protection.*$//} \ ${CFLAGS:C/^-fstack-protector.*$//:C/^-fstack-clash-protection.*$//} \ ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} @@ -92,7 +94,7 @@ PIEFLAG?=-fpie .S.pieo: ${CC:N${CCACHE_BIN}} ${PIEFLAG} -DPIC \ - ${CFLAGS} ${ACFLAGS} \ + ${SHARED_CFLAGS} ${CFLAGS} ${ACFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD}