freebsd-dev/libexec/rtld-elf/Makefile
Bryan Drewery 5608fd23c2 Revert r267233 for now. PIE support needs to be reworked.
1. 50+% of NO_PIE use is fixed by adding -fPIC to INTERNALLIB and other
   build-only utility libraries.
2. Another 40% is fixed by generating _pic.a variants of various libraries.
3. Some of the NO_PIE use is a bit absurd as it is disabling PIE (and ASLR)
   where it never would work anyhow, such as csu or loader. This suggests
   there may be better ways of adding support to the tree. Many of these
   cases can be fixed such that -fPIE will work but there is really no
   reason to have it in those cases.
4. Some of the uses are working around hacks done to some Makefiles that are
   really building libraries but have been using bsd.prog.mk because the code
   is cleaner. Had they been using bsd.lib.mk then NO_PIE would not have
   been needed.

We likely do want to enable PIE by default (opt-out) for non-tree consumers
(such as ports). For in-tree though we probably want to only enable PIE
(opt-in) for common attack targets such as remote service daemons and setuid
utilities. This is also a great performance compromise since ASLR is expected
to reduce performance. As such it does not make sense to enable it in all
utilities such as ls(1) that have little benefit to having it enabled.

Reported by:	kib
2014-08-19 15:04:32 +00:00

87 lines
2.0 KiB
Makefile

# $FreeBSD$
.include <src.opts.mk>
MK_SSP= no
PROG?= ld-elf.so.1
SRCS= rtld_start.S \
reloc.c rtld.c rtld_lock.c rtld_printf.c map_object.c \
malloc.c xmalloc.c debug.c libmap.c
MAN= rtld.1
CSTD?= gnu99
TOPSRCDIR= ${.CURDIR}/../..
CFLAGS+= -Wall -DFREEBSD_ELF -DIN_RTLD
CFLAGS+= -I${TOPSRCDIR}/lib/csu/common
.if exists(${.CURDIR}/${MACHINE_ARCH})
RTLD_ARCH= ${MACHINE_ARCH}
.else
RTLD_ARCH= ${MACHINE_CPUARCH}
.endif
CFLAGS+= -I${.CURDIR}/${RTLD_ARCH} -I${.CURDIR}
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -mcall-aixdesc
LDFLAGS+= -nostdlib -e _rtld_start
.else
LDFLAGS+= -nostdlib -e .rtld_start
.endif
WARNS?= 2
INSTALLFLAGS= -C -b
PRECIOUSPROG=
BINDIR= /libexec
SYMLINKS= ${BINDIR}/${PROG} /usr/libexec/${PROG}
MLINKS= rtld.1 ld-elf.so.1.1 \
rtld.1 ld.so.1
.if ${MACHINE_CPUARCH} == "sparc64"
CFLAGS+= -fPIC
.else
CFLAGS+= -fpic
.endif
CFLAGS+= -DPIC $(DEBUG)
LDFLAGS+= -shared -Wl,-Bsymbolic
DPADD= ${LIBC_PIC}
LDADD= -lc_pic
.if ${MACHINE_CPUARCH} == "arm" && ${MK_ARM_EABI} != "no"
# Some of the required math functions (div & mod) are implemented in
# libcompiler_rt on ARM. The library also needs to be placed first to be
# correctly linked. As some of the functions are used before we have
# shared libraries.
DPADD+= ${LIBCOMPILER_RT}
LDADD+= -lcompiler_rt
.endif
.if ${MK_SYMVER} == "yes"
LIBCDIR= ${TOPSRCDIR}/lib/libc
VERSION_DEF= ${LIBCDIR}/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
VERSION_MAP= Version.map
LDFLAGS+= -Wl,--version-script=${VERSION_MAP}
${PROG}: ${VERSION_MAP}
.if exists(${.CURDIR}/${RTLD_ARCH}/Symbol.map)
SYMBOL_MAPS+= ${.CURDIR}/${RTLD_ARCH}/Symbol.map
.endif
.endif
.sinclude "${.CURDIR}/${RTLD_ARCH}/Makefile.inc"
# Since moving rtld-elf to /libexec, we need to create a symlink.
# Fixup the existing binary that's there so we can symlink over it.
beforeinstall:
.if exists(${DESTDIR}/usr/libexec/${PROG})
-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
.endif
.PATH: ${.CURDIR}/${RTLD_ARCH}
.if ${MK_TESTS} != "no"
SUBDIR+= tests
.endif
.include <bsd.symver.mk>
.include <bsd.prog.mk>