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