blob: 8266b087c509f539bba597b3ac6d2313610a32c1 [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
33 tlab := false
34
35 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
36
37 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
38 gcType = "SS"
39 tlab = true
40 }
41
42 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
43 if tlab {
44 cflags = append(cflags, "-DART_USE_TLAB=1")
45 }
46
David Brazdil7b49e6c2016-09-01 11:06:18 +010047 if !envFalse(ctx, "ART_ENABLE_VDEX") {
48 cflags = append(cflags, "-DART_ENABLE_VDEX")
49 }
50
Colin Cross1f7f3bd2016-07-27 10:12:38 -070051 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
52 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
53
54 if envTrue(ctx, "ART_HEAP_POISONING") {
55 cflags = append(cflags, "-DART_HEAP_POISONING=1")
56 asflags = append(asflags, "-DART_HEAP_POISONING=1")
57 }
58
59 if envTrue(ctx, "ART_USE_READ_BARRIER") {
60 // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP.
61 // The default is BAKER.
62 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
63 cflags = append(cflags,
64 "-DART_USE_READ_BARRIER=1",
65 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
66 asflags = append(asflags,
67 "-DART_USE_READ_BARRIER=1",
68 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
69
70 // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major
71 // slowdown with the read barrier config. b/26744236.
72 cflags = append(cflags, "-fstack-protector")
73 }
74
Roland Levillain04147ef2016-09-06 11:09:41 +010075 // Are additional statically-linked ART host binaries
76 // (dex2oats, oatdumps, etc.) getting built?
77 if envTrue(ctx, "ART_BUILD_HOST_STATIC") {
78 cflags = append(cflags, "-DART_BUILD_HOST_STATIC=1")
79 }
80
Colin Cross1f7f3bd2016-07-27 10:12:38 -070081 return cflags, asflags
82}
83
84func deviceFlags(ctx android.BaseContext) []string {
85 var cflags []string
86 deviceFrameSizeLimit := 1736
87 if len(ctx.AConfig().SanitizeDevice()) > 0 {
88 deviceFrameSizeLimit = 6400
89 }
90 cflags = append(cflags,
91 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
92 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
93 )
94
95 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
96 if envTrue(ctx, "ART_TARGET_LINUX") {
97 cflags = append(cflags, "-DART_TARGET_LINUX")
98 } else {
99 cflags = append(cflags, "-DART_TARGET_ANDROID")
100 }
101 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
102 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
103 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
104 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
105
106 return cflags
107}
108
109func hostFlags(ctx android.BaseContext) []string {
110 var cflags []string
111 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700112 if len(ctx.AConfig().SanitizeHost()) > 0 {
113 // art/test/137-cfi/cfi.cc
114 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
115 hostFrameSizeLimit = 6400
116 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700117 cflags = append(cflags,
118 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
119 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
120 )
121
122 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
123 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
124 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
125 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
126 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
127
128 return cflags
129}
130
Colin Cross6e511782016-09-13 13:41:03 -0700131func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700132 type props struct {
133 Target struct {
134 Android struct {
135 Cflags []string
136 }
137 Host struct {
138 Cflags []string
139 }
140 }
141 Cflags []string
142 Asflags []string
143 }
144
145 p := &props{}
146 p.Cflags, p.Asflags = globalFlags(ctx)
147 p.Target.Android.Cflags = deviceFlags(ctx)
148 p.Target.Host.Cflags = hostFlags(ctx)
149 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700150}
Colin Cross6326d1b2016-09-06 10:24:28 -0700151
Colin Cross6e511782016-09-13 13:41:03 -0700152func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700153 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
154 if linker != "" {
155 type props struct {
156 DynamicLinker string
157 }
158
159 p := &props{}
160 p.DynamicLinker = linker
161 ctx.AppendProperties(p)
162 }
163}
164
Colin Cross6e511782016-09-13 13:41:03 -0700165func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700166 if envTrue(ctx, "HOST_PREFER_32_BIT") {
167 type props struct {
168 Target struct {
169 Host struct {
170 Compile_multilib string
171 }
172 }
173 }
174
175 p := &props{}
176 p.Target.Host.Compile_multilib = "prefer32"
177 ctx.AppendProperties(p)
178 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700179}
180
Colin Cross6e95dd52016-09-12 15:37:10 -0700181func testMap(config android.Config) map[string][]string {
182 return config.Once("artTests", func() interface{} {
183 return make(map[string][]string)
184 }).(map[string][]string)
185}
186
187func testInstall(ctx android.InstallHookContext) {
188 testMap := testMap(ctx.AConfig())
189
190 var name string
191 if ctx.Host() {
192 name = "host_"
193 } else {
194 name = "device_"
195 }
196 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
197
198 artTestMutex.Lock()
199 defer artTestMutex.Unlock()
200
201 tests := testMap[name]
202 tests = append(tests, ctx.Path().RelPathString())
203 testMap[name] = tests
204}
205
206var artTestMutex sync.Mutex
207
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700208func init() {
209 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700210 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700211 soong.RegisterModuleType("art_cc_test", artTest)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700212 soong.RegisterModuleType("art_cc_test_library", artTestLibrary)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700213 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
214 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
215}
216
217func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700218 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700219 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700220
221 return module, props
222}
223
224func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700225 c := &codegenProperties{}
226 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700227 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700228
229 return module, props
230}
231
232func artLibrary() (blueprint.Module, []interface{}) {
233 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
234 module, props := library.Init()
235
Colin Cross6e95dd52016-09-12 15:37:10 -0700236 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700237
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700238 return module, props
239}
240
Colin Cross123989f2016-09-07 14:12:50 -0700241func artBinary() (blueprint.Module, []interface{}) {
242 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
243 module, props := binary.Init()
244
Colin Cross6e511782016-09-13 13:41:03 -0700245 android.AddLoadHook(module, customLinker)
246 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700247 return module, props
248}
249
Colin Crossc7376e02016-09-08 12:52:18 -0700250func artTest() (blueprint.Module, []interface{}) {
251 test := cc.NewTest(android.HostAndDeviceSupported)
252 module, props := test.Init()
253
Colin Cross6e95dd52016-09-12 15:37:10 -0700254 props = installCodegenCustomizer(module, props, false)
255
Colin Cross6e511782016-09-13 13:41:03 -0700256 android.AddLoadHook(module, customLinker)
257 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700258 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700259 return module, props
260}
261
Colin Crossafd3c9e2016-09-16 13:47:21 -0700262func artTestLibrary() (blueprint.Module, []interface{}) {
263 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
264 module, props := test.Init()
265
266 props = installCodegenCustomizer(module, props, false)
267
268 android.AddLoadHook(module, prefer32Bit)
269 android.AddInstallHook(module, testInstall)
270 return module, props
271}
272
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700273func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
274 ret := ctx.AConfig().Getenv(key)
275 if ret == "" {
276 return defaultValue
277 }
278 return ret
279}
280
281func envTrue(ctx android.BaseContext, key string) bool {
282 return ctx.AConfig().Getenv(key) == "true"
283}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100284
285func envFalse(ctx android.BaseContext, key string) bool {
286 return ctx.AConfig().Getenv(key) == "false"
287}