1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16LOCAL_DIR := $(GET_LOCAL_DIR)
17
18MODULE := $(LOCAL_DIR)
19
20SCUDO_DIR := $(call FIND_EXTERNAL,scudo)
21
22MODULE_INCLUDES += \
23	$(LOCAL_DIR)/include \
24	$(SCUDO_DIR)/standalone \
25	$(SCUDO_DIR)/standalone/include \
26
27# These C/C++ flags are copied from the Android.bp build rules for Scudo.
28MODULE_CFLAGS += \
29	-fno-rtti \
30	-fno-stack-protector \
31	-fno-emulated-tls \
32	-Wno-unused-result \
33	-DSCUDO_MIN_ALIGNMENT_LOG=4 \
34
35MODULE_DEFINES += \
36	SCUDO_USE_CUSTOM_CONFIG=1
37
38MODULE_CPPFLAGS += \
39	-fno-exceptions \
40	-nostdinc++ \
41
42# Set the default options to Trusty-specific values:
43#   - allocation_ring_buffer_size=0
44#   	Limit the ring buffer size to 0 on Trusty (see aosp/2395872)
45MODULE_COMPILEFLAGS += \
46	-DSCUDO_DEFAULT_OPTIONS="allocation_ring_buffer_size=0"
47
48# scudo should be freestanding, but the rest of the app should not be.
49MODULE_COMPILEFLAGS += -ffreestanding
50
51# WARNING: while libstdc++-trusty continues to define `new` and `delete`,
52# it's possible that the symbols for those will be chosen over the ones
53# Scudo defines (also weak). None of the C++ sources below require any
54# STL headers but, if that changes, care will need to be taken to avoid
55# non-Scudo-defined `new` and `delete` from getting linked when STL headers
56# are desired.
57MODULE_SRCS += \
58	$(SCUDO_DIR)/standalone/checksum.cpp \
59	$(SCUDO_DIR)/standalone/common.cpp \
60	$(SCUDO_DIR)/standalone/crc32_hw.cpp \
61	$(SCUDO_DIR)/standalone/flags.cpp \
62	$(SCUDO_DIR)/standalone/flags_parser.cpp \
63	$(SCUDO_DIR)/standalone/mem_map.cpp \
64	$(SCUDO_DIR)/standalone/release.cpp \
65	$(SCUDO_DIR)/standalone/report.cpp \
66	$(SCUDO_DIR)/standalone/report_linux.cpp \
67	$(SCUDO_DIR)/standalone/string_utils.cpp \
68	$(SCUDO_DIR)/standalone/trusty.cpp \
69	$(LOCAL_DIR)/wrappers_c_copy.cpp \
70	$(LOCAL_DIR)/wrappers_cpp_copy.cpp \
71
72# Add dependency on syscall-stubs
73MODULE_LIBRARY_DEPS += trusty/user/base/lib/syscall-stubs
74
75# Add src dependency on syscall header to ensure it is generated before we try
76# to build
77include trusty/user/base/lib/syscall-stubs/common-inc.mk
78MODULE_SRCDEPS += $(SYSCALL_H)
79
80include make/library.mk
81