Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/decompress/huf_decompress_amd64.S
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "../common/portability_macros.h"

#if ZSTD_ENABLE_ASM_X86_64_BMI2

/* Stack marking
* ref: https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
*/
#if defined(__linux__) && defined(__ELF__)
#if defined(__ELF__) && defined(__GNUC__)
.section .note.GNU-stack,"",%progbits
#endif

#if ZSTD_ENABLE_ASM_X86_64_BMI2

/* Calling convention:
*
* %rdi contains the first argument: HUF_DecompressAsmArgs*.
Expand Down
15 changes: 15 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 Down Expand Up @@ -96,6 +98,19 @@ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
LDFLAGS += $(MOREFLAGS)
FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)

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) $(FLAGS) -z noexecstack -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
LDFLAGS += -z noexecstack
endif
ifeq ($(shell echo | $(CC) $(FLAGS) -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
CFLAGS += -Wa,--noexecstack
else ifeq ($(shell echo | $(CC) $(FLAGS) -Qunused-arguments -Wa,--noexecstack -x assembler -Werror -c - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
# See e.g.: https://github.com/android/ndk/issues/171
CFLAGS += -Qunused-arguments -Wa,--noexecstack
endif
endif

HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
GREP_OPTIONS ?=
ifeq ($HAVE_COLORNEVER, 1)
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
7 changes: 7 additions & 0 deletions tests/playTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ zstd -d -f tmp_corrupt.zst --no-check
zstd -d -f tmp_corrupt.zst --check --no-check # final flag overrides
zstd -d -f tmp.zst --no-check

if [ "$isWindows" = false ]; then
if [ -n "$(which readelf)" ]; then
println "test: check if binary has executable stack (#2963)"
readelf -lW "$ZSTD_BIN" | grep 'GNU_STACK .* RW ' || die "zstd binary has executable stack!"
fi
fi

println "\n===> zstdgrep tests"
ln -sf "$ZSTD_BIN" zstdcat
rm -f tmp_grep
Expand Down