blob: ba5521a9aec4a4db6874518971061a6368025d7e [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
Colin Cross1f7f3bd2016-07-27 10:12:38 -070075 return cflags, asflags
76}
77
78func deviceFlags(ctx android.BaseContext) []string {
79 var cflags []string
80 deviceFrameSizeLimit := 1736
81 if len(ctx.AConfig().SanitizeDevice()) > 0 {
82 deviceFrameSizeLimit = 6400
83 }
84 cflags = append(cflags,
85 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
86 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
87 )
88
89 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
90 if envTrue(ctx, "ART_TARGET_LINUX") {
91 cflags = append(cflags, "-DART_TARGET_LINUX")
92 } else {
93 cflags = append(cflags, "-DART_TARGET_ANDROID")
94 }
95 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
96 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
97 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
98 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
99
100 return cflags
101}
102
103func hostFlags(ctx android.BaseContext) []string {
104 var cflags []string
105 hostFrameSizeLimit := 1736
Colin Cross3174b682016-09-19 12:25:31 -0700106 if len(ctx.AConfig().SanitizeHost()) > 0 {
107 // art/test/137-cfi/cfi.cc
108 // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess'
109 hostFrameSizeLimit = 6400
110 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700111 cflags = append(cflags,
112 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
113 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
114 )
115
116 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
117 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
118 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
119 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
120 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
121
122 return cflags
123}
124
Colin Cross6e511782016-09-13 13:41:03 -0700125func globalDefaults(ctx android.LoadHookContext) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700126 type props struct {
127 Target struct {
128 Android struct {
129 Cflags []string
130 }
131 Host struct {
132 Cflags []string
133 }
134 }
135 Cflags []string
136 Asflags []string
137 }
138
139 p := &props{}
140 p.Cflags, p.Asflags = globalFlags(ctx)
141 p.Target.Android.Cflags = deviceFlags(ctx)
142 p.Target.Host.Cflags = hostFlags(ctx)
143 ctx.AppendProperties(p)
Colin Crossfe6064a2016-08-30 13:49:26 -0700144}
Colin Cross6326d1b2016-09-06 10:24:28 -0700145
Colin Cross6e511782016-09-13 13:41:03 -0700146func customLinker(ctx android.LoadHookContext) {
Colin Crossfe6064a2016-08-30 13:49:26 -0700147 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
148 if linker != "" {
149 type props struct {
150 DynamicLinker string
151 }
152
153 p := &props{}
154 p.DynamicLinker = linker
155 ctx.AppendProperties(p)
156 }
157}
158
Colin Cross6e511782016-09-13 13:41:03 -0700159func prefer32Bit(ctx android.LoadHookContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700160 if envTrue(ctx, "HOST_PREFER_32_BIT") {
161 type props struct {
162 Target struct {
163 Host struct {
164 Compile_multilib string
165 }
166 }
167 }
168
169 p := &props{}
170 p.Target.Host.Compile_multilib = "prefer32"
171 ctx.AppendProperties(p)
172 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700173}
174
Colin Cross6e95dd52016-09-12 15:37:10 -0700175func testMap(config android.Config) map[string][]string {
176 return config.Once("artTests", func() interface{} {
177 return make(map[string][]string)
178 }).(map[string][]string)
179}
180
181func testInstall(ctx android.InstallHookContext) {
182 testMap := testMap(ctx.AConfig())
183
184 var name string
185 if ctx.Host() {
186 name = "host_"
187 } else {
188 name = "device_"
189 }
190 name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
191
192 artTestMutex.Lock()
193 defer artTestMutex.Unlock()
194
195 tests := testMap[name]
196 tests = append(tests, ctx.Path().RelPathString())
197 testMap[name] = tests
198}
199
200var artTestMutex sync.Mutex
201
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700202func init() {
203 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700204 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700205 soong.RegisterModuleType("art_cc_test", artTest)
Colin Crossafd3c9e2016-09-16 13:47:21 -0700206 soong.RegisterModuleType("art_cc_test_library", artTestLibrary)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700207 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
208 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
209}
210
211func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700212 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700213 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700214
215 return module, props
216}
217
218func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700219 c := &codegenProperties{}
220 module, props := cc.DefaultsFactory(c)
Colin Cross6e95dd52016-09-12 15:37:10 -0700221 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700222
223 return module, props
224}
225
226func artLibrary() (blueprint.Module, []interface{}) {
227 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
228 module, props := library.Init()
229
Colin Cross6e95dd52016-09-12 15:37:10 -0700230 props = installCodegenCustomizer(module, props, true)
Colin Crossfe6064a2016-08-30 13:49:26 -0700231
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700232 return module, props
233}
234
Colin Cross123989f2016-09-07 14:12:50 -0700235func artBinary() (blueprint.Module, []interface{}) {
236 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
237 module, props := binary.Init()
238
Colin Cross6e511782016-09-13 13:41:03 -0700239 android.AddLoadHook(module, customLinker)
240 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700241 return module, props
242}
243
Colin Crossc7376e02016-09-08 12:52:18 -0700244func artTest() (blueprint.Module, []interface{}) {
245 test := cc.NewTest(android.HostAndDeviceSupported)
246 module, props := test.Init()
247
Colin Cross6e95dd52016-09-12 15:37:10 -0700248 props = installCodegenCustomizer(module, props, false)
249
Colin Cross6e511782016-09-13 13:41:03 -0700250 android.AddLoadHook(module, customLinker)
251 android.AddLoadHook(module, prefer32Bit)
Colin Cross6e95dd52016-09-12 15:37:10 -0700252 android.AddInstallHook(module, testInstall)
Colin Crossc7376e02016-09-08 12:52:18 -0700253 return module, props
254}
255
Colin Crossafd3c9e2016-09-16 13:47:21 -0700256func artTestLibrary() (blueprint.Module, []interface{}) {
257 test := cc.NewTestLibrary(android.HostAndDeviceSupported)
258 module, props := test.Init()
259
260 props = installCodegenCustomizer(module, props, false)
261
262 android.AddLoadHook(module, prefer32Bit)
263 android.AddInstallHook(module, testInstall)
264 return module, props
265}
266
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700267func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
268 ret := ctx.AConfig().Getenv(key)
269 if ret == "" {
270 return defaultValue
271 }
272 return ret
273}
274
275func envTrue(ctx android.BaseContext, key string) bool {
276 return ctx.AConfig().Getenv(key) == "true"
277}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100278
279func envFalse(ctx android.BaseContext, key string) bool {
280 return ctx.AConfig().Getenv(key) == "false"
281}