Skip to content

Commit

Permalink
Introduce PIE base.
Browse files Browse the repository at this point in the history
Enabled for amd64, i386, and aarch64.
  • Loading branch information
lattera committed Oct 11, 2016
1 parent 5b32991 commit 885c2e5
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 1 deletion.
Empty file modified lib/libstand/Makefile
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions libexec/rtld-elf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ beforeinstall:
SUBDIR+= tests
.endif

NOPIE= yes

.include <bsd.prog.mk>
${PROG_FULL}: ${VERSION_MAP}
.include <bsd.symver.mk>
2 changes: 2 additions & 0 deletions rescue/librescue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ CFLAGS+= -DHESIOD
.endif
CFLAGS+= -I${.CURDIR}/../../lib/libc/include

NOPIE= yes

.include <bsd.lib.mk>
2 changes: 2 additions & 0 deletions rescue/rescue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,7 @@ CRUNCH_PROGS_usr.bin+= iscsictl
CRUNCH_PROGS_usr.sbin+= iscsid
.endif

NOPIE= yes

.include <bsd.crunchgen.mk>
.include <bsd.prog.mk>
23 changes: 23 additions & 0 deletions share/mk/bsd.lib.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ PICFLAG=-fpic
.endif
.endif

.if defined(MK_PIE)
# Ports will not have MK_PIE defined and the following logic requires
# it be defined.

.if !defined(NO_PIC)
.if ${MK_PIE} != "no"
.if !defined(NOPIE)
CFLAGS+= ${PICFLAG}
.endif
.endif
.endif
.endif

.if defined(MK_RELRO)
.if ${MK_RELRO} != "no"
LDFLAGS+= -Wl,-z,relro
.endif

.if ${MK_BIND_NOW} != "no"
LDFLAGS+= -Wl,-z,now
.endif
.endif

PO_FLAG=-pg

.c.o:
Expand Down
27 changes: 27 additions & 0 deletions share/mk/bsd.prog.mk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
LDFLAGS+= -static
.endif

.if defined(MK_PIE)
# Ports will not have MK_PIE defined and the following logic requires
# it be defined.

.if ${LDFLAGS:M-static}
NOPIE=yes
.endif

.if !defined(NOPIE)
.if ${MK_PIE} != "no"
CFLAGS+= -fPIE
CXXFLAGS+= -fPIE
LDFLAGS+= -pie
.endif
.endif
.endif

.if defined(MK_RELRO)
.if ${MK_RELRO} != "no"
LDFLAGS+= -Wl,-z,relro
.endif

.if ${MK_BIND_NOW} != "no"
LDFLAGS+= -Wl,-z,now
.endif
.endif

.if ${MK_DEBUG_FILES} != "no"
PROG_FULL=${PROG}.full
# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
Expand Down
2 changes: 2 additions & 0 deletions share/mk/bsd.test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TESTS_SUBDIRS?=
# List of variables to pass to the tests at run-time via the environment.
TESTS_ENV?=

NOPIE= yes

# Force all tests in a separate distribution file.
#
# We want this to be the case even when the distribution name is already
Expand Down
10 changes: 9 additions & 1 deletion share/mk/src.opts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ __DEFAULT_YES_OPTIONS = \
AUTHPF \
AUTOFS \
BHYVE \
BIND_NOW \
BINUTILS \
BINUTILS_BOOTSTRAP \
BLACKLIST \
Expand Down Expand Up @@ -148,11 +149,13 @@ __DEFAULT_YES_OPTIONS = \
RCMDS \
RBOOTD \
RCS \
RELRO \
RESCUE \
ROUTED \
SENDMAIL \
SETUID_LOGIN \
SHAREDOCS \
SHARED_TOOLCHAIN \
SOURCELESS \
SOURCELESS_HOST \
SOURCELESS_UCODE \
Expand Down Expand Up @@ -186,7 +189,6 @@ __DEFAULT_NO_OPTIONS = \
NAND \
OFED \
OPENLDAP \
SHARED_TOOLCHAIN \
SORT_THREADS \
SVN \
SYSTEM_COMPILER
Expand Down Expand Up @@ -258,6 +260,12 @@ BROKEN_OPTIONS+=LLDB
BROKEN_OPTIONS+=LIBSOFT
.endif

.if ${__T} == "amd64" || ${__T} == "i386" || ${__T} == "aarch64"
__DEFAULT_YES_OPTIONS+=PIE
.else
__DEFAULT_NO_OPTIONS+=PIE
.endif

.include <bsd.mkopt.mk>

#
Expand Down
1 change: 1 addition & 0 deletions sys/boot/common/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c
SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c
.elif ${MACHINE_CPUARCH} == "aarch64"
SRCS+= load_elf64.c reloc_elf64.c
NOPIE= yes
.elif ${MACHINE_CPUARCH} == "arm"
SRCS+= load_elf32.c reloc_elf32.c
.elif ${MACHINE_CPUARCH} == "powerpc"
Expand Down
4 changes: 4 additions & 0 deletions sys/boot/efi/boot1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

MAN=

.if ${MACHINE_CPUARCH} == "aarch64"
NOPIE= yes
.endif

.include <src.opts.mk>

MK_SSP= no
Expand Down
1 change: 1 addition & 0 deletions sys/boot/efi/libefi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CFLAGS+= -msoft-float -mgeneral-regs-only
.endif
.if ${MACHINE_ARCH} == "amd64"
CFLAGS+= -fPIC -mno-red-zone
NOPIE= yes
.endif
CFLAGS+= -I${.CURDIR}/../include
CFLAGS+= -I${.CURDIR}/../include/${MACHINE}
Expand Down
4 changes: 4 additions & 0 deletions sys/boot/efi/loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

MAN=

.if ${MACHINE_CPUARCH} == "aarch64"
NOPIE= yes
.endif

.include <src.opts.mk>

MK_SSP= no
Expand Down
2 changes: 2 additions & 0 deletions sys/boot/efi/loader/arch/arm64/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ loader.help: help.common

FILES+= loader.rc
.endif

NOPIE= yes
2 changes: 2 additions & 0 deletions sys/boot/fdt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ CFLAGS+= -m32

CFLAGS+= -Wformat -Wall

NOPIE= yes

.include <bsd.stand.mk>
.include <bsd.lib.mk>
4 changes: 4 additions & 0 deletions sys/boot/ficl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

FICLDIR?= ${.CURDIR}

.if ${MACHINE_CPUARCH} == "aarch64"
NOPIE= yes
.endif

.if defined(FICL32)
.PATH: ${FICLDIR}/${MACHINE_CPUARCH:S/amd64/i386/}
.elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el"
Expand Down
2 changes: 2 additions & 0 deletions sys/boot/i386/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ BTXLDR= ${BTXDIR}/btxldr/btxldr
BTXKERN= ${BTXDIR}/btx/btx
BTXCRT= ${BTXDIR}/lib/crt0.o

NOPIE= yes

.include "../Makefile.inc"
4 changes: 4 additions & 0 deletions sys/boot/usb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ CFLAGS+= -m32
CFLAGS+= -mno-abicalls
.endif

.if ${MACHINE_CPUARCH} == "aarch64"
NOPIE= yes
.endif


.include "usbcore.mk"
.include "../kshim/kshim.mk"
Expand Down

0 comments on commit 885c2e5

Please sign in to comment.