blob: b826538696b9530453b3a91aa635279e2258cbc0 [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 (
18 "android/soong"
19 "android/soong/android"
20 "android/soong/cc"
21 "fmt"
Colin Cross6e95dd52016-09-12 15:37:10 -070022 "sync"
Colin Cross1f7f3bd2016-07-27 10:12:38 -070023
24 "github.com/google/blueprint"
25)
26
27var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"}
28
29func globalFlags(ctx android.BaseContext) ([]string, []string) {
30 var cflags []string
31 var asflags []string
32
Colin Crossbe332ed2016-09-21 13:23:53 -070033 opt := envDefault(ctx, "ART_NDEBUG_OPT_FLAG", "-O3")
34 cflags = append(cflags, opt)
35
Colin Cross1f7f3bd2016-07-27 10:12:38 -070036 tlab := false
37
38 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
39
40 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
41 gcType = "SS"
42 tlab = true
43 }
44
45 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
46 if tlab {
47 cflags = append(cflags, "-DART_USE_TLAB=1")
48 }
49
David Brazdil7b49e6c2016-09-01 11:06:18 +010050 if !envFalse(ctx, "ART_ENABLE_VDEX") {
51 cflags = append(cflags, "-DART_ENABLE_VDEX")
52 }
53
Colin Cross1f7f3bd2016-07-27 10:12:38 -070054 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
55 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
56
57 if envTrue(ctx, "ART_HEAP_POISONING") {
58 cflags = append(cflags, "-DART_HEAP_POISONING=1")
59 asflags = append(asflags, "-DART_HEAP_POISONING=1")
60 }
61
62 if envTrue(ctx, "ART_USE_READ_BARRIER") {
63 // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP.
64 // The default is BAKER.
65 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
66 cflags = append(cflags,
67 "-DART_USE_READ_BARRIER=1",
68 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
69 asflags = append(asflags,
70 "-DART_USE_READ_BARRIER=1",
71 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
72
73 // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major
74 // slowdown with the read barrier config. b/26744236.
75 cflags = append(cflags, "-fstack-protector")
76 }
77
Colin Cross1f7f3bd2016-07-27 10:12:38 -070078 return cflags, asflags
79}
80
Colin Crossbe332ed2016-09-21 13:23:53 -070081func debugFlags(ctx android.BaseContext) []string {
82 var cflags []string
83
84 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
85 cflags = append(cflags, opt)
86
87 return cflags
88}
89
Colin Cross1f7f3bd2016-07-27 10:12:38 -070090func deviceFlags(ctx android.BaseContext) []string {
91 var cflags []string
92 deviceFrameSizeLimit := 1736
93 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -070094 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -070095 }
96 cflags = append(cflags,
97 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
98 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
99 )
100
101 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
102 if envTrue(ctx, "ART_TARGET_LINUX") {
103 cflags = append(cflags, "-DART_TARGET_LINUX")
104 } else {
105 cflags = append(cflags, "-DART_TARGET_ANDROID")
106 }
107 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
108 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
109 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
110 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
111
112 return cflags
113}
114
115func hostFlags(ctx android.BaseContext) []string {
116 var cflags []string
117 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700118 if len(ctx.AConfig().SanitizeHost()) > 0 {
119 // art/test/137-cfi/cfi.cc
120 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
121 hostFrameSizeLimit = 6400
122 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700123 cflags = append(cflags,
124 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
125 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
126 )
127
128 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
129 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
130 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
131 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
132 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
133
134 return cflags
135}
136
Colin Cross6e511782016-09-13 13:41:03 -0700137func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700138 type props struct {
139 Target struct {
140 Android struct {
141 Cflags []string
142 }
143 Host struct {
144 Cflags []string
145 }
146 }
147 Cflags []string
148 Asflags []string
149 }
150
151 p := &props{}
152 p.Cflags, p.Asflags = globalFlags(ctx)
153 p.Target.Android.Cflags = deviceFlags(ctx)
154 p.Target.Host.Cflags = hostFlags(ctx)
155 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700156}
Colin Cross6326d1b2016-09-06 10:24:28 -0700157
Colin Crossbe332ed2016-09-21 13:23:53 -0700158func debugDefaults(ctx android.LoadHookContext) {
159 type props struct {
160 Cflags []string
161 }
162
163 p := &props{}
164 p.Cflags = debugFlags(ctx)
165 ctx.AppendProperties(p)
166}
167
Colin Cross6e511782016-09-13 13:41:03 -0700168func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700169 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
170 if linker != "" {
171 type props struct {
172 DynamicLinker string
173 }
174
175 p := &props{}
176 p.DynamicLinker = linker
177 ctx.AppendProperties(p)
178 }
179}
180
Colin Cross6e511782016-09-13 13:41:03 -0700181func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700182 if envTrue(ctx, "HOST_PREFER_32_BIT") {
183 type props struct {
184 Target struct {
185 Host struct {
186 Compile_multilib string
187 }
188 }
189 }
190
191 p := &props{}
192 p.Target.Host.Compile_multilib = "prefer32"
193 ctx.AppendProperties(p)
194 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700195}
196
Colin Cross6e95dd52016-09-12 15:37:10 -0700197func testMap(config android.Config) map[string][]string {
198 return config.Once("artTests", func() interface{} {
199 return make(map[string][]string)
200 }).(map[string][]string)
201}
202
203func testInstall(ctx android.InstallHookContext) {
204 testMap := testMap(ctx.AConfig())
205
206 var name string
207 if ctx.Host() {
208 name = "host_"
209 } else {
210 name = "device_"
211 }
212 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
213
214 artTestMutex.Lock()
215 defer artTestMutex.Unlock()
216
217 tests := testMap[name]
218 tests = append(tests, ctx.Path().RelPathString())
219 testMap[name] = tests
220}
221
222var artTestMutex sync.Mutex
223
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700224func init() {
225 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700226 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700227 soong.RegisterModuleType("art_cc_test", artTest)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700228 soong.RegisterModuleType("art_cc_test_library", artTestLibrary)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700229 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
230 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
Colin Crossbe332ed2016-09-21 13:23:53 -0700231 soong.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700232}
233
234func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700235 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700236 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700237
238 return module, props
239}
240
Colin Crossbe332ed2016-09-21 13:23:53 -0700241func artDebugDefaultsFactory() (blueprint.Module, []interface{}) {
242 module, props := artDefaultsFactory()
243 android.AddLoadHook(module, debugDefaults)
244
245 return module, props
246}
247
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700248func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700249 c := &codegenProperties{}
250 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700251 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700252
253 return module, props
254}
255
256func artLibrary() (blueprint.Module, []interface{}) {
257 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
258 module, props := library.Init()
259
Colin Cross6e95dd52016-09-12 15:37:10 -0700260 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700261
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700262 return module, props
263}
264
Colin Cross123989f2016-09-07 14:12:50 -0700265func artBinary() (blueprint.Module, []interface{}) {
266 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
267 module, props := binary.Init()
268
Colin Cross6e511782016-09-13 13:41:03 -0700269 android.AddLoadHook(module, customLinker)
270 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700271 return module, props
272}
273
Colin Crossc7376e02016-09-08 12:52:18 -0700274func artTest() (blueprint.Module, []interface{}) {
275 test := cc.NewTest(android.HostAndDeviceSupported)
276 module, props := test.Init()
277
Colin Cross6e95dd52016-09-12 15:37:10 -0700278 props = installCodegenCustomizer(module, props, false)
279
Colin Cross6e511782016-09-13 13:41:03 -0700280 android.AddLoadHook(module, customLinker)
281 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700282 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700283 return module, props
284}
285
Colin Crossafd3c9e2016-09-16 13:47:21 -0700286func artTestLibrary() (blueprint.Module, []interface{}) {
287 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
288 module, props := test.Init()
289
290 props = installCodegenCustomizer(module, props, false)
291
292 android.AddLoadHook(module, prefer32Bit)
293 android.AddInstallHook(module, testInstall)
294 return module, props
295}
296
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700297func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
298 ret := ctx.AConfig().Getenv(key)
299 if ret == "" {
300 return defaultValue
301 }
302 return ret
303}
304
305func envTrue(ctx android.BaseContext, key string) bool {
306 return ctx.AConfig().Getenv(key) == "true"
307}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100308
309func envFalse(ctx android.BaseContext, key string) bool {
310 return ctx.AConfig().Getenv(key) == "false"
311}