xref: /freebsd/libexec/rtld-elf/Makefile (revision 53b70c86)
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
17CONFS=		libmap.conf
18PROG?=		ld-elf.so.1
19.if (${PROG:M*ld-elf32*} != "")
20TAGS+=		lib32
21.endif
22SRCS= \
23	crtbrand.S \
24	rtld_start.S \
25	reloc.c \
26	rtld.c \
27	rtld_lock.c \
28	rtld_malloc.c \
29	rtld_printf.c \
30	map_object.c \
31	xmalloc.c \
32	debug.c \
33	libmap.c
34MAN?=		rtld.1
35ACFLAGS+=	-DLOCORE
36CFLAGS+=	-Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding
37CFLAGS+=	-I${SRCTOP}/lib/csu/common
38.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
39RTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
40.else
41RTLD_ARCH=	${MACHINE_CPUARCH}
42.endif
43CFLAGS+=	-I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
44
45NO_WCAST_ALIGN=	yes
46INSTALLFLAGS=	-C -b
47PRECIOUSPROG=
48BINDIR=		/libexec
49SYMLINKS=	../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
50MLINKS?=	rtld.1 ld-elf.so.1.1 \
51		rtld.1 ld.so.1
52
53CFLAGS+=	-fpic -DPIC $(DEBUG)
54
55LDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs -nostdlib -e ${RTLD_ENTRY}
56# Pull in the dependencies that we use from libc
57.include "rtld-libc/Makefile.inc"
58.if ${MK_TOOLCHAIN} == "no"
59LDFLAGS+=	-L${LIBCDIR}
60.endif
61
62VERSION_DEF=	${LIBCSRCDIR}/Versions.def
63SYMBOL_MAPS=	${RTLD_ELF_DIR}/Symbol.map
64VERSION_MAP=	Version.map
65LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
66
67.if exists(${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map)
68SYMBOL_MAPS+=	${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map
69.endif
70
71.sinclude "${RTLD_ELF_DIR}/${RTLD_ARCH}/Makefile.inc"
72RTLD_ENTRY?=	.rtld_start
73
74# Since moving rtld-elf to /libexec, we need to create a symlink.
75# Fixup the existing binary that's there so we can symlink over it.
76beforeinstall:
77.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
78	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
79.endif
80
81.PATH: ${RTLD_ELF_DIR}/${RTLD_ARCH} ${SRCTOP}/lib/csu/common
82
83.if ${.CURDIR} == ${RTLD_ELF_DIR}
84HAS_TESTS=
85SUBDIR.${MK_TESTS}+= tests
86.endif
87
88# Some of the required math functions (div & mod) are implemented in
89# libcompiler_rt on some architectures.
90LIBADD+=	compiler_rt
91
92.include <bsd.prog.mk>
93${PROG_FULL}:	${VERSION_MAP}
94.include <bsd.symver.mk>
95
96.if ${COMPILER_TYPE} == "gcc"
97# GCC warns about redeclarations even though they have __exported
98# and are therefore not identical to the ones from the system headers.
99CFLAGS+=	-Wno-redundant-decls
100.endif
101