diff options
Diffstat (limited to 'share/mk/bsd.prog.mk')
-rw-r--r-- | share/mk/bsd.prog.mk | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index c546c4f0b680..f44556ef9b75 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -4,7 +4,7 @@ .include <bsd.compiler.mk> .include <bsd.linker.mk> -.SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm +.include <bsd.suffixes-extra.mk> # 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} @@ -69,6 +70,12 @@ LDFLAGS+= -Wl,-zretpolineplt .endif # LLD sensibly defaults to -znoexecstack, so do the same for BFD LDFLAGS.bfd+= -Wl,-znoexecstack +.if ${MK_BRANCH_PROTECTION} != "no" +CFLAGS+= -mbranch-protection=standard +.if ${LINKER_FEATURES:Mbti-report} && defined(BTI_REPORT_ERROR) +LDFLAGS+= -Wl,-zbti-report=error +.endif +.endif # Initialize stack variables on function entry .if ${OPT_INIT_ALL} != "none" @@ -84,6 +91,15 @@ CXXFLAGS+= -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-cl .endif .endif +# Zero used registers on return (mitigate some ROP) +.if ${MK_ZEROREGS} != "no" +.if ${COMPILER_FEATURES:Mzeroregs} +ZEROREG_TYPE?= used +CFLAGS+= -fzero-call-used-regs=${ZEROREG_TYPE} +CXXFLAGS+= -fzero-call-used-regs=${ZEROREG_TYPE} +.endif +.endif + # bsd.sanitizer.mk is not installed, so don't require it (e.g. for ports). .sinclude "bsd.sanitizer.mk" @@ -146,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} @@ -182,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} |