2019-06-30 11:49:58 +00:00
|
|
|
# $FreeBSD$
|
|
|
|
# This makefiles adds the necessary libc dependencies for RTLD without pulling
|
|
|
|
# in all of the complex libc bits such as locales, etc.
|
|
|
|
|
|
|
|
.include <bsd.compiler.mk>
|
|
|
|
|
|
|
|
LIBC_SRCTOP=${SRCTOP}/lib/libc
|
2020-09-23 00:21:51 +00:00
|
|
|
.if exists(${LIBC_SRCTOP}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
|
|
|
|
LIBC_ARCH=${MACHINE_ARCH:S/powerpc64le/powerpc64/}
|
2019-06-30 11:49:58 +00:00
|
|
|
.else
|
|
|
|
LIBC_ARCH=${MACHINE_CPUARCH}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
CFLAGS+= -I${SRCTOP}/libexec/rtld-elf/rtld-libc
|
|
|
|
|
|
|
|
# Build all the libc files that use interposed symbols or pthreads again for
|
|
|
|
# RTLD. We compile with a different libc_private.h and namespace.h that
|
|
|
|
# redirects all calls to interposed functions to use the non-interposed version
|
|
|
|
# instead.
|
|
|
|
.PATH: ${LIBC_SRCTOP}/gen
|
|
|
|
SRCS+= opendir.c closedir.c readdir.c telldir.c
|
|
|
|
|
|
|
|
# Avoid further dependencies by providing simple implementations of libc
|
|
|
|
# functions such as __error(), etc.
|
|
|
|
.PATH: ${SRCTOP}/libexec/rtld-elf/rtld-libc
|
|
|
|
SRCS+= rtld_libc.c
|
|
|
|
|
|
|
|
# Now build the remaining files from libc:
|
|
|
|
.PATH: ${LIBC_SRCTOP}/stdlib
|
|
|
|
SRCS+= reallocf.c realpath.c getenv.c merge.c reallocarray.c
|
|
|
|
# TODO: fix merge.c to build with WARNS=6
|
|
|
|
.if ${COMPILER_TYPE} == "clang"
|
|
|
|
CFLAGS.merge.c+=-Wno-error=null-pointer-arithmetic
|
|
|
|
.endif
|
|
|
|
.PATH: ${LIBC_SRCTOP}/gen
|
|
|
|
SRCS+= errlst.c getcwd.c getprogname.c raise.c sigsetops.c sysctlnametomib.c \
|
|
|
|
__xuname.c
|
|
|
|
# errlst.c needs the errlst.h header from libc:
|
|
|
|
CFLAGS.errlst.c+=-I${LIBC_SRCTOP}/include
|
|
|
|
|
|
|
|
# Use the string and memory .o files from libc instead of rebuilding them (they
|
|
|
|
# might be using optimized assembly and duplicating that logic here is awkward).
|
2020-01-15 01:30:32 +00:00
|
|
|
_libc_string_objects= bcmp bcopy bzero memset memchr memcmp memcpy memmove \
|
|
|
|
stpncpy strcat strchr strcmp stpcpy strcpy strcspn strdup strlcat strlcpy \
|
|
|
|
strlen strncmp strncpy strrchr strsep strspn strstr strtok
|
2019-06-30 11:49:58 +00:00
|
|
|
# Also use all the syscall .o files from libc_nossp_pic:
|
|
|
|
_libc_other_objects= sigsetjmp lstat stat fstat fstatat fstatfs syscall \
|
2020-02-09 12:22:43 +00:00
|
|
|
cerror geteuid getegid sigfastblock munmap mprotect \
|
2020-06-12 22:10:03 +00:00
|
|
|
sysarch __sysctl issetugid __getcwd utrace getpid \
|
2020-02-09 12:22:43 +00:00
|
|
|
thr_self thr_kill pread mmap lseek _exit _fstat _fstatat _fstatfs \
|
2019-06-30 11:49:58 +00:00
|
|
|
getdirentries _getdirentries _close _fcntl _open _openat _read \
|
2020-02-20 16:58:19 +00:00
|
|
|
_sigprocmask _write readlink __realpathat _setjmp setjmp setjmperr
|
2019-06-30 11:49:58 +00:00
|
|
|
|
2020-12-19 08:38:31 +00:00
|
|
|
# Allow building files from libcompiler_rt. Beware, there are some name
|
|
|
|
# collisions between libcompiler_rt files and libc files.
|
|
|
|
CRTSRC= ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins
|
|
|
|
.PATH: ${CRTSRC}
|
2019-06-30 11:49:58 +00:00
|
|
|
|
2020-12-19 08:38:31 +00:00
|
|
|
# Finally add additional architecture-dependent dependencies
|
2019-06-30 11:49:58 +00:00
|
|
|
.if ${LIBC_ARCH} == "arm"
|
|
|
|
# ARM needs aeabi_unwind_cpp for _setjmp
|
|
|
|
_libc_other_objects+=aeabi_unwind_cpp
|
|
|
|
.elif ${LIBC_ARCH} == "i386"
|
|
|
|
# __udivdi3 is needed by kvprintf() in rtld_printf.c
|
|
|
|
# i386 also needs i386_set_gsbase for allocate_initial_tls()
|
2019-06-30 17:03:14 +00:00
|
|
|
_libc_other_objects+=umoddi3 udivdi3 qdivrem i386_set_gsbase
|
2020-12-19 08:38:31 +00:00
|
|
|
SRCS+= udivmoddi4.c
|
2019-06-30 11:49:58 +00:00
|
|
|
.elif ${LIBC_ARCH} == "powerpc" || ${LIBC_ARCH} == "powerpcspe"
|
|
|
|
# ppc needs __syncicache for reloc.c and __umoddi3+__udivdi3 for rtld_printf.c
|
|
|
|
_libc_other_objects+=syncicache umoddi3 udivdi3 qdivrem
|
|
|
|
# for some reason there is also a reference to abs()
|
|
|
|
_libc_other_objects+=abs
|
|
|
|
.elif ${LIBC_ARCH} == "powerpc64"
|
|
|
|
# ppc64 needs __syncicache for reloc.c
|
|
|
|
_libc_other_objects+=syncicache
|
|
|
|
.elif ${LIBC_ARCH} == "mips"
|
|
|
|
# 32-bit MIPS needs __umoddi3+__udivdi3 for rtld_printf.c
|
|
|
|
.if ${MACHINE_ARCH:Mmipsn32*} == "" && ${MACHINE_ARCH:Mmips64*} == ""
|
|
|
|
_libc_other_objects+=umoddi3 udivdi3 qdivrem
|
|
|
|
.endif
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Extract all the .o files from libc_nossp_pic.a. This ensures that
|
|
|
|
# we don't accidentally pull in the interposing table or similar by linking
|
|
|
|
# directly against libc_nossp_pic.a
|
|
|
|
_rtld_libc_objs=
|
|
|
|
.for _obj in ${_libc_other_objects} ${_libc_string_objects}
|
|
|
|
_rtld_libc_objs+=${_obj}.nossppico
|
|
|
|
CLEANFILES+=${_obj}.nossppico
|
|
|
|
# LDFLAGS+= -Wl,--trace-symbol=${_obj}
|
|
|
|
.endfor
|
|
|
|
# LDFLAGS+= -Wl,--trace
|
|
|
|
|
|
|
|
# We insert all the .o files from libc_nossp_pic.a into a new rtld_libc.a file
|
|
|
|
# to ensure that only .o files that are actually used end up being included.
|
|
|
|
rtld_libc.a: ${LIBC_NOSSP_PIC} ${SRCTOP}/libexec/rtld-elf/rtld-libc/Makefile.inc
|
2020-12-19 08:38:27 +00:00
|
|
|
@rm -f ${.TARGET}
|
2019-06-30 11:49:58 +00:00
|
|
|
${AR} x ${LIBC_NOSSP_PIC} ${_rtld_libc_objs}
|
2020-12-19 08:38:27 +00:00
|
|
|
${AR} cr ${.TARGET} ${_rtld_libc_objs}
|
2019-06-30 11:49:58 +00:00
|
|
|
CLEANFILES+=rtld_libc.a
|
|
|
|
LDADD+=${.OBJDIR}/rtld_libc.a
|
2019-07-02 22:11:07 +00:00
|
|
|
beforelinking: rtld_libc.a
|