]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rtld-elf/rtld-libc/Makefile.inc
Merge ^/vendor/compiler-rt/dist up to its last change, and resolve conflicts.
[FreeBSD/FreeBSD.git] / libexec / rtld-elf / rtld-libc / Makefile.inc
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
7 LIBC_SRCTOP=${SRCTOP}/lib/libc
8 .if exists(${LIBC_SRCTOP}/${MACHINE_ARCH})
9 LIBC_ARCH=${MACHINE_ARCH}
10 .else
11 LIBC_ARCH=${MACHINE_CPUARCH}
12 .endif
13
14 CFLAGS+=        -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
21 SRCS+=  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
26 SRCS+=  rtld_libc.c
27
28 # Now build the remaining files from libc:
29 .PATH: ${LIBC_SRCTOP}/stdlib
30 SRCS+=  reallocf.c realpath.c getenv.c merge.c reallocarray.c
31 # TODO: fix merge.c to build with WARNS=6
32 .if ${COMPILER_TYPE} == "clang"
33 CFLAGS.merge.c+=-Wno-error=null-pointer-arithmetic
34 .endif
35 .PATH: ${LIBC_SRCTOP}/gen
36 SRCS+=  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:
39 CFLAGS.errlst.c+=-I${LIBC_SRCTOP}/include
40
41 # Use the string and memory .o files from libc instead of rebuilding them (they
42 # might be using optimized assembly and duplicating that logic here is awkward).
43 _libc_string_objects=   bcmp bcopy bzero memset memchr memcmp memcpy memmove \
44     stpncpy strcat strchr strcmp stpcpy strcpy strcspn strdup strlcat strlcpy \
45     strlen strncmp strncpy strrchr strsep strspn strstr strtok
46 # Also use all the syscall .o files from libc_nossp_pic:
47 _libc_other_objects= sigsetjmp lstat stat fstat fstatat fstatfs syscall \
48     cerror geteuid getegid munmap mprotect sysarch __sysctl issetugid __getcwd \
49     utrace thr_self thr_kill pread mmap lseek _exit _fstat _fstatat _fstatfs \
50     getdirentries _getdirentries _close _fcntl _open _openat _read \
51     _sigprocmask _write readlink _setjmp setjmp setjmperr
52
53
54 # Finally add additional architecture-dependent libc dependencies
55 .if ${LIBC_ARCH} == "arm"
56 # ARM needs aeabi_unwind_cpp for _setjmp
57 _libc_other_objects+=aeabi_unwind_cpp
58 .elif ${LIBC_ARCH} == "i386"
59 # __udivdi3 is needed by kvprintf() in rtld_printf.c
60 # i386 also needs i386_set_gsbase for allocate_initial_tls()
61 _libc_other_objects+=umoddi3 udivdi3 qdivrem i386_set_gsbase
62 .elif ${LIBC_ARCH} == "powerpc" || ${LIBC_ARCH} == "powerpcspe"
63 # ppc needs __syncicache for reloc.c and __umoddi3+__udivdi3 for rtld_printf.c
64 _libc_other_objects+=syncicache umoddi3 udivdi3 qdivrem
65 # for some reason there is also a reference to abs()
66 _libc_other_objects+=abs
67 .elif ${LIBC_ARCH} == "powerpc64"
68 # ppc64 needs __syncicache for reloc.c
69 _libc_other_objects+=syncicache
70 .elif ${LIBC_ARCH} == "mips"
71 # 32-bit MIPS needs __umoddi3+__udivdi3 for rtld_printf.c
72 .if ${MACHINE_ARCH:Mmipsn32*} == "" && ${MACHINE_ARCH:Mmips64*} == ""
73 _libc_other_objects+=umoddi3 udivdi3 qdivrem
74 .endif
75 .elif ${LIBC_ARCH} == "sparc64"
76 # reloc.c uses __sparc_utrap which needs a lot of other object files
77 _libc_other_objects+=__sparc_utrap __sparc_utrap_fp_disabled __sparc_utrap_gen \
78     __sparc_utrap_setup __sparc_utrap_align __sparc_utrap_emul kill getpid \
79     fpu fpu_explode fpu_div fpu_reg fpu_sqrt fpu_implode fpu_subr fpu_add \
80     fpu_compare fpu_mul
81 .endif
82
83 # Extract all the .o files from libc_nossp_pic.a. This ensures that
84 # we don't accidentally pull in the interposing table or similar by linking
85 # directly against libc_nossp_pic.a
86 _rtld_libc_objs=
87 .for _obj in ${_libc_other_objects} ${_libc_string_objects}
88 _rtld_libc_objs+=${_obj}.nossppico
89 CLEANFILES+=${_obj}.nossppico
90 # LDFLAGS+=     -Wl,--trace-symbol=${_obj}
91 .endfor
92 # LDFLAGS+=     -Wl,--trace
93
94 # We insert all the .o files from libc_nossp_pic.a into a new rtld_libc.a file
95 # to ensure that only .o files that are actually used end up being included.
96 rtld_libc.a: ${LIBC_NOSSP_PIC} ${SRCTOP}/libexec/rtld-elf/rtld-libc/Makefile.inc
97         ${AR} x ${LIBC_NOSSP_PIC} ${_rtld_libc_objs}
98         ${AR} cr ${.OBJDIR}/${.TARGET} ${_rtld_libc_objs}
99 CLEANFILES+=rtld_libc.a
100 LDADD+=${.OBJDIR}/rtld_libc.a
101 beforelinking: rtld_libc.a