Skip to content

Commit

Permalink
Makefiles: Add noexecstack Options to Compilation and Linking
Browse files Browse the repository at this point in the history
Hopefully this marks the binary artifacts `noexecstack` even on platforms
where binaries default to true.
  • Loading branch information
felixhandte committed Jan 5, 2022
1 parent 35208f7 commit bd136c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
ZSTD_LIB_DEPRECATED = 0
endif


include libzstd.mk

ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
Expand Down
24 changes: 24 additions & 0 deletions lib/libzstd.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ZSTD_NO_ASM ?= 0
# libzstd helpers
##################################################################

VOID ?= /dev/null

# Make 4.3 doesn't support '\#' anymore (https://lwn.net/Articles/810071/)
NUM_SYMBOL := \#

Expand All @@ -59,6 +61,28 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
CCVER := $(shell $(CC) --version)
ZSTD_VERSION?= $(LIBVER)


ifndef ALREADY_APPENDED_NOEXECSTACK
export ALREADY_APPENDED_NOEXECSTACK := 1
ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) -z noexecstack -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
$(info Supports noexecstack linker flag!)
$(info $(LDFLAGS))
LDFLAGS += -z noexecstack
$(info $(LDFLAGS))
else
$(info Doesn't support noexecstack linker flag!)
endif
ifeq ($(shell echo | $(CC) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
$(info Supports noexecstack assembler flag!)
$(info $(CFLAGS))
CFLAGS += -Wa,--noexecstack
$(info $(CFLAGS))
else
$(info Doesn't support noexecstack assembler flag!)
endif
endif


# ZSTD_LIB_MINIFY is a helper variable that
# configures a bunch of other variables to space-optimized defaults.
ZSTD_LIB_MINIFY ?= 0
Expand Down
2 changes: 0 additions & 2 deletions programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ else
EXT =
endif

VOID = /dev/null

# thread detection
NO_THREAD_MSG := ==> no threads, building without multithreading support
HAVE_PTHREAD := $(shell printf '$(NUM_SYMBOL)include <pthread.h>\nint main(void) { return 0; }' > have_pthread.c && $(CC) $(FLAGS) -o have_pthread$(EXT) have_pthread.c -pthread 2> $(VOID) && rm have_pthread$(EXT) && echo 1 || echo 0; rm have_pthread.c)
Expand Down

0 comments on commit bd136c8

Please sign in to comment.