xref: /freebsd-14.2/libexec/rtld-elf/Makefile (revision 3cce838c)
19d085703SBruce Evans
2d3b06cf2SKonstantin Belousov# Use the following command to build local debug version of dynamic
3d3b06cf2SKonstantin Belousov# linker:
4e3e21edbSKonstantin Belousov# make DEBUG_FLAGS=-g WITHOUT_TESTS=yes all
5d3b06cf2SKonstantin Belousov
6a4330302SBrooks DavisRTLD_ELF_DIR:=	${.PARSEDIR}
7a4330302SBrooks Davis
8c6063d0dSWarner Losh.include <src.opts.mk>
9c389411cSGlen BarberPACKAGE=	clibs
10bcf99d2dSEd MasteMK_PIE=		no # Always position independent using local rules
117bc797e3SAlex Richardson# Not compatible with sanitizer instrumentation or SSP.
127bc797e3SAlex RichardsonMK_ASAN=	no
13d9ca85fcSRuslan ErmilovMK_SSP=		no
147bc797e3SAlex RichardsonMK_UBSAN=	no
1500fb440cSDaniel Eischen
16195e5054SJessica Clarke.include <bsd.compat.pre.mk>
17195e5054SJessica Clarke
18d0f0e0bdSEmmanuel Vadot.if !defined(NEED_COMPAT)
199a537769SBrad DavisCONFS=		libmap.conf
20d0f0e0bdSEmmanuel Vadot.endif
21c905e45dSPeter WemmPROG?=		ld-elf.so.1
22195e5054SJessica Clarke.for _libcompat in ${_ALL_libcompats}
23195e5054SJessica Clarke.if ${PROG:M*ld-elf${_libcompat}[-.]*} != ""
24195e5054SJessica ClarkeTAGS+=		lib${_libcompat}
25c389411cSGlen Barber.endif
26195e5054SJessica Clarke.endfor
27d49ca25dSKonstantin BelousovSRCS= \
28e9751a84SJohn Baldwin	crtbrand.S \
29d49ca25dSKonstantin Belousov	rtld_start.S \
30d49ca25dSKonstantin Belousov	reloc.c \
31d49ca25dSKonstantin Belousov	rtld.c \
32d49ca25dSKonstantin Belousov	rtld_lock.c \
33d49ca25dSKonstantin Belousov	rtld_malloc.c \
34d49ca25dSKonstantin Belousov	rtld_printf.c \
35d49ca25dSKonstantin Belousov	map_object.c \
36d49ca25dSKonstantin Belousov	xmalloc.c \
37d49ca25dSKonstantin Belousov	debug.c \
38d49ca25dSKonstantin Belousov	libmap.c
39a4330302SBrooks DavisMAN?=		rtld.1
40e9751a84SJohn BaldwinACFLAGS+=	-DLOCORE
41a697425cSJohn BaldwinCFLAGS+=	-Wall -DIN_RTLD -ffreestanding
423c89d6b0SBryan DreweryCFLAGS+=	-I${SRCTOP}/lib/csu/common
4324faccc2SBrandon Bergren.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
4424faccc2SBrandon BergrenRTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
45789e8545SNathan Whitehorn.else
46789e8545SNathan WhitehornRTLD_ARCH=	${MACHINE_CPUARCH}
47789e8545SNathan Whitehorn.endif
48a4330302SBrooks DavisCFLAGS+=	-I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
49903e0ffdSAlex Richardson
50903e0ffdSAlex RichardsonNO_WCAST_ALIGN=	yes
51dee651ebSRuslan ErmilovINSTALLFLAGS=	-C -b
52dee651ebSRuslan ErmilovPRECIOUSPROG=
53f31c1e3fSPawel Jakub DawidekBINDIR=		/libexec
54ce9f2d31SRodney W. GrimesSYMLINKS=	../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
55051ed84fSBrooks DavisMLINKS?=	rtld.1 ld-elf.so.1.1 \
56d9943f16SAlexey Zelkin		rtld.1 ld.so.1
5713575fc4SDoug Rabson
587e3300e5SKonstantin BelousovCFLAGS+=	-fpic -DPIC $(DEBUG)
597838a782SMichal Meloun
607e3300e5SKonstantin BelousovLDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs -nostdlib -e ${RTLD_ENTRY}
61b54a59f3SAlex Richardson# Pull in the dependencies that we use from libc
62b54a59f3SAlex Richardson.include "rtld-libc/Makefile.inc"
637ca8e6a6SAlexander Kabaev
643c89d6b0SBryan DreweryVERSION_DEF=	${LIBCSRCDIR}/Versions.def
65a4330302SBrooks DavisSYMBOL_MAPS=	${RTLD_ELF_DIR}/Symbol.map
667ca8e6a6SAlexander KabaevVERSION_MAP=	Version.map
677ca8e6a6SAlexander KabaevLDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
687ca8e6a6SAlexander Kabaev
69a4330302SBrooks Davis.if exists(${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map)
70a4330302SBrooks DavisSYMBOL_MAPS+=	${RTLD_ELF_DIR}/${RTLD_ARCH}/Symbol.map
717ca8e6a6SAlexander Kabaev.endif
72d5b537d0SJohn Polstra
73a4330302SBrooks Davis.sinclude "${RTLD_ELF_DIR}/${RTLD_ARCH}/Makefile.inc"
747e3300e5SKonstantin BelousovRTLD_ENTRY?=	.rtld_start
753124c3e0SJohn Polstra
765a984731SKonstantin Belousov# Always produce the map file so that may be inspected to confirm
775a984731SKonstantin Belousov# undesired code is not linked from libsys/libc.
785a984731SKonstantin BelousovMAPFILE=	ld-elf.so.1.map
795a984731SKonstantin BelousovLDFLAGS+=	-Wl,-Map=${MAPFILE} -Wl,--cref
805a984731SKonstantin BelousovCLEANFILES+=	${MAPFILE}
815a984731SKonstantin Belousov
82*3cce838cSKonstantin Belousovafterbuild:
83*3cce838cSKonstantin Belousov	@if grep __libsys_interposing ${MAPFILE} >/dev/null ; then \
84*3cce838cSKonstantin Belousov		echo "libsys_interposing leaked" 1>&2 ; \
85*3cce838cSKonstantin Belousov		exit 1 ; \
86*3cce838cSKonstantin Belousov	fi
87*3cce838cSKonstantin Belousov	@if grep __libc_interposing ${MAPFILE} >/dev/null ; then \
88*3cce838cSKonstantin Belousov		echo "libc_interposing leaked" 1>&2 ; \
89*3cce838cSKonstantin Belousov		exit 1 ; \
90*3cce838cSKonstantin Belousov	fi
91*3cce838cSKonstantin Belousov	@if grep xlocale ${MAPFILE} >/dev/null ; then \
92*3cce838cSKonstantin Belousov		echo "xlocale leaked" 1>&2 ; \
93*3cce838cSKonstantin Belousov		exit 1 ; \
94*3cce838cSKonstantin Belousov	fi
95*3cce838cSKonstantin Belousov	@if grep fprintf ${MAPFILE} >/dev/null ; then \
96*3cce838cSKonstantin Belousov		echo "stdio leaked" 1>&2 ; \
97*3cce838cSKonstantin Belousov		exit 1 ; \
98*3cce838cSKonstantin Belousov	fi
99*3cce838cSKonstantin Belousov
100*3cce838cSKonstantin Belousov
101a857d930SGordon Tetlow# Since moving rtld-elf to /libexec, we need to create a symlink.
102a857d930SGordon Tetlow# Fixup the existing binary that's there so we can symlink over it.
103a857d930SGordon Tetlowbeforeinstall:
1041508ab98SBryan Drewery.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
105456b64c4SPawel Jakub Dawidek	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
1061b1aa7e4SRuslan Ermilov.endif
107a857d930SGordon Tetlow
108e9751a84SJohn Baldwin.PATH: ${RTLD_ELF_DIR}/${RTLD_ARCH} ${SRCTOP}/lib/csu/common
1093124c3e0SJohn Polstra
110a4330302SBrooks Davis.if ${.CURDIR} == ${RTLD_ELF_DIR}
111d511b20aSEnji CooperHAS_TESTS=
1124b330699SEnji CooperSUBDIR.${MK_TESTS}+= tests
113a4330302SBrooks Davis.endif
1146b22f423SJonathan Anderson
11563f93c7eSRyan Libby# Some of the required math functions (div & mod) are implemented in
11663f93c7eSRyan Libby# libcompiler_rt on some architectures.
11763f93c7eSRyan LibbyLIBADD+=	compiler_rt
11863f93c7eSRyan Libby
1193124c3e0SJohn Polstra.include <bsd.prog.mk>
120e7debdcbSBryan Drewery${PROG_FULL}:	${VERSION_MAP}
121056b7d85SBryan Drewery.include <bsd.symver.mk>
122903e0ffdSAlex Richardson
1233ab5b6bdSAlex Richardson.if ${COMPILER_TYPE} == "gcc"
1243ab5b6bdSAlex Richardson# GCC warns about redeclarations even though they have __exported
1253ab5b6bdSAlex Richardson# and are therefore not identical to the ones from the system headers.
1263ab5b6bdSAlex RichardsonCFLAGS+=	-Wno-redundant-decls
1273ab5b6bdSAlex Richardson.endif
128