aboutsummaryrefslogtreecommitdiff
path: root/Mk/Features/pie.mk
blob: 3a8a95b93aea6b9870338883130ec83141ac36a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# PIE Support
#
# Produce a Position-Independent Executable (PIE) instead of a "normal"
# fixed-address ELF.
# A PIE is an executable whose code sections are compiled and linked so that,
# at runtime, they can be loaded at any base address in memory.
#
# Because it can be loaded at unpredictable addresses, PIE enables full Address
# Space Layout Randomization (ASLR) for your main executable-making certain
# classes of memory-corruption exploits much harder.

.if !defined(_PIE_MK_INCLUDED)
_PIE_MK_INCLUDED=	yes
PIE_Include_MAINTAINER=	portmgr@FreeBSD.org

.  if !defined(PIE_UNSAFE)
.    if defined(_INCLUDE_USES_CMAKE_MK)
CMAKE_ARGS+=	-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
.    else
PIE_CFLAGS?=	-fPIE -fPIC
CFLAGS+=	${PIE_CFLAGS}
CXXFLAGS+=	${PIE_CFLAGS}
LDFLAGS+=	-pie
STATIC_PIE_ARGS+=	-static-pie
.    endif
.  endif
.endif