1
1
# -*- Makefile -*-, you silly Emacs!
4
# Copyright (C) 2009-2010 Kees Cook <kees@debian.org>
4
# Copyright (C) 2009-2011 Kees Cook <kees@debian.org>
5
5
# License: GPLv2 or newer
7
7
# This file is intended to be included in a Debian rules file so that the
73
73
_HARDENED_PIE_CFLAGS := -fPIE
74
74
_HARDENED_PIE_LDFLAGS := -fPIE -pie
76
_HARDENED_STACKPROTECTOR_CFLAGS := -fstack-protector
76
_HARDENED_STACKPROTECTOR_CFLAGS := -fstack-protector --param ssp-buffer-size=4
78
78
# Fortify Source requires that -O2 or higher is used, but that should be
79
79
# handled outside of this include file.
80
80
_HARDENED_FORTIFY_CFLAGS := -D_FORTIFY_SOURCE=2
82
_HARDENED_FORMAT_CFLAGS := -Wformat -Wformat-security
82
_HARDENED_FORMAT_CFLAGS := -Wformat -Wformat-security -Werror=format-security
84
84
_HARDENED_RELRO_LDFLAGS := -Wl,-z,relro
110
110
HARDENING_DISABLE_FORMAT_CFLAGS:=-Wno-format-security
111
111
HARDENING_DISABLE_RELRO_LDFLAGS:=-Wl,-z,norelro
112
112
HARDENING_DISABLE_BINDNOW_LDFLAGS:=-Wl,-z,lazy
113
# Note: GCC does not have a way to just turn off pie (there is no -nopie)
113
# Note: GCC does not have a way to just turn off pie (there is no "-nopie")
114
114
# so if PIE needs to be disabled for a specific target, the CFLAGS and LDFLAGS
115
115
# need to be filtered. For example:
116
116
# monkey: monkey.c
117
117
# $(CC) $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(CFLAGS)) \
118
118
# $(filter-out $(HARDENING_DISABLE_PIE_LDFLAGS_FILTER),$(LDFLAGS)) \
121
# Note: when building shared libraries, or with some build frameworks (e.g.
122
# cmake) that pass "-fPIC" to everything, the "-fPIE" option must be filtered
123
# out to avoid building shared objects that need PIC but end up only with PIE.
124
# This is usually indicated by errors at link time that look like this:
125
# relocation R_X86_64_PC32 against symbol `foo' can not be used when making a shared object; recompile with -fPIC
126
# In these cases, the CFLAGS can be filtered to exclude "-fPIE" until this
127
# is fixed in gcc correctly. For example, on one target:
129
# $(CC) $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(CFLAGS)) \
131
# In cases where mixed shared objects and executable objects are being built,
132
# "-fPIC" needs to actually replace "-fPIE", since gcc won't distinguish
133
# between them yet. For example:
134
# export CFLAGS=$(shell dpkg-buildflags --get CFLAGS)
135
# CFLAGS += $(HARDENING_CFLAGS_PIC) \
136
# $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(HARDENING_CFLAGS))
120
138
HARDENING_DISABLE_PIE_CFLAGS_FILTER:=$(_HARDENED_PIE_CFLAGS)
121
139
HARDENING_DISABLE_PIE_LDFLAGS_FILTER:=$(_HARDENED_PIE_LDFLAGS)
140
HARDENING_CFLAGS_PIC:=-fPIC