1//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16//
17
18ubsan_rtl_files = [
19    "ubsan_diag.cc",
20    "ubsan_init.cc",
21    "ubsan_flags.cc",
22    "ubsan_handlers.cc",
23    "ubsan_value.cc",
24]
25
26ubsan_cxx_rtl_files = [
27    "ubsan_handlers_cxx.cc",
28    "ubsan_type_hash.cc",
29    "ubsan_type_hash_itanium.cc",
30    "ubsan_type_hash_win.cc",
31]
32
33ubsan_rtl_cppflags = [
34    "-fvisibility=hidden",
35    "-fno-exceptions",
36    "-std=c++11",
37    "-Wall",
38    "-Werror",
39    "-Wno-unused-parameter",
40    "-Wno-non-virtual-dtor",
41    "-DUBSAN_CAN_USE_CXXABI",
42]
43
44ubsan_rtl_c_includes = ["external/compiler-rt/lib"]
45
46cc_library_static {
47    name: "libubsan",
48    host_supported: true,
49
50    include_dirs: ubsan_rtl_c_includes,
51    cppflags: ubsan_rtl_cppflags,
52    srcs: ubsan_rtl_files,
53    sdk_version: "19",
54    stl: "none",
55    sanitize: {
56        never: true,
57    },
58    compile_multilib: "both",
59    target: {
60        host: {
61            cflags: ["-fno-rtti"],
62        },
63    },
64}
65
66cc_library_static {
67    name: "libubsan_cxx",
68    host_supported: true,
69
70    include_dirs: ubsan_rtl_c_includes,
71    cppflags: ubsan_rtl_cppflags,
72    rtti: true,
73    srcs: ubsan_cxx_rtl_files,
74    sdk_version: "19",
75    sanitize: {
76        never: true,
77    },
78    compile_multilib: "both",
79}
80
81cc_defaults {
82    name: "libclang_rt_ubsan_defaults",
83
84    include_dirs: [
85        "external/compiler-rt/lib",
86        "external/compiler-rt/include",
87    ],
88    static_libs: [
89        "libsan",
90    ],
91    whole_static_libs: [
92        "libubsan",
93        "libubsan_cxx",
94    ],
95    shared_libs: [
96        "liblog",
97        "libdl",
98    ],
99    clang: true,
100    sanitize: {
101        never: true,
102    },
103    // _cxx bits (vptr-sanitizer and cfi) need dynamic_cast<>
104    stl: "c++_static",
105    sdk_version: "19",
106    enabled: false,
107}
108
109// Disable libubsan_standalone prebuilts in aosp/master until soong has a build
110// option to pick a prebuilt or compile/build a module.
111//
112// cc_library_shared {
113//     name: "libclang_rt.ubsan_standalone-arm-android",
114//     defaults: ["libclang_rt_ubsan_defaults"],
115//     arch: {
116//         arm: {
117//             enabled: true,
118//         },
119//     },
120// }
121//
122// cc_library_shared {
123//     name: "libclang_rt.ubsan_standalone-aarch64-android",
124//     defaults: ["libclang_rt_ubsan_defaults"],
125//     arch: {
126//         arm64: {
127//             enabled: true,
128//         },
129//     },
130// }
131//
132// cc_library_shared {
133//     name: "libclang_rt.ubsan_standalone-i686-android",
134//     defaults: ["libclang_rt_ubsan_defaults"],
135//     arch: {
136//         x86: {
137//             enabled: true,
138//         },
139//     },
140// }
141//
142// cc_library_shared {
143//     name: "libclang_rt.ubsan_standalone-x86_64-android",
144//     defaults: ["libclang_rt_ubsan_defaults"],
145//     arch: {
146//         x86_64: {
147//             enabled: true,
148//         },
149//     },
150// }
151//
152// cc_library_shared {
153//     name: "libclang_rt.ubsan_standalone-mips-android",
154//     defaults: ["libclang_rt_ubsan_defaults"],
155//     arch: {
156//         mips: {
157//             enabled: true,
158//         },
159//     },
160// }
161//
162// cc_library_shared {
163//     name: "libclang_rt.ubsan_standalone-mips64-android",
164//     defaults: ["libclang_rt_ubsan_defaults"],
165//     arch: {
166//         mips64: {
167//             enabled: true,
168//         },
169//     },
170// }
171
172//###############################################################################
173// Host modules
174
175cc_library_host_static {
176    name: "libubsan_standalone",
177
178    include_dirs: ubsan_rtl_c_includes,
179    cppflags: ubsan_rtl_cppflags + ["-fno-rtti"],
180    srcs: ubsan_rtl_files,
181    whole_static_libs: ["libsan"],
182    stl: "none",
183    sanitize: {
184        never: true,
185    },
186    compile_multilib: "both",
187    target: {
188        darwin: {
189            enabled: false,
190        },
191    },
192}
193
194cc_library_host_static {
195    name: "libubsan_standalone_cxx",
196
197    include_dirs: ubsan_rtl_c_includes,
198    cppflags: ubsan_rtl_cppflags,
199    srcs: ubsan_cxx_rtl_files,
200    sanitize: {
201        never: true,
202    },
203    compile_multilib: "both",
204    target: {
205        darwin: {
206            enabled: false,
207        },
208    },
209}
210