blob: 61a97590eae84790070d3fed3cb64611145aea91 [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
Colin Cross1f7f3bd2016-07-27 10:12:38 -070079 return cflags, asflags
80}
81
Colin Crossbe332ed2016-09-21 13:23:53 -070082func debugFlags(ctx android.BaseContext) []string {
83 var cflags []string
84
85 opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2")
86 cflags = append(cflags, opt)
87
88 return cflags
89}
90
Colin Cross1f7f3bd2016-07-27 10:12:38 -070091func deviceFlags(ctx android.BaseContext) []string {
92 var cflags []string
93 deviceFrameSizeLimit := 1736
94 if len(ctx.AConfig().SanitizeDevice()) > 0 {
Vishwath Mohan1ecc4fe2016-09-26 09:22:42 -070095 deviceFrameSizeLimit = 7400
Colin Cross1f7f3bd2016-07-27 10:12:38 -070096 }
97 cflags = append(cflags,
98 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
99 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
100 )
101
102 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
103 if envTrue(ctx, "ART_TARGET_LINUX") {
104 cflags = append(cflags, "-DART_TARGET_LINUX")
105 } else {
106 cflags = append(cflags, "-DART_TARGET_ANDROID")
107 }
108 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
109 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
110 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
111 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
112
113 return cflags
114}
115
116func hostFlags(ctx android.BaseContext) []string {
117 var cflags []string
118 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700119 if len(ctx.AConfig().SanitizeHost()) > 0 {
120 // art/test/137-cfi/cfi.cc
121 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
122 hostFrameSizeLimit = 6400
123 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700124 cflags = append(cflags,
125 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
126 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
127 )
128
129 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
130 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
131 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
132 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
133 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
134
135 return cflags
136}
137
Colin Cross6e511782016-09-13 13:41:03 -0700138func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700139 type props struct {
140 Target struct {
141 Android struct {
142 Cflags []string
143 }
144 Host struct {
145 Cflags []string
146 }
147 }
148 Cflags []string
149 Asflags []string
150 }
151
152 p := &props{}
153 p.Cflags, p.Asflags = globalFlags(ctx)
154 p.Target.Android.Cflags = deviceFlags(ctx)
155 p.Target.Host.Cflags = hostFlags(ctx)
156 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700157}
Colin Cross6326d1b2016-09-06 10:24:28 -0700158
Colin Crossbe332ed2016-09-21 13:23:53 -0700159func debugDefaults(ctx android.LoadHookContext) {
160 type props struct {
161 Cflags []string
162 }
163
164 p := &props{}
165 p.Cflags = debugFlags(ctx)
166 ctx.AppendProperties(p)
167}
168
Colin Cross6e511782016-09-13 13:41:03 -0700169func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700170 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
171 if linker != "" {
172 type props struct {
173 DynamicLinker string
174 }
175
176 p := &props{}
177 p.DynamicLinker = linker
178 ctx.AppendProperties(p)
179 }
180}
181
Colin Cross6e511782016-09-13 13:41:03 -0700182func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700183 if envTrue(ctx, "HOST_PREFER_32_BIT") {
184 type props struct {
185 Target struct {
186 Host struct {
187 Compile_multilib string
188 }
189 }
190 }
191
192 p := &props{}
193 p.Target.Host.Compile_multilib = "prefer32"
194 ctx.AppendProperties(p)
195 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700196}
197
Colin Cross6e95dd52016-09-12 15:37:10 -0700198func testMap(config android.Config) map[string][]string {
199 return config.Once("artTests", func() interface{} {
200 return make(map[string][]string)
201 }).(map[string][]string)
202}
203
204func testInstall(ctx android.InstallHookContext) {
205 testMap := testMap(ctx.AConfig())
206
207 var name string
208 if ctx.Host() {
209 name = "host_"
210 } else {
211 name = "device_"
212 }
213 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
214
215 artTestMutex.Lock()
216 defer artTestMutex.Unlock()
217
218 tests := testMap[name]
219 tests = append(tests, ctx.Path().RelPathString())
220 testMap[name] = tests
221}
222
223var artTestMutex sync.Mutex
224
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700225func init() {
Colin Cross96548c92016-10-12 14:26:55 -0700226 android.RegisterModuleType("art_cc_library", artLibrary)
227 android.RegisterModuleType("art_cc_binary", artBinary)
228 android.RegisterModuleType("art_cc_test", artTest)
229 android.RegisterModuleType("art_cc_test_library", artTestLibrary)
230 android.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
231 android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
232 android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700233}
234
235func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700236 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700237 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700238
239 return module, props
240}
241
Colin Crossbe332ed2016-09-21 13:23:53 -0700242func artDebugDefaultsFactory() (blueprint.Module, []interface{}) {
243 module, props := artDefaultsFactory()
244 android.AddLoadHook(module, debugDefaults)
245
246 return module, props
247}
248
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700249func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700250 c := &codegenProperties{}
251 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700252 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700253
254 return module, props
255}
256
257func artLibrary() (blueprint.Module, []interface{}) {
Colin Cross97916262016-12-09 14:47:29 -0800258 library, _ := cc.NewLibrary(android.HostAndDeviceSupported)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700259 module, props := library.Init()
260
Colin Cross6e95dd52016-09-12 15:37:10 -0700261 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700262
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700263 return module, props
264}
265
Colin Cross123989f2016-09-07 14:12:50 -0700266func artBinary() (blueprint.Module, []interface{}) {
267 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
268 module, props := binary.Init()
269
Colin Cross6e511782016-09-13 13:41:03 -0700270 android.AddLoadHook(module, customLinker)
271 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700272 return module, props
273}
274
Colin Crossc7376e02016-09-08 12:52:18 -0700275func artTest() (blueprint.Module, []interface{}) {
276 test := cc.NewTest(android.HostAndDeviceSupported)
277 module, props := test.Init()
278
Colin Cross6e95dd52016-09-12 15:37:10 -0700279 props = installCodegenCustomizer(module, props, false)
280
Colin Cross6e511782016-09-13 13:41:03 -0700281 android.AddLoadHook(module, customLinker)
282 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700283 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700284 return module, props
285}
286
Colin Crossafd3c9e2016-09-16 13:47:21 -0700287func artTestLibrary() (blueprint.Module, []interface{}) {
288 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
289 module, props := test.Init()
290
291 props = installCodegenCustomizer(module, props, false)
292
293 android.AddLoadHook(module, prefer32Bit)
294 android.AddInstallHook(module, testInstall)
295 return module, props
296}
297
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700298func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
299 ret := ctx.AConfig().Getenv(key)
300 if ret == "" {
301 return defaultValue
302 }
303 return ret
304}
305
306func envTrue(ctx android.BaseContext, key string) bool {
307 return ctx.AConfig().Getenv(key) == "true"
308}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100309
310func envFalse(ctx android.BaseContext, key string) bool {
311 return ctx.AConfig().Getenv(key) == "false"
312}