xref: /freebsd/libexec/rtld-elf/Makefile (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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.if !defined(NEED_COMPAT)
18CONFS=		libmap.conf
19.endif
20PROG?=		ld-elf.so.1
21.if (${PROG:M*ld-elf32*} != "")
22TAGS+=		lib32
23.endif
24SRCS= \
25	crtbrand.S \
26	rtld_start.S \
27	reloc.c \
28	rtld.c \
29	rtld_lock.c \
30	rtld_malloc.c \
31	rtld_printf.c \
32	map_object.c \
33	xmalloc.c \
34	debug.c \
35	libmap.c
36MAN?=		rtld.1
37ACFLAGS+=	-DLOCORE
38CFLAGS+=	-Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding
39CFLAGS+=	-I${SRCTOP}/lib/csu/common
40.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
41RTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
42.else
43RTLD_ARCH=	${MACHINE_CPUARCH}
44.endif
45CFLAGS+=	-I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
46
47NO_WCAST_ALIGN=	yes
48INSTALLFLAGS=	-C -b
49PRECIOUSPROG=
50BINDIR=		/libexec
51SYMLINKS=	../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
52MLINKS?=	rtld.1 ld-elf.so.1.1 \
53		rtld.1 ld.so.1
54
55CFLAGS+=	-fpic -DPIC $(DEBUG)
56
57LDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs -nostdlib -e ${RTLD_ENTRY}
58# Pull in the dependencies that we use from libc
59.include "rtld-libc/Makefile.inc"
60.if ${MK_TOOLCHAIN} == "no"
61LDFLAGS+=	-L${LIBCDIR}
62.endif
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