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# Since moving rtld-elf to /libexec, we need to create a symlink. 77# Fixup the existing binary that's there so we can symlink over it. 78beforeinstall: 79.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no" 80 -chflags -h noschg ${DESTDIR}/usr/libexec/${PROG} 81.endif 82 83.PATH: ${RTLD_ELF_DIR}/${RTLD_ARCH} ${SRCTOP}/lib/csu/common 84 85.if ${.CURDIR} == ${RTLD_ELF_DIR} 86HAS_TESTS= 87SUBDIR.${MK_TESTS}+= tests 88.endif 89 90# Some of the required math functions (div & mod) are implemented in 91# libcompiler_rt on some architectures. 92LIBADD+= compiler_rt 93 94.include <bsd.prog.mk> 95${PROG_FULL}: ${VERSION_MAP} 96.include <bsd.symver.mk> 97 98.if ${COMPILER_TYPE} == "gcc" 99# GCC warns about redeclarations even though they have __exported 100# and are therefore not identical to the ones from the system headers. 101CFLAGS+= -Wno-redundant-decls 102.endif 103