xref: /freebsd-12.1/libexec/rtld-elf/Makefile (revision 349a1e57)
17f3dea24SPeter Wemm# $FreeBSD$
29d085703SBruce Evans
3d3b06cf2SKonstantin Belousov# Use the following command to build local debug version of dynamic
4d3b06cf2SKonstantin Belousov# linker:
54ed140ecSKonstantin Belousov# make DEBUG_FLAGS=-g WITHOUT_TESTS=yes all
6d3b06cf2SKonstantin Belousov
7c6063d0dSWarner Losh.include <src.opts.mk>
8c389411cSGlen BarberPACKAGE=	clibs
9*349a1e57SEd MasteMK_PIE=		no # Always position independent using local rules
10d9ca85fcSRuslan ErmilovMK_SSP=		no
1100fb440cSDaniel Eischen
129a537769SBrad DavisCONFS=		libmap.conf
13c905e45dSPeter WemmPROG?=		ld-elf.so.1
14c389411cSGlen Barber.if (${PROG:M*ld-elf32*} != "")
15c389411cSGlen BarberTAGS+=		lib32
16c389411cSGlen Barber.endif
17adbc4082SKonstantin BelousovSRCS= \
18adbc4082SKonstantin Belousov	rtld_start.S \
19adbc4082SKonstantin Belousov	reloc.c \
20adbc4082SKonstantin Belousov	rtld.c \
21adbc4082SKonstantin Belousov	rtld_lock.c \
22adbc4082SKonstantin Belousov	rtld_malloc.c \
23adbc4082SKonstantin Belousov	rtld_printf.c \
24adbc4082SKonstantin Belousov	map_object.c \
25adbc4082SKonstantin Belousov	xmalloc.c \
26adbc4082SKonstantin Belousov	debug.c \
27adbc4082SKonstantin Belousov	libmap.c
28e5b5c66bSRuslan ErmilovMAN=		rtld.1
298f17707cSDavid E. O'BrienCSTD?=		gnu99
304cce0e98SNathan WhitehornCFLAGS+=	-Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding
313c89d6b0SBryan DreweryCFLAGS+=	-I${SRCTOP}/lib/csu/common
32789e8545SNathan Whitehorn.if exists(${.CURDIR}/${MACHINE_ARCH})
33789e8545SNathan WhitehornRTLD_ARCH=	${MACHINE_ARCH}
34789e8545SNathan Whitehorn.else
35789e8545SNathan WhitehornRTLD_ARCH=	${MACHINE_CPUARCH}
36789e8545SNathan Whitehorn.endif
37789e8545SNathan WhitehornCFLAGS+=	-I${.CURDIR}/${RTLD_ARCH} -I${.CURDIR}
3827bd4146SNathan Whitehorn.if ${MACHINE_ARCH} == "powerpc64"
3927bd4146SNathan WhitehornLDFLAGS+=	-nostdlib -e _rtld_start
4027bd4146SNathan Whitehorn.else
41d5b537d0SJohn PolstraLDFLAGS+=	-nostdlib -e .rtld_start
4227bd4146SNathan Whitehorn.endif
43adbc4082SKonstantin Belousov
44adbc4082SKonstantin BelousovNO_WCAST_ALIGN=	yes
45adbc4082SKonstantin BelousovWARNS?=		6
46dee651ebSRuslan ErmilovINSTALLFLAGS=	-C -b
47dee651ebSRuslan ErmilovPRECIOUSPROG=
48f31c1e3fSPawel Jakub DawidekBINDIR=		/libexec
49ce9f2d31SRodney W. GrimesSYMLINKS=	../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
50d9943f16SAlexey ZelkinMLINKS=		rtld.1 ld-elf.so.1.1 \
51d9943f16SAlexey Zelkin		rtld.1 ld.so.1
5213575fc4SDoug Rabson
53b9c727d8SDimitry Andric.if ${MACHINE_CPUARCH} == "sparc64"
54b9c727d8SDimitry AndricCFLAGS+=	-fPIC
55b9c727d8SDimitry Andric.else
56b9c727d8SDimitry AndricCFLAGS+=	-fpic
57b9c727d8SDimitry Andric.endif
5806786ccfSKonstantin BelousovCFLAGS+=	-DPIC $(DEBUG)
590c4f9ecdSKonstantin Belousov.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
600c4f9ecdSKonstantin BelousovCFLAGS+=	-fvisibility=hidden
610c4f9ecdSKonstantin Belousov.endif
62f4711b38SJohn Baldwin.if ${MACHINE_CPUARCH} == "mips"
63f4711b38SJohn BaldwinCFLAGS.reloc.c+=-fno-jump-tables
64f4711b38SJohn Baldwin.endif
654562cfc4SKonstantin BelousovLDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs
660725fca5SKonstantin BelousovLIBADD=		c_nossp_pic
67c0f5aeb0SBryan Drewery.if ${MK_TOOLCHAIN} == "no"
68c0f5aeb0SBryan DreweryLDFLAGS+=	-L${LIBCDIR}
69c0f5aeb0SBryan Drewery.endif
707ca8e6a6SAlexander Kabaev
716d4766c1SAndrew Turner.if ${MACHINE_CPUARCH} == "arm"
7237656b87SEd Schouten# Some of the required math functions (div & mod) are implemented in
7337656b87SEd Schouten# libcompiler_rt on ARM. The library also needs to be placed first to be
7437656b87SEd Schouten# correctly linked. As some of the functions are used before we have
7537656b87SEd Schouten# shared libraries.
76ee5a34ecSBaptiste DaroussinLIBADD+=	compiler_rt
77de2be60cSAndrew Turner.endif
78de2be60cSAndrew Turner
79de2be60cSAndrew Turner
80de2be60cSAndrew Turner
8100fb440cSDaniel Eischen.if ${MK_SYMVER} == "yes"
823c89d6b0SBryan DreweryVERSION_DEF=	${LIBCSRCDIR}/Versions.def
837ca8e6a6SAlexander KabaevSYMBOL_MAPS=	${.CURDIR}/Symbol.map
847ca8e6a6SAlexander KabaevVERSION_MAP=	Version.map
857ca8e6a6SAlexander KabaevLDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
867ca8e6a6SAlexander Kabaev
87789e8545SNathan Whitehorn.if exists(${.CURDIR}/${RTLD_ARCH}/Symbol.map)
88789e8545SNathan WhitehornSYMBOL_MAPS+=	${.CURDIR}/${RTLD_ARCH}/Symbol.map
897ca8e6a6SAlexander Kabaev.endif
90d5b537d0SJohn Polstra.endif
91d5b537d0SJohn Polstra
92789e8545SNathan Whitehorn.sinclude "${.CURDIR}/${RTLD_ARCH}/Makefile.inc"
933124c3e0SJohn Polstra
94a857d930SGordon Tetlow# Since moving rtld-elf to /libexec, we need to create a symlink.
95a857d930SGordon Tetlow# Fixup the existing binary that's there so we can symlink over it.
96a857d930SGordon Tetlowbeforeinstall:
971508ab98SBryan Drewery.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
98456b64c4SPawel Jakub Dawidek	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
991b1aa7e4SRuslan Ermilov.endif
100a857d930SGordon Tetlow
101789e8545SNathan Whitehorn.PATH: ${.CURDIR}/${RTLD_ARCH}
1023124c3e0SJohn Polstra
103d511b20aSEnji CooperHAS_TESTS=
1044b330699SEnji CooperSUBDIR.${MK_TESTS}+= tests
1056b22f423SJonathan Anderson
1063124c3e0SJohn Polstra.include <bsd.prog.mk>
107e7debdcbSBryan Drewery${PROG_FULL}:	${VERSION_MAP}
108056b7d85SBryan Drewery.include <bsd.symver.mk>
109adbc4082SKonstantin Belousov
110adbc4082SKonstantin Belousov.if ${COMPILER_TYPE} == "gcc"
111adbc4082SKonstantin Belousov# GCC warns about redeclarations even though they have __exported
112adbc4082SKonstantin Belousov# and are therefore not identical to the ones from the system headers.
113adbc4082SKonstantin BelousovCFLAGS+=	-Wno-redundant-decls
114adbc4082SKonstantin Belousov.if ${COMPILER_VERSION} < 40300
115adbc4082SKonstantin Belousov# Silence -Wshadow false positives in ancient GCC
116adbc4082SKonstantin BelousovCFLAGS+=	-Wno-shadow
117adbc4082SKonstantin Belousov.endif
118adbc4082SKonstantin Belousov.endif
119