From af17c1d44d7efc73ac5a625ecef4b3a3923cf6f1 Mon Sep 17 00:00:00 2001 From: Nick Connolly Date: Thu, 25 Feb 2021 18:31:54 +0000 Subject: [PATCH] mk: adjust options for mingw cross compilation Check compiler target triplet for the strings 'windows' or 'mingw' and set OS to Windows. If found, adjust basic parameters: Set EXEEXT to indicate executables have .exe suffix. Exclude 'relro' and 'now' flags which are not recognised on Windows. Exclude 'noexecstack' flag which is not recognised on Windows. Exclude -pthread flag because Windows doesn't have POSIX threads. Include libssp.a to support stack-protector and _FORTIFY_SOURCE. Signed-off-by: Nick Connolly Change-Id: I94a45d3123ebc81f5529006fa07b05da897e5866 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6574 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- mk/spdk.common.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index e8bb0ffdd..ffb2e8b2a 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -69,10 +69,17 @@ endif ifneq ($(filter freebsd%,$(TARGET_TRIPLET_WORDS)),) OS = FreeBSD endif +ifneq ($(filter mingw% windows%,$(TARGET_TRIPLET_WORDS)),) +OS = Windows +endif TARGET_ARCHITECTURE ?= $(CONFIG_ARCH) TARGET_MACHINE := $(firstword $(TARGET_TRIPLET_WORDS)) +ifeq ($(OS),Windows) +EXEEXT = .exe +endif + COMMON_CFLAGS = -g $(C_OPT) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations -fno-strict-aliasing -I$(SPDK_ROOT_DIR)/include ifneq ($(filter powerpc% ppc%,$(TARGET_MACHINE)),) @@ -127,11 +134,15 @@ COMMON_CFLAGS += -fno-common # Enable full RELRO - no lazy relocation (resolve everything at load time). # This allows the GOT to be made read-only early in the loading process. +ifneq ($(OS),Windows) LDFLAGS += -Wl,-z,relro,-z,now +endif # Make the stack non-executable. # This is the default in most environments, but it doesn't hurt to set it explicitly. +ifneq ($(OS),Windows) LDFLAGS += -Wl,-z,noexecstack +endif # Specify the linker to use ifneq ($(LD_TYPE),) @@ -253,8 +264,10 @@ ifneq (, $(SPDK_GIT_COMMIT)) COMMON_CFLAGS += -DSPDK_GIT_COMMIT=$(SPDK_GIT_COMMIT) endif +ifneq ($(OS),Windows) COMMON_CFLAGS += -pthread LDFLAGS += -pthread +endif CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -Wstrict-prototypes -Wold-style-definition -std=gnu99 CXXFLAGS += $(COMMON_CFLAGS) @@ -267,6 +280,11 @@ ifneq ($(CONFIG_NVME_CUSE)$(CONFIG_FUSE),nn) SYS_LIBS += -lfuse3 endif +ifeq ($(OS).$(CC_TYPE),Windows.gcc) +# Include libssp.a for stack-protector and _FORTIFY_SOURCE +SYS_LIBS += -l:libssp.a +endif + MAKEFLAGS += --no-print-directory C_SRCS += $(C_SRCS-y)