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