1 2# Use the following command to build local debug version of dynamic 3# linker: 4# make DEBUG_FLAGS=-g WITHOUT_TESTS=yes all 5 6RTLD_ELF_DIR:= ${.PARSEDIR} 7 8.include <src.opts.mk> 9PACKAGE= clibs 10MK_PIE= no # Always position independent using local rules 11# Not compatible with sanitizer instrumentation or SSP. 12MK_ASAN= no 13MK_SSP= no 14MK_UBSAN= no 15 16.include <bsd.compat.pre.mk> 17 18.if !defined(NEED_COMPAT) 19CONFS= libmap.conf 20.endif 21PROG?= ld-elf.so.1 22.for _libcompat in ${_ALL_libcompats} 23.if ${PROG:M*ld-elf${_libcompat}[-.]*} != "" 24TAGS+= lib${_libcompat} 25.endif 26.endfor 27SRCS= \ 28 crtbrand.S \ 29 rtld_start.S \ 30 reloc.c \ 31 rtld.c \ 32 rtld_lock.c \ 33 rtld_malloc.c \ 34 rtld_printf.c \ 35 map_object.c \ 36 xmalloc.c \ 37 debug.c \ 38 libmap.c 39MAN?= rtld.1 40ACFLAGS+= -DLOCORE 41CFLAGS+= -Wall -DIN_RTLD -ffreestanding 42CFLAGS+= -I${SRCTOP}/lib/csu/common 43.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/}) 44RTLD_ARCH= ${MACHINE_ARCH:S/powerpc64le/powerpc64/} 45.else 46RTLD_ARCH= ${MACHINE_CPUARCH} 47.endif 48CFLAGS+= -I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR} 49 50NO_WCAST_ALIGN= yes 51INSTALLFLAGS= -C -b 52PRECIOUSPROG= 53BINDIR= /libexec 54SYMLINKS= ../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG} 55MLINKS?= rtld.1 ld-elf.so.1.1 \ 56 rtld.1 ld.so.1 57 58CFLAGS+= -fpic -DPIC $(DEBUG) 59 60LDFLAGS+= -shared -Wl,-Bsymbolic -Wl,-z,defs -nostdlib -e ${RTLD_ENTRY} 61# Pull in the dependencies that we use from libc 62.include "rtld-libc/Makefile.inc" 63 64VERSION_DEF= ${LIBCSRCDIR}/Versions.def 65SYMBOL_MAPS= ${RTLD_ELF_DIR}/Symbol.map 66VERSION_MAP= Version.map 67LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 68 69.if exists(${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map) 70SYMBOL_MAPS+= ${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map 71.endif 72 73.sinclude "${RTLD_ELF_DIR}/${RTLD_ARCH}/Makefile.inc" 74RTLD_ENTRY?= .rtld_start 75 76# Always produce the map file so that may be inspected to confirm 77# undesired code is not linked from libsys/libc. 78MAPFILE= ld-elf.so.1.map 79LDFLAGS+= -Wl,-Map=${MAPFILE} -Wl,--cref 80CLEANFILES+= ${MAPFILE} 81 82afterbuild: 83 @if grep __libsys_interposing ${MAPFILE} >/dev/null ; then \ 84 echo "libsys_interposing leaked" 1>&2 ; \ 85 exit 1 ; \ 86 fi 87 @if grep __libc_interposing ${MAPFILE} >/dev/null ; then \ 88 echo "libc_interposing leaked" 1>&2 ; \ 89 exit 1 ; \ 90 fi 91 @if grep xlocale ${MAPFILE} >/dev/null ; then \ 92 echo "xlocale leaked" 1>&2 ; \ 93 exit 1 ; \ 94 fi 95 @if grep fprintf ${MAPFILE} >/dev/null ; then \ 96 echo "stdio leaked" 1>&2 ; \ 97 exit 1 ; \ 98 fi 99 100 101# Since moving rtld-elf to /libexec, we need to create a symlink. 102# Fixup the existing binary that's there so we can symlink over it. 103beforeinstall: 104.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no" 105 -chflags -h noschg ${DESTDIR}/usr/libexec/${PROG} 106.endif 107 108.PATH: ${RTLD_ELF_DIR}/${RTLD_ARCH} ${SRCTOP}/lib/csu/common 109 110.if ${.CURDIR} == ${RTLD_ELF_DIR} 111HAS_TESTS= 112SUBDIR.${MK_TESTS}+= tests 113.endif 114 115# Some of the required math functions (div & mod) are implemented in 116# libcompiler_rt on some architectures. 117LIBADD+= compiler_rt 118 119.include <bsd.prog.mk> 120${PROG_FULL}: ${VERSION_MAP} 121.include <bsd.symver.mk> 122 123.if ${COMPILER_TYPE} == "gcc" 124# GCC warns about redeclarations even though they have __exported 125# and are therefore not identical to the ones from the system headers. 126CFLAGS+= -Wno-redundant-decls 127.endif 128