2015-06-20 17:37:18 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 OpenWrt.org
|
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
|
|
|
PKG_CHECK_FORMAT_SECURITY ?= 1
|
2018-01-08 22:47:06 +00:00
|
|
|
PKG_ASLR_PIE ?= 1
|
2019-10-27 13:37:45 +00:00
|
|
|
PKG_ASLR_PIE_REGULAR ?= 0
|
2015-06-24 10:57:14 +00:00
|
|
|
PKG_SSP ?= 1
|
|
|
|
PKG_FORTIFY_SOURCE ?= 1
|
|
|
|
PKG_RELRO ?= 1
|
2015-06-20 17:37:18 +00:00
|
|
|
|
|
|
|
ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
|
|
|
|
ifeq ($(strip $(PKG_CHECK_FORMAT_SECURITY)),1)
|
|
|
|
TARGET_CFLAGS += -Wformat -Werror=format-security
|
|
|
|
endif
|
|
|
|
endif
|
2019-10-27 13:37:45 +00:00
|
|
|
ifdef CONFIG_PKG_ASLR_PIE_ALL
|
2018-01-08 22:47:06 +00:00
|
|
|
ifeq ($(strip $(PKG_ASLR_PIE)),1)
|
2018-06-09 08:11:24 +00:00
|
|
|
TARGET_CFLAGS += $(FPIC)
|
2018-07-17 16:29:34 +00:00
|
|
|
TARGET_LDFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
|
2018-01-08 22:47:06 +00:00
|
|
|
endif
|
|
|
|
endif
|
2019-10-27 13:37:45 +00:00
|
|
|
ifdef CONFIG_PKG_ASLR_PIE_REGULAR
|
|
|
|
ifeq ($(strip $(PKG_ASLR_PIE_REGULAR)),1)
|
|
|
|
TARGET_CFLAGS += $(FPIC)
|
|
|
|
TARGET_LDFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
|
|
|
|
endif
|
|
|
|
endif
|
2015-06-20 17:37:18 +00:00
|
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -fstack-protector
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -fstack-protector-strong
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifdef CONFIG_PKG_FORTIFY_SOURCE_1
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_FORTIFY_SOURCE)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -D_FORTIFY_SOURCE=1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifdef CONFIG_PKG_FORTIFY_SOURCE_2
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_FORTIFY_SOURCE)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -D_FORTIFY_SOURCE=2
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifdef CONFIG_PKG_RELRO_PARTIAL
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_RELRO)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -Wl,-z,relro
|
|
|
|
TARGET_LDFLAGS += -zrelro
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifdef CONFIG_PKG_RELRO_FULL
|
2015-06-24 10:57:14 +00:00
|
|
|
ifeq ($(strip $(PKG_RELRO)),1)
|
2015-06-20 17:37:18 +00:00
|
|
|
TARGET_CFLAGS += -Wl,-z,now -Wl,-z,relro
|
|
|
|
TARGET_LDFLAGS += -znow -zrelro
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|