xref: /aosp_15_r20/trusty/kernel/lib/libc-trusty/rules.mk (revision 344aa361028b423587d4ef3fa52a23d194628137)
1*344aa361SAndroid Build Coastguard Worker#
2*344aa361SAndroid Build Coastguard Worker# Copyright (c) 2022, Google, Inc. All rights reserved
3*344aa361SAndroid Build Coastguard Worker#
4*344aa361SAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person obtaining
5*344aa361SAndroid Build Coastguard Worker# a copy of this software and associated documentation files
6*344aa361SAndroid Build Coastguard Worker# (the "Software"), to deal in the Software without restriction,
7*344aa361SAndroid Build Coastguard Worker# including without limitation the rights to use, copy, modify, merge,
8*344aa361SAndroid Build Coastguard Worker# publish, distribute, sublicense, and/or sell copies of the Software,
9*344aa361SAndroid Build Coastguard Worker# and to permit persons to whom the Software is furnished to do so,
10*344aa361SAndroid Build Coastguard Worker# subject to the following conditions:
11*344aa361SAndroid Build Coastguard Worker#
12*344aa361SAndroid Build Coastguard Worker# The above copyright notice and this permission notice shall be
13*344aa361SAndroid Build Coastguard Worker# included in all copies or substantial portions of the Software.
14*344aa361SAndroid Build Coastguard Worker#
15*344aa361SAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*344aa361SAndroid Build Coastguard Worker# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*344aa361SAndroid Build Coastguard Worker# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18*344aa361SAndroid Build Coastguard Worker# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19*344aa361SAndroid Build Coastguard Worker# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20*344aa361SAndroid Build Coastguard Worker# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21*344aa361SAndroid Build Coastguard Worker# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*344aa361SAndroid Build Coastguard Worker#
23*344aa361SAndroid Build Coastguard Worker
24*344aa361SAndroid Build Coastguard WorkerLOCAL_DIR := $(GET_LOCAL_DIR)
25*344aa361SAndroid Build Coastguard Worker
26*344aa361SAndroid Build Coastguard WorkerMODULE := $(LOCAL_DIR)
27*344aa361SAndroid Build Coastguard Worker
28*344aa361SAndroid Build Coastguard WorkerMODULE_DEPS := \
29*344aa361SAndroid Build Coastguard Worker	lib/io
30*344aa361SAndroid Build Coastguard Worker
31*344aa361SAndroid Build Coastguard Workerifndef WITH_CUSTOM_MALLOC
32*344aa361SAndroid Build Coastguard WorkerMODULE_DEPS += lib/heap
33*344aa361SAndroid Build Coastguard Workerendif
34*344aa361SAndroid Build Coastguard Worker
35*344aa361SAndroid Build Coastguard Worker# Clang currently generates incorrect code when it simplifies calls to libc
36*344aa361SAndroid Build Coastguard Worker# and then inlines them.  The simplification pass does not set a calling
37*344aa361SAndroid Build Coastguard Worker# convention on the new call, leading to problems when inlining.
38*344aa361SAndroid Build Coastguard Worker# Avoid this bug by disabling LTO for libc.  See: b/161257552
39*344aa361SAndroid Build Coastguard WorkerMODULE_DISABLE_LTO := true
40*344aa361SAndroid Build Coastguard Worker
41*344aa361SAndroid Build Coastguard WorkerMUSL_DIR := external/trusty/musl
42*344aa361SAndroid Build Coastguard WorkerLK_DIR := $(LKROOT)
43*344aa361SAndroid Build Coastguard WorkerLIBC_TRUSTY_DIR := trusty/user/base/lib/libc-trusty
44*344aa361SAndroid Build Coastguard Worker
45*344aa361SAndroid Build Coastguard WorkerMODULE_INCLUDES += \
46*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/internal \
47*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/include \
48*344aa361SAndroid Build Coastguard Worker
49*344aa361SAndroid Build Coastguard WorkerMODULE_EXPORT_COMPILEFLAGS += \
50*344aa361SAndroid Build Coastguard Worker	-isystem $(MUSL_DIR)/arch/$(STANDARD_ARCH_NAME) \
51*344aa361SAndroid Build Coastguard Worker	-isystem $(MUSL_DIR)/arch/generic \
52*344aa361SAndroid Build Coastguard Worker	-isystem $(MUSL_DIR)/include \
53*344aa361SAndroid Build Coastguard Worker
54*344aa361SAndroid Build Coastguard WorkerMODULE_EXPORT_INCLUDES += \
55*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/include_common \
56*344aa361SAndroid Build Coastguard Worker
57*344aa361SAndroid Build Coastguard Worker# Musl is scrupulous about exposing prototypes and defines based on what
58*344aa361SAndroid Build Coastguard Worker# standard is requested. When compiling C++ code, however, Clang defines
59*344aa361SAndroid Build Coastguard Worker# _GNU_SOURCE because libcxx's header files depend on prototypes that are only
60*344aa361SAndroid Build Coastguard Worker# available with _GNU_SOURCE specified. To avoid skew where prototypes are
61*344aa361SAndroid Build Coastguard Worker# defined for C++ but not C, turn everything on always.
62*344aa361SAndroid Build Coastguard WorkerMODULE_EXPORT_COMPILEFLAGS += -D_ALL_SOURCE
63*344aa361SAndroid Build Coastguard Worker
64*344aa361SAndroid Build Coastguard Worker# Musl declares global variables with names like "index" that can conflict with
65*344aa361SAndroid Build Coastguard Worker# function names when _ALL_SOURCE is turned on. Compile Musl as it expects to be
66*344aa361SAndroid Build Coastguard Worker# compiled.
67*344aa361SAndroid Build Coastguard WorkerMODULE_COMPILEFLAGS += -U_ALL_SOURCE -D_XOPEN_SOURCE=700
68*344aa361SAndroid Build Coastguard Worker
69*344aa361SAndroid Build Coastguard Worker# Musl's source is not warning clean. Suppress warnings we know about.
70*344aa361SAndroid Build Coastguard WorkerMODULE_COMPILEFLAGS += \
71*344aa361SAndroid Build Coastguard Worker	-Wno-parentheses \
72*344aa361SAndroid Build Coastguard Worker	-Wno-sign-compare \
73*344aa361SAndroid Build Coastguard Worker	-Wno-incompatible-pointer-types-discards-qualifiers \
74*344aa361SAndroid Build Coastguard Worker	-Wno-string-plus-int \
75*344aa361SAndroid Build Coastguard Worker	-Wno-missing-braces \
76*344aa361SAndroid Build Coastguard Worker	-Wno-implicit-fallthrough \
77*344aa361SAndroid Build Coastguard Worker	-Wno-unused-but-set-variable \
78*344aa361SAndroid Build Coastguard Worker
79*344aa361SAndroid Build Coastguard Worker# Musl is generally not strict about its function prototypes.
80*344aa361SAndroid Build Coastguard Worker# This could be fixed, except for "main". The prototype for main is deliberately
81*344aa361SAndroid Build Coastguard Worker# ill-defined.
82*344aa361SAndroid Build Coastguard WorkerMODULE_CFLAGS += -Wno-strict-prototypes
83*344aa361SAndroid Build Coastguard Worker
84*344aa361SAndroid Build Coastguard Worker# Musl will do something like this:
85*344aa361SAndroid Build Coastguard Worker# weak_alias(a, b); weak_alias(b, c);
86*344aa361SAndroid Build Coastguard Worker# But it appears the second statement will get eagerly evaluated to:
87*344aa361SAndroid Build Coastguard Worker# weak_alias(a, c);
88*344aa361SAndroid Build Coastguard Worker# and overriding b will not affect c.  This is likely not intended behavior, but
89*344aa361SAndroid Build Coastguard Worker# it does not matter for us so ignore it.
90*344aa361SAndroid Build Coastguard WorkerMODULE_COMPILEFLAGS += \
91*344aa361SAndroid Build Coastguard Worker	-Wno-ignored-attributes \
92*344aa361SAndroid Build Coastguard Worker
93*344aa361SAndroid Build Coastguard Worker# The are compares that make sense in 64-bit but do not make sense in 32-bit.
94*344aa361SAndroid Build Coastguard WorkerMODULE_COMPILEFLAGS += \
95*344aa361SAndroid Build Coastguard Worker	-Wno-tautological-constant-compare
96*344aa361SAndroid Build Coastguard Worker
97*344aa361SAndroid Build Coastguard Worker# NOTE eabi_unwind_stubs.c because libgcc pulls in unwinding stuff.
98*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS := \
99*344aa361SAndroid Build Coastguard Worker	$(LOCAL_DIR)/abort.c \
100*344aa361SAndroid Build Coastguard Worker	$(LOCAL_DIR)/close.c \
101*344aa361SAndroid Build Coastguard Worker	$(LOCAL_DIR)/fflush.c \
102*344aa361SAndroid Build Coastguard Worker	$(LOCAL_DIR)/libc_state.c \
103*344aa361SAndroid Build Coastguard Worker	$(LOCAL_DIR)/writev.c \
104*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/atoi.c \
105*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/eabi.c \
106*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/eabi_unwind_stubs.c \
107*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/io_handle.c \
108*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/printf.c \
109*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/stdio.c \
110*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/strtol.c \
111*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/strtoll.c \
112*344aa361SAndroid Build Coastguard Worker
113*344aa361SAndroid Build Coastguard Worker# These sources are only necessary to support C++
114*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS += \
115*344aa361SAndroid Build Coastguard Worker	$(LIBC_TRUSTY_DIR)/locale_stubs.c \
116*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/atexit.c \
117*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/pure_virtual.cpp
118*344aa361SAndroid Build Coastguard Worker
119*344aa361SAndroid Build Coastguard WorkerMODULE_DEPS += \
120*344aa361SAndroid Build Coastguard Worker	$(LK_DIR)/lib/libc/rand
121*344aa361SAndroid Build Coastguard Worker
122*344aa361SAndroid Build Coastguard Worker# These stubs are only needed because binder uses libutils which uses pthreads mutex directly
123*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS += \
124*344aa361SAndroid Build Coastguard Worker	$(LIBC_TRUSTY_DIR)/pthreads.c
125*344aa361SAndroid Build Coastguard Worker
126*344aa361SAndroid Build Coastguard Worker# Musl
127*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS += \
128*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isalnum.c \
129*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isalpha.c \
130*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isascii.c \
131*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isblank.c \
132*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/iscntrl.c \
133*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isdigit.c \
134*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isgraph.c \
135*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/islower.c \
136*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isprint.c \
137*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/ispunct.c \
138*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isspace.c \
139*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isupper.c \
140*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/isxdigit.c \
141*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/toascii.c \
142*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/tolower.c \
143*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/toupper.c \
144*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/locale/c_locale.c \
145*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/abs.c \
146*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/bsearch.c \
147*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/div.c \
148*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/imaxabs.c \
149*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/imaxdiv.c \
150*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/labs.c \
151*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/ldiv.c \
152*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/llabs.c \
153*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/lldiv.c \
154*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdlib/qsort.c \
155*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/explicit_bzero.c \
156*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/bcmp.c \
157*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/memccpy.c \
158*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/memmem.c \
159*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/mempcpy.c \
160*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/memrchr.c \
161*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/stpcpy.c \
162*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/stpncpy.c \
163*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strcasecmp.c \
164*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strcasestr.c \
165*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strchrnul.c \
166*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strcspn.c \
167*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strerror_r.c \
168*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strncasecmp.c \
169*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strndup.c \
170*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strsep.c \
171*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strtok_r.c \
172*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/strverscmp.c \
173*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/string/swab.c \
174*344aa361SAndroid Build Coastguard Worker
175*344aa361SAndroid Build Coastguard Worker# We use the lk implementation of stdio but export
176*344aa361SAndroid Build Coastguard Worker# the musl stdio.h headers, which expose different
177*344aa361SAndroid Build Coastguard Worker# definitions of stdin/out/err. The files below contain
178*344aa361SAndroid Build Coastguard Worker# the musl definitions of those FILE structures, along
179*344aa361SAndroid Build Coastguard Worker# with their dependencies.
180*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS += \
181*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/stderr.c \
182*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/stdin.c \
183*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/stdout.c \
184*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/__stdio_close.c \
185*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/__stdio_read.c \
186*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/__stdio_write.c \
187*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/stdio/__stdio_seek.c \
188*344aa361SAndroid Build Coastguard Worker
189*344aa361SAndroid Build Coastguard Worker# These sources are only necessary to support C++
190*344aa361SAndroid Build Coastguard WorkerMODULE_SRCS += \
191*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/ctype/__ctype_get_mb_cur_max.c \
192*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/multibyte/internal.c \
193*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/multibyte/mbtowc.c \
194*344aa361SAndroid Build Coastguard Worker	$(MUSL_DIR)/src/multibyte/wcrtomb.c \
195*344aa361SAndroid Build Coastguard Worker
196*344aa361SAndroid Build Coastguard Workerinclude $(LK_DIR)/lib/libc/string/rules.mk
197*344aa361SAndroid Build Coastguard Worker
198*344aa361SAndroid Build Coastguard Workerinclude make/library.mk
199