Home | History | Annotate | Line # | Download | only in ld.elf_so
Makefile revision 1.144.2.1
      1  1.144.2.1    martin #	$NetBSD: Makefile,v 1.144.2.1 2023/08/01 17:03:53 martin Exp $
      2       1.90        ad #
      3       1.90        ad # NOTE: when changing ld.so, ensure that ldd still compiles.
      4       1.90        ad #
      5      1.143     kamil NOLIBCSANITIZER=# defined
      6      1.138  christos NOSANITIZER=	# defined
      7       1.89  christos WARNS?=4
      8        1.5       cjs 
      9      1.117      matt LDELFSO_MACHINE_ARCH?= ${MACHINE_ARCH}
     10      1.117      matt 
     11       1.92       mrg # This needs to be before bsd.init.mk
     12       1.92       mrg .if defined(BSD_MK_COMPAT_FILE)
     13       1.92       mrg .include <${BSD_MK_COMPAT_FILE}>
     14       1.92       mrg .endif
     15       1.92       mrg 
     16       1.86  christos # We are not building this with PIE
     17       1.86  christos PIE_CFLAGS=
     18       1.86  christos PIE_LDFLAGS=
     19       1.97       mrg .include <bsd.init.mk>			# for MKPIC definition
     20      1.114     joerg .include <bsd.shlib.mk>			# for SHLINKINSTALLDIR definition
     21       1.11  jonathan 
     22       1.87       mrg .if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
     23       1.87       mrg     exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
     24       1.87       mrg ARCHSUBDIR=	${LDELFSO_MACHINE_CPU}
     25       1.87       mrg .else
     26       1.67     skrll ARCHSUBDIR=	${MACHINE_CPU}
     27       1.87       mrg .endif
     28       1.67     skrll M=		${.CURDIR}/arch/${ARCHSUBDIR}
     29       1.23  jonathan 
     30      1.127      matt .if ((${MACHINE_CPU} == "aarch64") ||					\
     31      1.127      matt      (${LDELFSO_MACHINE_ARCH} == "alpha") ||				\
     32       1.75    simonb      (${MACHINE_CPU} == "arm") ||					\
     33      1.121      matt      (${LDELFSO_MACHINE_ARCH} == "coldfire") ||				\
     34      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "hppa") ||				\
     35      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "i386") ||				\
     36      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "m68k") ||				\
     37       1.75    simonb      (${MACHINE_CPU} == "mips") ||					\
     38      1.128      matt      (${MACHINE_CPU} == "or1k") ||					\
     39      1.126      matt      (${MACHINE_CPU} == "powerpc") ||					\
     40      1.129      matt      (${MACHINE_CPU} == "riscv") ||					\
     41       1.75    simonb      (${MACHINE_CPU} == "sh3") ||					\
     42      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "sparc") ||				\
     43      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "sparc64") ||				\
     44      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "x86_64") ||				\
     45      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "vax")) &&				\
     46       1.97       mrg     ${MKPIC} != "no"
     47       1.29   thorpej 
     48      1.106     joerg LDFLAGS+=	${${ACTIVE_CC} == "clang":? -Wl,-Bsymbolic : -symbolic} \
     49      1.106     joerg 		-shared -nostartfiles -nodefaultlibs
     50       1.74     skrll LDFLAGS+=	-Wl,-static
     51      1.102      matt LDFLAGS+=	-Wl,--warn-shared-textrel
     52      1.144     skrll LDFLAGS+=	-Wl,--no-undefined
     53      1.126      matt LDFLAGS+=	-Wl,-Map=${.TARGET}.map
     54      1.102      matt 
     55      1.112      matt COPTS+=		-fvisibility=hidden
     56       1.66       uwe 
     57        1.8     lukem # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
     58        1.1       cgd # is first.
     59       1.23  jonathan .if exists($M/Makefile.inc)
     60       1.23  jonathan .include "$M/Makefile.inc"
     61        1.3       cgd .endif
     62        1.1       cgd 
     63       1.93       mrg # Support compat ld.elf_so.
     64       1.91       mrg .if defined(MLIBDIR)
     65       1.93       mrg PROG=		ld.elf_so-${MLIBDIR}
     66       1.93       mrg CPPFLAGS+=	-DRTLD_ARCH_SUBDIR=\"${MLIBDIR}\"
     67      1.134  christos .	if ${MLIBDIR} == "o32"
     68      1.134  christos .	endif
     69       1.87       mrg .else
     70       1.93       mrg PROG=		ld.elf_so
     71       1.93       mrg .endif
     72       1.93       mrg 
     73       1.51     lukem CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
     74       1.44        tv 
     75  1.144.2.1    martin SRCS+=		compat.c
     76  1.144.2.1    martin SRCS+=		debug.c
     77  1.144.2.1    martin SRCS+=		diagassert.c
     78  1.144.2.1    martin SRCS+=		expand.c
     79  1.144.2.1    martin SRCS+=		hash.c
     80  1.144.2.1    martin SRCS+=		headers.c
     81  1.144.2.1    martin SRCS+=		load.c
     82  1.144.2.1    martin SRCS+=		map_object.c
     83  1.144.2.1    martin SRCS+=		paths.c
     84  1.144.2.1    martin SRCS+=		reloc.c
     85  1.144.2.1    martin SRCS+=		rtld.c
     86  1.144.2.1    martin SRCS+=		search.c
     87  1.144.2.1    martin SRCS+=		symbol.c
     88  1.144.2.1    martin SRCS+=		symver.c
     89  1.144.2.1    martin SRCS+=		tls.c
     90  1.144.2.1    martin SRCS+=		xmalloc.c
     91  1.144.2.1    martin SRCS+=		xprintf.c
     92       1.40   thorpej 
     93       1.85  christos .if ${USE_FORT} == "yes"
     94       1.84        ad .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc
     95       1.80  christos SRCS+=		stack_protector.c
     96       1.85  christos .endif
     97       1.83     skrll 
     98       1.83     skrll .PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
     99       1.83     skrll SRCS+=		exit.c
    100       1.80  christos 
    101      1.101     joerg errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
    102      1.101     joerg 	${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
    103      1.101     joerg 	mv -f ${.TARGET}.tmp ${.TARGET}
    104      1.101     joerg 
    105      1.101     joerg xprintf.c: errlist_concat.h
    106      1.101     joerg 
    107      1.126      matt CLEANFILES+=	errlist_concat.h ${PROG}.map
    108      1.101     joerg 
    109      1.114     joerg BINDIR=		${SHLINKINSTALLDIR}
    110      1.114     joerg 
    111      1.142     joerg CPPFLAGS.tls.c+=	-std=gnu11
    112       1.67     skrll CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
    113      1.130  christos CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
    114       1.67     skrll CPPFLAGS+=	-DRTLD_LOADER
    115      1.133  christos CPPFLAGS+=	-DGNU_RELRO
    116       1.67     skrll CPPFLAGS+=	-D_RTLD_SOURCE
    117      1.140  christos CPPFLAGS+=	-DHAVE_INITFINI_ARRAY
    118       1.71    martin #CPPFLAGS+=	-DDEBUG
    119       1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG
    120       1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG_RELOC
    121      1.117      matt .if !empty(LDELFSO_MACHINE_ARCH:Mearm*)
    122      1.116      matt CPPFLAGS+=	-I${NETBSDSRCDIR}/lib/libexecinfo
    123      1.116      matt .endif
    124       1.67     skrll #DBG=		-g
    125      1.122     joerg COPTS+=		-O3
    126      1.122     joerg 
    127      1.123      matt .if ${MACHINE_CPU} != "m68k" && ${MACHINE_CPU} != "sh3" && ${MACHINE_ARCH} != "vax"
    128      1.122     joerg COPTS+=		-fomit-frame-pointer
    129      1.122     joerg .endif
    130       1.43     lukem 
    131      1.117      matt .if ${LDELFSO_MACHINE_ARCH} == "i386" || ${LDELFSO_MACHINE_ARCH} == "x86_64"
    132      1.112      matt COPTS+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
    133      1.105     joerg .endif
    134      1.105     joerg 
    135      1.114     joerg 
    136      1.114     joerg .if ${SHLIBDIR} != ${LIBDIR}
    137      1.114     joerg CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
    138      1.114     joerg .endif
    139      1.114     joerg 
    140       1.96     skrll # rtld.c and symbol.c use alloca, so disable SSP warnings.
    141       1.96     skrll COPTS.rtld.c+=	-Wno-stack-protector
    142       1.96     skrll COPTS.symbol.c+=-Wno-stack-protector
    143       1.96     skrll 
    144      1.141  christos .if ${MACHINE_CPU} == "vax"
    145      1.141  christos COPTS.rtld.c+=	-O0
    146      1.141  christos .endif
    147      1.141  christos 
    148      1.136  christos LDADD+=		-Wl,--version-script=${.CURDIR}/symbols.map
    149       1.77      matt LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
    150       1.77      matt .if ${MKPICLIB} != "no"
    151       1.77      matt LDADD+=		-lc_pic
    152       1.68     enami .if ${MKPICINSTALL} != "no"
    153       1.67     skrll DPADD+=		${LIBC_PIC}
    154       1.60       uwe .endif
    155       1.67     skrll DPADD+=		${CLIBOBJ}/libc_pic.a
    156       1.77      matt .else
    157       1.77      matt LDADD+=		-lc
    158       1.77      matt DPADD+=		${CLIBOBJ}/libc.a
    159       1.77      matt .endif
    160        1.1       cgd 
    161      1.135  christos .if ${MACHINE_CPU} == "hppa" || ${MACHINE_CPU} == "sh3"
    162      1.107  christos # for $$divU, $$remU etc. (millicode)
    163      1.110       mrg LDADD+=		-lgcc
    164      1.110       mrg DPADD+=		${LIBGCC}
    165      1.107  christos .endif
    166      1.107  christos 
    167        1.4   thorpej STRIPFLAG=
    168        1.1       cgd 
    169       1.23  jonathan .PATH: $M
    170        1.1       cgd 
    171      1.115  christos 
    172       1.36  christos ${PROG}: ${OBJS} ${DPADD}
    173       1.64     lukem 	${_MKMSG_LINK} ${PROG}
    174       1.72     lukem 	${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LDADD}
    175      1.115  christos .if ${MKDEBUG} != "no"
    176      1.115  christos 	(  ${OBJCOPY} --only-keep-debug ${.TARGET} ${.TARGET}.debug \
    177      1.115  christos 	   && ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
    178      1.115  christos 	   --add-gnu-debuglink=${.TARGET}.debug ${.TARGET} \
    179      1.115  christos 	) || (rm -f ${.TARGET}.debug; false)
    180      1.115  christos 
    181      1.115  christos _PROGDEBUG.${PROG} := ${PROG}.debug
    182      1.115  christos .endif
    183      1.115  christos 
    184       1.35  christos 
    185      1.114     joerg .if ${SHLINKINSTALLDIR} != "/usr/libexec"
    186      1.114     joerg SYMLINKS+=	${SHLINKINSTALLDIR}/${PROG} /usr/libexec/${PROG}
    187      1.119  christos .if ${MKDEBUG} != "no"
    188      1.120     skrll SYMLINKS+=	${DEBUGDIR}${BINDIR}/${PROG}.debug \
    189      1.120     skrll 		${DEBUGDIR}/usr${BINDIR}/${PROG}.debug
    190      1.119  christos .endif
    191        1.7       mrg .endif
    192        1.1       cgd 
    193        1.1       cgd .include <bsd.prog.mk>
    194       1.45     skrll .else
    195       1.45     skrll 
    196       1.68     enami MAN=		ld.elf_so.1
    197       1.45     skrll 
    198       1.45     skrll .include <bsd.man.mk>
    199       1.45     skrll .endif
    200