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	$(SCUDO_DIR)/standalone \
24	$(SCUDO_DIR)/standalone/include \
25
26# These C/C++ flags are copied from the Android.bp build rules for Scudo.
27MODULE_CFLAGS += \
28	-fno-rtti \
29	-fno-stack-protector \
30	-fno-emulated-tls \
31	-Wno-unused-result \
32	-DSCUDO_MIN_ALIGNMENT_LOG=4 \
33
34MODULE_CPPFLAGS += \
35	-fno-exceptions \
36	-nostdinc++ \
37
38# Set the default options to Trusty-specific values
39MODULE_COMPILEFLAGS += \
40	-DSCUDO_DEFAULT_OPTIONS="allocation_ring_buffer_size=0"
41
42# scudo should be freestanding, but the rest of the app should not be.
43MODULE_COMPILEFLAGS += -ffreestanding
44
45# WARNING: while libstdc++-trusty continues to define `new` and `delete`,
46# it's possible that the symbols for those will be chosen over the ones
47# Scudo defines (also weak). None of the C++ sources below require any
48# STL headers but, if that changes, care will need to be taken to avoid
49# non-Scudo-defined `new` and `delete` from getting linked when STL headers
50# are desired.
51MODULE_SRCS += \
52	$(SCUDO_DIR)/standalone/checksum.cpp \
53	$(SCUDO_DIR)/standalone/common.cpp \
54	$(SCUDO_DIR)/standalone/crc32_hw.cpp \
55	$(SCUDO_DIR)/standalone/flags.cpp \
56	$(SCUDO_DIR)/standalone/flags_parser.cpp \
57	$(SCUDO_DIR)/standalone/mem_map.cpp \
58	$(SCUDO_DIR)/standalone/release.cpp \
59	$(SCUDO_DIR)/standalone/report.cpp \
60	$(SCUDO_DIR)/standalone/report_linux.cpp \
61	$(SCUDO_DIR)/standalone/string_utils.cpp \
62	$(SCUDO_DIR)/standalone/trusty.cpp \
63	$(SCUDO_DIR)/standalone/wrappers_c.cpp \
64	$(SCUDO_DIR)/standalone/wrappers_cpp.cpp \
65
66# Add dependency on syscall-stubs
67MODULE_LIBRARY_DEPS += trusty/user/base/lib/syscall-stubs
68
69# Add src dependency on syscall header to ensure it is generated before we try
70# to build
71include trusty/user/base/lib/syscall-stubs/common-inc.mk
72MODULE_SRCDEPS += $(SYSCALL_H)
73
74include make/library.mk
75