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