blob: f5547ccf024d5e63a774b8c29dffd6d309335c96 [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
112 cflags = append(cflags,
113 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
114 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
115 )
116
117 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
118 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
119 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
120 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
121 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
122
123 return cflags
124}
125
Colin Cross6e511782016-09-13 13:41:03 -0700126func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700127 type props struct {
128 Target struct {
129 Android struct {
130 Cflags []string
131 }
132 Host struct {
133 Cflags []string
134 }
135 }
136 Cflags []string
137 Asflags []string
138 }
139
140 p := &props{}
141 p.Cflags, p.Asflags = globalFlags(ctx)
142 p.Target.Android.Cflags = deviceFlags(ctx)
143 p.Target.Host.Cflags = hostFlags(ctx)
144 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700145}
Colin Cross6326d1b2016-09-06 10:24:28 -0700146
Colin Cross6e511782016-09-13 13:41:03 -0700147func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700148 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
149 if linker != "" {
150 type props struct {
151 DynamicLinker string
152 }
153
154 p := &props{}
155 p.DynamicLinker = linker
156 ctx.AppendProperties(p)
157 }
158}
159
Colin Cross6e511782016-09-13 13:41:03 -0700160func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700161 if envTrue(ctx, "HOST_PREFER_32_BIT") {
162 type props struct {
163 Target struct {
164 Host struct {
165 Compile_multilib string
166 }
167 }
168 }
169
170 p := &props{}
171 p.Target.Host.Compile_multilib = "prefer32"
172 ctx.AppendProperties(p)
173 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700174}
175
Colin Cross6e95dd52016-09-12 15:37:10 -0700176func testMap(config android.Config) map[string][]string {
177 return config.Once("artTests", func() interface{} {
178 return make(map[string][]string)
179 }).(map[string][]string)
180}
181
182func testInstall(ctx android.InstallHookContext) {
183 testMap := testMap(ctx.AConfig())
184
185 var name string
186 if ctx.Host() {
187 name = "host_"
188 } else {
189 name = "device_"
190 }
191 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
192
193 artTestMutex.Lock()
194 defer artTestMutex.Unlock()
195
196 tests := testMap[name]
197 tests = append(tests, ctx.Path().RelPathString())
198 testMap[name] = tests
199}
200
201var artTestMutex sync.Mutex
202
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700203func init() {
204 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700205 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700206 soong.RegisterModuleType("art_cc_test", artTest)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700207 soong.RegisterModuleType("art_cc_test_library", artTestLibrary)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700208 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
209 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
210}
211
212func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700213 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700214 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700215
216 return module, props
217}
218
219func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700220 c := &codegenProperties{}
221 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700222 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700223
224 return module, props
225}
226
227func artLibrary() (blueprint.Module, []interface{}) {
228 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
229 module, props := library.Init()
230
Colin Cross6e95dd52016-09-12 15:37:10 -0700231 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700232
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700233 return module, props
234}
235
Colin Cross123989f2016-09-07 14:12:50 -0700236func artBinary() (blueprint.Module, []interface{}) {
237 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
238 module, props := binary.Init()
239
Colin Cross6e511782016-09-13 13:41:03 -0700240 android.AddLoadHook(module, customLinker)
241 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700242 return module, props
243}
244
Colin Crossc7376e02016-09-08 12:52:18 -0700245func artTest() (blueprint.Module, []interface{}) {
246 test := cc.NewTest(android.HostAndDeviceSupported)
247 module, props := test.Init()
248
Colin Cross6e95dd52016-09-12 15:37:10 -0700249 props = installCodegenCustomizer(module, props, false)
250
Colin Cross6e511782016-09-13 13:41:03 -0700251 android.AddLoadHook(module, customLinker)
252 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700253 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700254 return module, props
255}
256
Colin Crossafd3c9e2016-09-16 13:47:21 -0700257func artTestLibrary() (blueprint.Module, []interface{}) {
258 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
259 module, props := test.Init()
260
261 props = installCodegenCustomizer(module, props, false)
262
263 android.AddLoadHook(module, prefer32Bit)
264 android.AddInstallHook(module, testInstall)
265 return module, props
266}
267
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700268func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
269 ret := ctx.AConfig().Getenv(key)
270 if ret == "" {
271 return defaultValue
272 }
273 return ret
274}
275
276func envTrue(ctx android.BaseContext, key string) bool {
277 return ctx.AConfig().Getenv(key) == "true"
278}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100279
280func envFalse(ctx android.BaseContext, key string) bool {
281 return ctx.AConfig().Getenv(key) == "false"
282}