blob: 6dca793f297b75192b1c50be53d5647df1c0c2f5 [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
Hiroshi Yamauchida75ad72017-01-24 11:06:47 -080061 if !envFalse(ctx, "ART_USE_READ_BARRIER") && ctx.AConfig().ArtUseReadBarrier() {
Roland Levillainb81e9e92017-04-20 17:35:32 +010062 // Used to change the read barrier type. Valid values are BAKER, BROOKS,
63 // TABLELOOKUP. The default is BAKER.
Colin Cross1f7f3bd2016-07-27 10:12:38 -070064 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")
Colin Cross1f7f3bd2016-07-27 10:12:38 -070071 }
72
Nicolas Geoffray467d94a2017-03-16 10:24:17 +000073 if envTrue(ctx, "ART_USE_OLD_ARM_BACKEND") {
74 // Used to enable the old, pre-VIXL ARM code generator.
75 cflags = append(cflags, "-DART_USE_OLD_ARM_BACKEND=1")
76 asflags = append(asflags, "-DART_USE_OLD_ARM_BACKEND=1")
Scott Wakelinga7812ae2016-10-17 10:03:36 +010077 }
78
Andreas Gampebc9f10c2017-05-19 08:28:06 -070079 cflags = append(cflags,
80 "-DART_STACK_OVERFLOW_GAP_arm=8192",
81 "-DART_STACK_OVERFLOW_GAP_arm64=8192",
82 "-DART_STACK_OVERFLOW_GAP_mips=16384",
83 "-DART_STACK_OVERFLOW_GAP_mips64=16384",
84 "-DART_STACK_OVERFLOW_GAP_x86=8192",
85 "-DART_STACK_OVERFLOW_GAP_x86_64=8192")
86
Colin Cross1f7f3bd2016-07-27 10:12:38 -070087 return cflags, asflags
88}
89
Colin Crossbe332ed2016-09-21 13:23:53 -070090func debugFlags(ctx android.BaseContext) []string {
91 var cflags []string
92
93 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
94 cflags = append(cflags, opt)
95
96 return cflags
97}
98
Colin Cross1f7f3bd2016-07-27 10:12:38 -070099func deviceFlags(ctx android.BaseContext) []string {
100 var cflags []string
101 deviceFrameSizeLimit := 1736
102 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -0700103 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700104 }
105 cflags = append(cflags,
106 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
107 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
108 )
109
110 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
111 if envTrue(ctx, "ART_TARGET_LINUX") {
112 cflags = append(cflags, "-DART_TARGET_LINUX")
113 } else {
114 cflags = append(cflags, "-DART_TARGET_ANDROID")
115 }
116 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
117 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
118 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
119 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
120
121 return cflags
122}
123
124func hostFlags(ctx android.BaseContext) []string {
125 var cflags []string
126 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700127 if len(ctx.AConfig().SanitizeHost()) > 0 {
128 // art/test/137-cfi/cfi.cc
129 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
130 hostFrameSizeLimit = 6400
131 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700132 cflags = append(cflags,
133 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
134 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
135 )
136
137 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
138 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
139 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
140 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
141 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
142
143 return cflags
144}
145
Colin Cross6e511782016-09-13 13:41:03 -0700146func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700147 type props struct {
148 Target struct {
149 Android struct {
150 Cflags []string
151 }
152 Host struct {
153 Cflags []string
154 }
155 }
156 Cflags []string
157 Asflags []string
158 }
159
160 p := &props{}
161 p.Cflags, p.Asflags = globalFlags(ctx)
162 p.Target.Android.Cflags = deviceFlags(ctx)
163 p.Target.Host.Cflags = hostFlags(ctx)
164 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700165}
Colin Cross6326d1b2016-09-06 10:24:28 -0700166
Colin Crossbe332ed2016-09-21 13:23:53 -0700167func debugDefaults(ctx android.LoadHookContext) {
168 type props struct {
169 Cflags []string
170 }
171
172 p := &props{}
173 p.Cflags = debugFlags(ctx)
174 ctx.AppendProperties(p)
175}
176
Colin Cross6e511782016-09-13 13:41:03 -0700177func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700178 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
179 if linker != "" {
180 type props struct {
181 DynamicLinker string
182 }
183
184 p := &props{}
185 p.DynamicLinker = linker
186 ctx.AppendProperties(p)
187 }
188}
189
Colin Cross6e511782016-09-13 13:41:03 -0700190func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700191 if envTrue(ctx, "HOST_PREFER_32_BIT") {
192 type props struct {
193 Target struct {
194 Host struct {
195 Compile_multilib string
196 }
197 }
198 }
199
200 p := &props{}
201 p.Target.Host.Compile_multilib = "prefer32"
202 ctx.AppendProperties(p)
203 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700204}
205
Colin Cross6e95dd52016-09-12 15:37:10 -0700206func testMap(config android.Config) map[string][]string {
207 return config.Once("artTests", func() interface{} {
208 return make(map[string][]string)
209 }).(map[string][]string)
210}
211
212func testInstall(ctx android.InstallHookContext) {
213 testMap := testMap(ctx.AConfig())
214
215 var name string
216 if ctx.Host() {
217 name = "host_"
218 } else {
219 name = "device_"
220 }
221 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
222
223 artTestMutex.Lock()
224 defer artTestMutex.Unlock()
225
226 tests := testMap[name]
227 tests = append(tests, ctx.Path().RelPathString())
228 testMap[name] = tests
229}
230
231var artTestMutex sync.Mutex
232
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700233func init() {
Colin Cross96548c92016-10-12 14:26:55 -0700234 android.RegisterModuleType("art_cc_library", artLibrary)
235 android.RegisterModuleType("art_cc_binary", artBinary)
236 android.RegisterModuleType("art_cc_test", artTest)
237 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
238 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
239 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
240 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700241}
242
243func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700244 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700245 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700246
247 return module, props
248}
249
Colin Crossbe332ed2016-09-21 13:23:53 -0700250func artDebugDefaultsFactory() (blueprint.Module, []interface{}) {
251 module, props := artDefaultsFactory()
252 android.AddLoadHook(module, debugDefaults)
253
254 return module, props
255}
256
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700257func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700258 c := &codegenProperties{}
259 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700260 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700261
262 return module, props
263}
264
265func artLibrary() (blueprint.Module, []interface{}) {
Colin Cross97916262016-12-09 14:47:29 -0800266 library, _ := cc.NewLibrary(android.HostAndDeviceSupported)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700267 module, props := library.Init()
268
Colin Cross6e95dd52016-09-12 15:37:10 -0700269 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700270
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700271 return module, props
272}
273
Colin Cross123989f2016-09-07 14:12:50 -0700274func artBinary() (blueprint.Module, []interface{}) {
275 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
276 module, props := binary.Init()
277
Colin Cross6e511782016-09-13 13:41:03 -0700278 android.AddLoadHook(module, customLinker)
279 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700280 return module, props
281}
282
Colin Crossc7376e02016-09-08 12:52:18 -0700283func artTest() (blueprint.Module, []interface{}) {
284 test := cc.NewTest(android.HostAndDeviceSupported)
285 module, props := test.Init()
286
Colin Cross6e95dd52016-09-12 15:37:10 -0700287 props = installCodegenCustomizer(module, props, false)
288
Colin Cross6e511782016-09-13 13:41:03 -0700289 android.AddLoadHook(module, customLinker)
290 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700291 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700292 return module, props
293}
294
Colin Crossafd3c9e2016-09-16 13:47:21 -0700295func artTestLibrary() (blueprint.Module, []interface{}) {
296 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
297 module, props := test.Init()
298
299 props = installCodegenCustomizer(module, props, false)
300
301 android.AddLoadHook(module, prefer32Bit)
302 android.AddInstallHook(module, testInstall)
303 return module, props
304}
305
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700306func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
307 ret := ctx.AConfig().Getenv(key)
308 if ret == "" {
309 return defaultValue
310 }
311 return ret
312}
313
314func envTrue(ctx android.BaseContext, key string) bool {
315 return ctx.AConfig().Getenv(key) == "true"
316}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100317
318func envFalse(ctx android.BaseContext, key string) bool {
319 return ctx.AConfig().Getenv(key) == "false"
320}