blob: 1164cbc553646081eb2f57c44756266eb73f115f [file] [log] [blame]
Colin Cross1f7f3bd2016-07-27 10:12:38 -07001// Copyright (C) 2016 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
15package art
16
17import (
Colin Cross1f7f3bd2016-07-27 10:12:38 -070018 "android/soong/android"
19 "android/soong/cc"
20 "fmt"
Colin Cross6e95dd52016-09-12 15:37:10 -070021 "sync"
Colin Cross1f7f3bd2016-07-27 10:12:38 -070022
23 "github.com/google/blueprint"
24)
25
26var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"}
27
28func globalFlags(ctx android.BaseContext) ([]string, []string) {
29 var cflags []string
30 var asflags []string
31
Colin Crossbe332ed2016-09-21 13:23:53 -070032 opt := envDefault(ctx, "ART_NDEBUG_OPT_FLAG", "-O3")
33 cflags = append(cflags, opt)
34
Colin Cross1f7f3bd2016-07-27 10:12:38 -070035 tlab := false
36
37 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
38
39 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
40 gcType = "SS"
41 tlab = true
42 }
43
44 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
45 if tlab {
46 cflags = append(cflags, "-DART_USE_TLAB=1")
47 }
48
David Brazdil7b49e6c2016-09-01 11:06:18 +010049 if !envFalse(ctx, "ART_ENABLE_VDEX") {
50 cflags = append(cflags, "-DART_ENABLE_VDEX")
51 }
52
Colin Cross1f7f3bd2016-07-27 10:12:38 -070053 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
54 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
55
56 if envTrue(ctx, "ART_HEAP_POISONING") {
57 cflags = append(cflags, "-DART_HEAP_POISONING=1")
58 asflags = append(asflags, "-DART_HEAP_POISONING=1")
59 }
60
61 if envTrue(ctx, "ART_USE_READ_BARRIER") {
62 // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP.
63 // The default is BAKER.
64 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
65 cflags = append(cflags,
66 "-DART_USE_READ_BARRIER=1",
67 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
68 asflags = append(asflags,
69 "-DART_USE_READ_BARRIER=1",
70 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
71
72 // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major
73 // slowdown with the read barrier config. b/26744236.
74 cflags = append(cflags, "-fstack-protector")
75 }
76
Colin Cross1f7f3bd2016-07-27 10:12:38 -070077 return cflags, asflags
78}
79
Colin Crossbe332ed2016-09-21 13:23:53 -070080func debugFlags(ctx android.BaseContext) []string {
81 var cflags []string
82
83 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
84 cflags = append(cflags, opt)
85
86 return cflags
87}
88
Colin Cross1f7f3bd2016-07-27 10:12:38 -070089func deviceFlags(ctx android.BaseContext) []string {
90 var cflags []string
91 deviceFrameSizeLimit := 1736
92 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -070093 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -070094 }
95 cflags = append(cflags,
96 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
97 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
98 )
99
100 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
101 if envTrue(ctx, "ART_TARGET_LINUX") {
102 cflags = append(cflags, "-DART_TARGET_LINUX")
103 } else {
104 cflags = append(cflags, "-DART_TARGET_ANDROID")
105 }
106 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
107 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
108 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
109 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
110
111 return cflags
112}
113
114func hostFlags(ctx android.BaseContext) []string {
115 var cflags []string
116 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700117 if len(ctx.AConfig().SanitizeHost()) > 0 {
118 // art/test/137-cfi/cfi.cc
119 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
120 hostFrameSizeLimit = 6400
121 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700122 cflags = append(cflags,
123 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
124 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
125 )
126
127 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
128 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
129 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
130 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
131 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
132
133 return cflags
134}
135
Colin Cross6e511782016-09-13 13:41:03 -0700136func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700137 type props struct {
138 Target struct {
139 Android struct {
140 Cflags []string
141 }
142 Host struct {
143 Cflags []string
144 }
145 }
146 Cflags []string
147 Asflags []string
148 }
149
150 p := &props{}
151 p.Cflags, p.Asflags = globalFlags(ctx)
152 p.Target.Android.Cflags = deviceFlags(ctx)
153 p.Target.Host.Cflags = hostFlags(ctx)
154 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700155}
Colin Cross6326d1b2016-09-06 10:24:28 -0700156
Colin Crossbe332ed2016-09-21 13:23:53 -0700157func debugDefaults(ctx android.LoadHookContext) {
158 type props struct {
159 Cflags []string
160 }
161
162 p := &props{}
163 p.Cflags = debugFlags(ctx)
164 ctx.AppendProperties(p)
165}
166
Colin Cross6e511782016-09-13 13:41:03 -0700167func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700168 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
169 if linker != "" {
170 type props struct {
171 DynamicLinker string
172 }
173
174 p := &props{}
175 p.DynamicLinker = linker
176 ctx.AppendProperties(p)
177 }
178}
179
Colin Cross6e511782016-09-13 13:41:03 -0700180func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700181 if envTrue(ctx, "HOST_PREFER_32_BIT") {
182 type props struct {
183 Target struct {
184 Host struct {
185 Compile_multilib string
186 }
187 }
188 }
189
190 p := &props{}
191 p.Target.Host.Compile_multilib = "prefer32"
192 ctx.AppendProperties(p)
193 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700194}
195
Colin Cross6e95dd52016-09-12 15:37:10 -0700196func testMap(config android.Config) map[string][]string {
197 return config.Once("artTests", func() interface{} {
198 return make(map[string][]string)
199 }).(map[string][]string)
200}
201
202func testInstall(ctx android.InstallHookContext) {
203 testMap := testMap(ctx.AConfig())
204
205 var name string
206 if ctx.Host() {
207 name = "host_"
208 } else {
209 name = "device_"
210 }
211 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
212
213 artTestMutex.Lock()
214 defer artTestMutex.Unlock()
215
216 tests := testMap[name]
217 tests = append(tests, ctx.Path().RelPathString())
218 testMap[name] = tests
219}
220
221var artTestMutex sync.Mutex
222
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700223func init() {
Colin Cross96548c92016-10-12 14:26:55 -0700224 android.RegisterModuleType("art_cc_library", artLibrary)
225 android.RegisterModuleType("art_cc_binary", artBinary)
226 android.RegisterModuleType("art_cc_test", artTest)
227 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
228 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
229 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
230 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700231}
232
233func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700234 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700235 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700236
237 return module, props
238}
239
Colin Crossbe332ed2016-09-21 13:23:53 -0700240func artDebugDefaultsFactory() (blueprint.Module, []interface{}) {
241 module, props := artDefaultsFactory()
242 android.AddLoadHook(module, debugDefaults)
243
244 return module, props
245}
246
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700247func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700248 c := &codegenProperties{}
249 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700250 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700251
252 return module, props
253}
254
255func artLibrary() (blueprint.Module, []interface{}) {
256 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
257 module, props := library.Init()
258
Colin Cross6e95dd52016-09-12 15:37:10 -0700259 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700260
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700261 return module, props
262}
263
Colin Cross123989f2016-09-07 14:12:50 -0700264func artBinary() (blueprint.Module, []interface{}) {
265 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
266 module, props := binary.Init()
267
Colin Cross6e511782016-09-13 13:41:03 -0700268 android.AddLoadHook(module, customLinker)
269 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700270 return module, props
271}
272
Colin Crossc7376e02016-09-08 12:52:18 -0700273func artTest() (blueprint.Module, []interface{}) {
274 test := cc.NewTest(android.HostAndDeviceSupported)
275 module, props := test.Init()
276
Colin Cross6e95dd52016-09-12 15:37:10 -0700277 props = installCodegenCustomizer(module, props, false)
278
Colin Cross6e511782016-09-13 13:41:03 -0700279 android.AddLoadHook(module, customLinker)
280 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700281 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700282 return module, props
283}
284
Colin Crossafd3c9e2016-09-16 13:47:21 -0700285func artTestLibrary() (blueprint.Module, []interface{}) {
286 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
287 module, props := test.Init()
288
289 props = installCodegenCustomizer(module, props, false)
290
291 android.AddLoadHook(module, prefer32Bit)
292 android.AddInstallHook(module, testInstall)
293 return module, props
294}
295
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700296func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
297 ret := ctx.AConfig().Getenv(key)
298 if ret == "" {
299 return defaultValue
300 }
301 return ret
302}
303
304func envTrue(ctx android.BaseContext, key string) bool {
305 return ctx.AConfig().Getenv(key) == "true"
306}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100307
308func envFalse(ctx android.BaseContext, key string) bool {
309 return ctx.AConfig().Getenv(key) == "false"
310}