blob: ccaa11dfe7da33aead400f4babf0144ad49b7b7e [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
Scott Wakelinga7812ae2016-10-17 10:03:36 +010077 if envTrue(ctx, "ART_USE_VIXL_ARM_BACKEND") {
78 // Used to enable the new VIXL-based ARM code generator.
79 cflags = append(cflags, "-DART_USE_VIXL_ARM_BACKEND=1")
80 asflags = append(asflags, "-DART_USE_VIXL_ARM_BACKEND=1")
81 }
82
Colin Cross1f7f3bd2016-07-27 10:12:38 -070083 return cflags, asflags
84}
85
Colin Crossbe332ed2016-09-21 13:23:53 -070086func debugFlags(ctx android.BaseContext) []string {
87 var cflags []string
88
89 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
90 cflags = append(cflags, opt)
91
92 return cflags
93}
94
Colin Cross1f7f3bd2016-07-27 10:12:38 -070095func deviceFlags(ctx android.BaseContext) []string {
96 var cflags []string
97 deviceFrameSizeLimit := 1736
98 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -070099 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700100 }
101 cflags = append(cflags,
102 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
103 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
104 )
105
106 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
107 if envTrue(ctx, "ART_TARGET_LINUX") {
108 cflags = append(cflags, "-DART_TARGET_LINUX")
109 } else {
110 cflags = append(cflags, "-DART_TARGET_ANDROID")
111 }
112 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
113 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
114 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
115 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
116
117 return cflags
118}
119
120func hostFlags(ctx android.BaseContext) []string {
121 var cflags []string
122 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700123 if len(ctx.AConfig().SanitizeHost()) > 0 {
124 // art/test/137-cfi/cfi.cc
125 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
126 hostFrameSizeLimit = 6400
127 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700128 cflags = append(cflags,
129 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
130 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
131 )
132
133 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
134 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
135 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
136 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
137 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
138
139 return cflags
140}
141
Colin Cross6e511782016-09-13 13:41:03 -0700142func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700143 type props struct {
144 Target struct {
145 Android struct {
146 Cflags []string
147 }
148 Host struct {
149 Cflags []string
150 }
151 }
152 Cflags []string
153 Asflags []string
154 }
155
156 p := &props{}
157 p.Cflags, p.Asflags = globalFlags(ctx)
158 p.Target.Android.Cflags = deviceFlags(ctx)
159 p.Target.Host.Cflags = hostFlags(ctx)
160 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700161}
Colin Cross6326d1b2016-09-06 10:24:28 -0700162
Colin Crossbe332ed2016-09-21 13:23:53 -0700163func debugDefaults(ctx android.LoadHookContext) {
164 type props struct {
165 Cflags []string
166 }
167
168 p := &props{}
169 p.Cflags = debugFlags(ctx)
170 ctx.AppendProperties(p)
171}
172
Colin Cross6e511782016-09-13 13:41:03 -0700173func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700174 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
175 if linker != "" {
176 type props struct {
177 DynamicLinker string
178 }
179
180 p := &props{}
181 p.DynamicLinker = linker
182 ctx.AppendProperties(p)
183 }
184}
185
Colin Cross6e511782016-09-13 13:41:03 -0700186func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700187 if envTrue(ctx, "HOST_PREFER_32_BIT") {
188 type props struct {
189 Target struct {
190 Host struct {
191 Compile_multilib string
192 }
193 }
194 }
195
196 p := &props{}
197 p.Target.Host.Compile_multilib = "prefer32"
198 ctx.AppendProperties(p)
199 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700200}
201
Colin Cross6e95dd52016-09-12 15:37:10 -0700202func testMap(config android.Config) map[string][]string {
203 return config.Once("artTests", func() interface{} {
204 return make(map[string][]string)
205 }).(map[string][]string)
206}
207
208func testInstall(ctx android.InstallHookContext) {
209 testMap := testMap(ctx.AConfig())
210
211 var name string
212 if ctx.Host() {
213 name = "host_"
214 } else {
215 name = "device_"
216 }
217 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
218
219 artTestMutex.Lock()
220 defer artTestMutex.Unlock()
221
222 tests := testMap[name]
223 tests = append(tests, ctx.Path().RelPathString())
224 testMap[name] = tests
225}
226
227var artTestMutex sync.Mutex
228
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700229func init() {
Colin Cross96548c92016-10-12 14:26:55 -0700230 android.RegisterModuleType("art_cc_library", artLibrary)
231 android.RegisterModuleType("art_cc_binary", artBinary)
232 android.RegisterModuleType("art_cc_test", artTest)
233 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
234 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
235 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
236 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700237}
238
239func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700240 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700241 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700242
243 return module, props
244}
245
Colin Crossbe332ed2016-09-21 13:23:53 -0700246func artDebugDefaultsFactory() (blueprint.Module, []interface{}) {
247 module, props := artDefaultsFactory()
248 android.AddLoadHook(module, debugDefaults)
249
250 return module, props
251}
252
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700253func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700254 c := &codegenProperties{}
255 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700256 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700257
258 return module, props
259}
260
261func artLibrary() (blueprint.Module, []interface{}) {
262 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
263 module, props := library.Init()
264
Colin Cross6e95dd52016-09-12 15:37:10 -0700265 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700266
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700267 return module, props
268}
269
Colin Cross123989f2016-09-07 14:12:50 -0700270func artBinary() (blueprint.Module, []interface{}) {
271 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
272 module, props := binary.Init()
273
Colin Cross6e511782016-09-13 13:41:03 -0700274 android.AddLoadHook(module, customLinker)
275 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700276 return module, props
277}
278
Colin Crossc7376e02016-09-08 12:52:18 -0700279func artTest() (blueprint.Module, []interface{}) {
280 test := cc.NewTest(android.HostAndDeviceSupported)
281 module, props := test.Init()
282
Colin Cross6e95dd52016-09-12 15:37:10 -0700283 props = installCodegenCustomizer(module, props, false)
284
Colin Cross6e511782016-09-13 13:41:03 -0700285 android.AddLoadHook(module, customLinker)
286 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700287 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700288 return module, props
289}
290
Colin Crossafd3c9e2016-09-16 13:47:21 -0700291func artTestLibrary() (blueprint.Module, []interface{}) {
292 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
293 module, props := test.Init()
294
295 props = installCodegenCustomizer(module, props, false)
296
297 android.AddLoadHook(module, prefer32Bit)
298 android.AddInstallHook(module, testInstall)
299 return module, props
300}
301
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700302func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
303 ret := ctx.AConfig().Getenv(key)
304 if ret == "" {
305 return defaultValue
306 }
307 return ret
308}
309
310func envTrue(ctx android.BaseContext, key string) bool {
311 return ctx.AConfig().Getenv(key) == "true"
312}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100313
314func envFalse(ctx android.BaseContext, key string) bool {
315 return ctx.AConfig().Getenv(key) == "false"
316}