Merge pull request #2964 from felixhandte/noexecstack-all-archs

Mark Huffman Decoder Assembly `noexecstack` on All Architectures
This commit is contained in:
Felix Handte
2022-01-05 16:52:39 -05:00
committed by GitHub
4 changed files with 25 additions and 5 deletions
+3 -3
View File
@@ -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*.
+15
View File
@@ -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 := \#
@@ -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)