1# $FreeBSD$ 2# This makefiles adds the necessary libc dependencies for RTLD without pulling 3# in all of the complex libc bits such as locales, etc. 4 5.include <bsd.compiler.mk> 6 7LIBC_SRCTOP=${SRCTOP}/lib/libc 8.if exists(${LIBC_SRCTOP}/${MACHINE_ARCH:S/powerpc64le/powerpc64/}) 9LIBC_ARCH=${MACHINE_ARCH:S/powerpc64le/powerpc64/} 10.else 11LIBC_ARCH=${MACHINE_CPUARCH} 12.endif 13 14CFLAGS+= -I${SRCTOP}/libexec/rtld-elf/rtld-libc 15 16# Build all the libc files that use interposed symbols or pthreads again for 17# RTLD. We compile with a different libc_private.h and namespace.h that 18# redirects all calls to interposed functions to use the non-interposed version 19# instead. 20.PATH: ${LIBC_SRCTOP}/gen 21SRCS+= opendir.c closedir.c readdir.c telldir.c 22 23# Avoid further dependencies by providing simple implementations of libc 24# functions such as __error(), etc. 25.PATH: ${SRCTOP}/libexec/rtld-elf/rtld-libc 26SRCS+= rtld_libc.c 27 28# Now build the remaining files from libc: 29.PATH: ${LIBC_SRCTOP}/stdlib 30SRCS+= reallocf.c realpath.c merge.c reallocarray.c 31# TODO: fix merge.c to build with WARNS=6 32.if ${COMPILER_TYPE} == "clang" 33CFLAGS.merge.c+=-Wno-error=null-pointer-arithmetic 34.endif 35.PATH: ${LIBC_SRCTOP}/gen 36SRCS+= errlst.c getcwd.c getprogname.c raise.c sigsetops.c sysctlnametomib.c \ 37 __xuname.c 38# errlst.c needs the errlst.h header from libc: 39CFLAGS.errlst.c+=-I${LIBC_SRCTOP}/include 40 41# use generic versions of string functions to avoid potential ifunc dispatch 42.PATH: ${LIBC_SRCTOP}/string 43SRCS+= bcopy.c bzero.c memchr.c memcmp.c memcpy.c memmove.c memset.c strcat.c \ 44 strchr.c strchrnul.c strcmp.c strcpy.c strcspn.c strdup.c strlcat.c \ 45 strlcpy.c strlen.c strncmp.c strncpy.c strrchr.c strsep.c strspn.c \ 46 strstr.c strtok.c 47CFLAGS.memchr.c+=-Wno-cast-qual 48CFLAGS.strchr.c+=-Wno-cast-qual 49CFLAGS.strchrnul.c+=-Wno-cast-qual 50CFLAGS.strcspn.c+=-Wno-sign-compare 51CFLAGS.strrchr.c+=-Wno-cast-qual 52CFLAGS.strspn.c+=-Wno-sign-compare 53CFLAGS.strstr.c+=-Wno-cast-qual -Wno-sign-compare 54CFLAGS.strtok.c+=-Wno-cast-qual 55 56# Also use all the syscall .o files from libc_nossp_pic: 57_libc_other_objects= sigsetjmp lstat stat fstat fstatat fstatfs syscall \ 58 cerror geteuid getegid sigfastblock munmap mprotect \ 59 sysarch __sysctl issetugid __getcwd utrace getpid \ 60 thr_self thr_kill pread mmap lseek _exit _fstat _fstatat _fstatfs \ 61 getdirentries _getdirentries _close _fcntl _open _openat _read \ 62 _sigprocmask _write readlink __realpathat _setjmp setjmp setjmperr 63 64 65# Finally add additional architecture-dependent libc dependencies 66.if ${LIBC_ARCH} == "arm" 67# ARM needs aeabi_unwind_cpp for _setjmp 68_libc_other_objects+=aeabi_unwind_cpp 69.elif ${LIBC_ARCH} == "i386" 70# i386 needs i386_set_gsbase for allocate_initial_tls() 71_libc_other_objects+=i386_set_gsbase 72.elif ${LIBC_ARCH} == "powerpc" || ${LIBC_ARCH} == "powerpcspe" 73# ppc needs __syncicache and abs for reloc.c 74_libc_other_objects+=syncicache abs 75.elif ${LIBC_ARCH} == "powerpc64" 76# ppc64 needs __syncicache for reloc.c 77_libc_other_objects+=syncicache 78.endif 79 80# Extract all the .o files from libc_nossp_pic.a. This ensures that 81# we don't accidentally pull in the interposing table or similar by linking 82# directly against libc_nossp_pic.a 83_rtld_libc_objs= 84.for _obj in ${_libc_other_objects} 85_rtld_libc_objs+=${_obj}.nossppico 86CLEANFILES+=${_obj}.nossppico 87# LDFLAGS+= -Wl,--trace-symbol=${_obj} 88.endfor 89# LDFLAGS+= -Wl,--trace 90 91# We insert all the .o files from libc_nossp_pic.a into a new rtld_libc.a file 92# to ensure that only .o files that are actually used end up being included. 93rtld_libc.a: ${LIBC_NOSSP_PIC} ${SRCTOP}/libexec/rtld-elf/rtld-libc/Makefile.inc 94 @rm -f ${.TARGET} 95 ${AR} x ${LIBC_NOSSP_PIC} ${_rtld_libc_objs} 96 ${AR} cr ${.TARGET} ${_rtld_libc_objs} 97CLEANFILES+=rtld_libc.a 98LDADD+=${.OBJDIR}/rtld_libc.a 99beforelinking: rtld_libc.a 100