Home | History | Annotate | Line # | Download | only in ld.elf_so
Makefile revision 1.145
      1  1.145  riastrad #	$NetBSD: Makefile,v 1.145 2023/07/30 09:19:10 riastradh 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.145  riastrad SRCS+=		rtld.c
     76  1.145  riastrad SRCS+=		reloc.c
     77  1.145  riastrad SRCS+=		symbol.c
     78  1.145  riastrad SRCS+=		xmalloc.c
     79  1.145  riastrad SRCS+=		xprintf.c
     80  1.145  riastrad SRCS+=		debug.c
     81  1.145  riastrad SRCS+=		map_object.c
     82  1.145  riastrad SRCS+=		load.c
     83  1.145  riastrad SRCS+=		search.c
     84  1.145  riastrad SRCS+=		headers.c
     85  1.145  riastrad SRCS+=		paths.c
     86  1.145  riastrad SRCS+=		expand.c
     87  1.145  riastrad SRCS+=		tls.c
     88  1.145  riastrad SRCS+=		symver.c
     89  1.145  riastrad SRCS+=		diagassert.c
     90  1.145  riastrad SRCS+=		compat.c
     91   1.40   thorpej 
     92   1.85  christos .if ${USE_FORT} == "yes"
     93   1.84        ad .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc
     94   1.80  christos SRCS+=		stack_protector.c
     95   1.85  christos .endif
     96   1.83     skrll 
     97   1.83     skrll .PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
     98   1.83     skrll SRCS+=		exit.c
     99   1.80  christos 
    100  1.101     joerg errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
    101  1.101     joerg 	${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
    102  1.101     joerg 	mv -f ${.TARGET}.tmp ${.TARGET}
    103  1.101     joerg 
    104  1.101     joerg xprintf.c: errlist_concat.h
    105  1.101     joerg 
    106  1.126      matt CLEANFILES+=	errlist_concat.h ${PROG}.map
    107  1.101     joerg 
    108  1.114     joerg BINDIR=		${SHLINKINSTALLDIR}
    109  1.114     joerg 
    110  1.142     joerg CPPFLAGS.tls.c+=	-std=gnu11
    111   1.67     skrll CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
    112  1.130  christos CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
    113   1.67     skrll CPPFLAGS+=	-DRTLD_LOADER
    114  1.133  christos CPPFLAGS+=	-DGNU_RELRO
    115   1.67     skrll CPPFLAGS+=	-D_RTLD_SOURCE
    116  1.140  christos CPPFLAGS+=	-DHAVE_INITFINI_ARRAY
    117   1.71    martin #CPPFLAGS+=	-DDEBUG
    118   1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG
    119   1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG_RELOC
    120  1.117      matt .if !empty(LDELFSO_MACHINE_ARCH:Mearm*)
    121  1.116      matt CPPFLAGS+=	-I${NETBSDSRCDIR}/lib/libexecinfo
    122  1.116      matt .endif
    123   1.67     skrll #DBG=		-g
    124  1.122     joerg COPTS+=		-O3
    125  1.122     joerg 
    126  1.123      matt .if ${MACHINE_CPU} != "m68k" && ${MACHINE_CPU} != "sh3" && ${MACHINE_ARCH} != "vax"
    127  1.122     joerg COPTS+=		-fomit-frame-pointer
    128  1.122     joerg .endif
    129   1.43     lukem 
    130  1.117      matt .if ${LDELFSO_MACHINE_ARCH} == "i386" || ${LDELFSO_MACHINE_ARCH} == "x86_64"
    131  1.112      matt COPTS+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
    132  1.105     joerg .endif
    133  1.105     joerg 
    134  1.114     joerg 
    135  1.114     joerg .if ${SHLIBDIR} != ${LIBDIR}
    136  1.114     joerg CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
    137  1.114     joerg .endif
    138  1.114     joerg 
    139   1.96     skrll # rtld.c and symbol.c use alloca, so disable SSP warnings.
    140   1.96     skrll COPTS.rtld.c+=	-Wno-stack-protector
    141   1.96     skrll COPTS.symbol.c+=-Wno-stack-protector
    142   1.96     skrll 
    143  1.141  christos .if ${MACHINE_CPU} == "vax"
    144  1.141  christos COPTS.rtld.c+=	-O0
    145  1.141  christos .endif
    146  1.141  christos 
    147  1.136  christos LDADD+=		-Wl,--version-script=${.CURDIR}/symbols.map
    148   1.77      matt LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
    149   1.77      matt .if ${MKPICLIB} != "no"
    150   1.77      matt LDADD+=		-lc_pic
    151   1.68     enami .if ${MKPICINSTALL} != "no"
    152   1.67     skrll DPADD+=		${LIBC_PIC}
    153   1.60       uwe .endif
    154   1.67     skrll DPADD+=		${CLIBOBJ}/libc_pic.a
    155   1.77      matt .else
    156   1.77      matt LDADD+=		-lc
    157   1.77      matt DPADD+=		${CLIBOBJ}/libc.a
    158   1.77      matt .endif
    159    1.1       cgd 
    160  1.135  christos .if ${MACHINE_CPU} == "hppa" || ${MACHINE_CPU} == "sh3"
    161  1.107  christos # for $$divU, $$remU etc. (millicode)
    162  1.110       mrg LDADD+=		-lgcc
    163  1.110       mrg DPADD+=		${LIBGCC}
    164  1.107  christos .endif
    165  1.107  christos 
    166    1.4   thorpej STRIPFLAG=
    167    1.1       cgd 
    168   1.23  jonathan .PATH: $M
    169    1.1       cgd 
    170  1.115  christos 
    171   1.36  christos ${PROG}: ${OBJS} ${DPADD}
    172   1.64     lukem 	${_MKMSG_LINK} ${PROG}
    173   1.72     lukem 	${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LDADD}
    174  1.115  christos .if ${MKDEBUG} != "no"
    175  1.115  christos 	(  ${OBJCOPY} --only-keep-debug ${.TARGET} ${.TARGET}.debug \
    176  1.115  christos 	   && ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
    177  1.115  christos 	   --add-gnu-debuglink=${.TARGET}.debug ${.TARGET} \
    178  1.115  christos 	) || (rm -f ${.TARGET}.debug; false)
    179  1.115  christos 
    180  1.115  christos _PROGDEBUG.${PROG} := ${PROG}.debug
    181  1.115  christos .endif
    182  1.115  christos 
    183   1.35  christos 
    184  1.114     joerg .if ${SHLINKINSTALLDIR} != "/usr/libexec"
    185  1.114     joerg SYMLINKS+=	${SHLINKINSTALLDIR}/${PROG} /usr/libexec/${PROG}
    186  1.119  christos .if ${MKDEBUG} != "no"
    187  1.120     skrll SYMLINKS+=	${DEBUGDIR}${BINDIR}/${PROG}.debug \
    188  1.120     skrll 		${DEBUGDIR}/usr${BINDIR}/${PROG}.debug
    189  1.119  christos .endif
    190    1.7       mrg .endif
    191    1.1       cgd 
    192    1.1       cgd .include <bsd.prog.mk>
    193   1.45     skrll .else
    194   1.45     skrll 
    195   1.68     enami MAN=		ld.elf_so.1
    196   1.45     skrll 
    197   1.45     skrll .include <bsd.man.mk>
    198   1.45     skrll .endif
    199