From 245bb0110639fe963086fb2903143dbd4e6ac48c Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 21 Apr 2025 21:52:29 +0200 Subject: [PATCH] Use .pieo extension for WITH_PIE bsd.prog.mk output When object files for programs are built using bsd.prog.mk, and WITH_PIE is enabled, the extension used is still plain ".o". To be consistent with bsd.lib.mk, and to allow changes in WITH_PIE settings to propagate correctly, the extension should be ".pieo" instead. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D49966 --- share/mk/bsd.prog.mk | 15 ++++++++------- share/mk/bsd.progs.mk | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index 1894a8b938d..f44556ef9b7 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -4,7 +4,7 @@ .include .include -.SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm +.include # XXX The use of COPTS in modern makefiles is discouraged. .if defined(COPTS) @@ -47,13 +47,14 @@ LDFLAGS+= -Wl,-znorelro LDFLAGS+= -Wl,-zrelro .endif .endif -.if ${MK_PIE} != "no" # Static PIE is not yet supported/tested. -.if !defined(NO_SHARED) || ${NO_SHARED:tl} == "no" +.if ${MK_PIE} != "no" && (!defined(NO_SHARED) || ${NO_SHARED:tl} == "no") CFLAGS+= -fPIE CXXFLAGS+= -fPIE LDFLAGS+= -pie -.endif +OBJ_EXT=pieo +.else +OBJ_EXT=o .endif .if ${MK_RETPOLINE} != "no" .if ${COMPILER_FEATURES:Mretpoline} && ${LINKER_FEATURES:Mretpoline} @@ -161,7 +162,7 @@ PROGNAME?= ${PROG} .if defined(SRCS) -OBJS+= ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g} +OBJS+= ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.${OBJ_EXT}/g} # LLVM bitcode / textual IR representations of the program BCOBJS+=${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g} @@ -197,10 +198,10 @@ SRCS= ${PROG}.c # - the name of the object gets put into the executable symbol table instead of # the name of a variable temporary object. # - it's useful to keep objects around for crunching. -OBJS+= ${PROG}.o +OBJS+= ${PROG}.${OBJ_EXT} BCOBJS+= ${PROG}.bc LLOBJS+= ${PROG}.ll -CLEANFILES+= ${PROG}.o ${PROG}.bc ${PROG}.ll +CLEANFILES+= ${PROG}.${OBJ_EXT} ${PROG}.bc ${PROG}.ll .if target(beforelinking) beforelinking: ${OBJS} diff --git a/share/mk/bsd.progs.mk b/share/mk/bsd.progs.mk index ee6b1305757..4d1ff354edf 100644 --- a/share/mk/bsd.progs.mk +++ b/share/mk/bsd.progs.mk @@ -110,7 +110,7 @@ _PROGS_ALL_SRCS+= ${s} .if !empty(_PROGS_COMMON_SRCS) _PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]} .if !empty(_PROGS_COMMON_SRCS:N*.[dhly]) -_PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g} +_PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.${OBJ_EXT}/g} .endif .endif