blob: f694505fb4b34fed3bda3ccedb44efd9d9099c58 [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"
22
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
32 tlab := false
33
34 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
35
36 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
37 gcType = "SS"
38 tlab = true
39 }
40
41 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
42 if tlab {
43 cflags = append(cflags, "-DART_USE_TLAB=1")
44 }
45
David Brazdil7b49e6c2016-09-01 11:06:18 +010046 if !envFalse(ctx, "ART_ENABLE_VDEX") {
47 cflags = append(cflags, "-DART_ENABLE_VDEX")
48 }
49
Colin Cross1f7f3bd2016-07-27 10:12:38 -070050 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
51 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
52
53 if envTrue(ctx, "ART_HEAP_POISONING") {
54 cflags = append(cflags, "-DART_HEAP_POISONING=1")
55 asflags = append(asflags, "-DART_HEAP_POISONING=1")
56 }
57
58 if envTrue(ctx, "ART_USE_READ_BARRIER") {
59 // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP.
60 // The default is BAKER.
61 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
62 cflags = append(cflags,
63 "-DART_USE_READ_BARRIER=1",
64 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
65 asflags = append(asflags,
66 "-DART_USE_READ_BARRIER=1",
67 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
68
69 // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major
70 // slowdown with the read barrier config. b/26744236.
71 cflags = append(cflags, "-fstack-protector")
72 }
73
Roland Levillain04147ef2016-09-06 11:09:41 +010074 // Are additional statically-linked ART host binaries
75 // (dex2oats, oatdumps, etc.) getting built?
76 if envTrue(ctx, "ART_BUILD_HOST_STATIC") {
77 cflags = append(cflags, "-DART_BUILD_HOST_STATIC=1")
78 }
79
Colin Cross1f7f3bd2016-07-27 10:12:38 -070080 return cflags, asflags
81}
82
83func deviceFlags(ctx android.BaseContext) []string {
84 var cflags []string
85 deviceFrameSizeLimit := 1736
86 if len(ctx.AConfig().SanitizeDevice()) > 0 {
87 deviceFrameSizeLimit = 6400
88 }
89 cflags = append(cflags,
90 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
91 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
92 )
93
94 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
95 if envTrue(ctx, "ART_TARGET_LINUX") {
96 cflags = append(cflags, "-DART_TARGET_LINUX")
97 } else {
98 cflags = append(cflags, "-DART_TARGET_ANDROID")
99 }
100 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
101 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
102 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
103 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
104
105 return cflags
106}
107
108func hostFlags(ctx android.BaseContext) []string {
109 var cflags []string
110 hostFrameSizeLimit := 1736
111 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
125func (a *artGlobalDefaults) CustomizeProperties(ctx android.CustomizePropertiesContext) {
126 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 Crossfe6064a2016-08-30 13:49:26 -0700146type artGlobalDefaults struct{}
147
148func (a *artCustomLinkerCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
149 linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
150 if linker != "" {
151 type props struct {
152 DynamicLinker string
153 }
154
155 p := &props{}
156 p.DynamicLinker = linker
157 ctx.AppendProperties(p)
158 }
159}
160
161type artCustomLinkerCustomizer struct{}
162
163func (a *artPrefer32BitCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
Colin Cross6326d1b2016-09-06 10:24:28 -0700164 if envTrue(ctx, "HOST_PREFER_32_BIT") {
165 type props struct {
166 Target struct {
167 Host struct {
168 Compile_multilib string
169 }
170 }
171 }
172
173 p := &props{}
174 p.Target.Host.Compile_multilib = "prefer32"
175 ctx.AppendProperties(p)
176 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700177}
178
Colin Crossfe6064a2016-08-30 13:49:26 -0700179type artPrefer32BitCustomizer struct{}
Colin Cross123989f2016-09-07 14:12:50 -0700180
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700181func init() {
182 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700183 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700184 soong.RegisterModuleType("art_cc_test", artTest)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700185 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
186 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
187}
188
189func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
190 c := &artGlobalDefaults{}
191 module, props := artDefaultsFactory()
192 android.AddCustomizer(module.(android.Module), c)
193
194 return module, props
195}
196
197func artDefaultsFactory() (blueprint.Module, []interface{}) {
198 c := &codegenCustomizer{}
199 module, props := cc.DefaultsFactory(&c.codegenProperties)
200 android.AddCustomizer(module.(android.Module), c)
201
202 return module, props
203}
204
205func artLibrary() (blueprint.Module, []interface{}) {
206 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
207 module, props := library.Init()
208
209 c := &codegenCustomizer{}
210 android.AddCustomizer(library, c)
211 props = append(props, &c.codegenProperties)
Colin Crossfe6064a2016-08-30 13:49:26 -0700212
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700213 return module, props
214}
215
Colin Cross123989f2016-09-07 14:12:50 -0700216func artBinary() (blueprint.Module, []interface{}) {
217 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
218 module, props := binary.Init()
219
Colin Crossfe6064a2016-08-30 13:49:26 -0700220 android.AddCustomizer(binary, &artCustomLinkerCustomizer{})
221 android.AddCustomizer(binary, &artPrefer32BitCustomizer{})
Colin Cross123989f2016-09-07 14:12:50 -0700222 return module, props
223}
224
Colin Crossc7376e02016-09-08 12:52:18 -0700225func artTest() (blueprint.Module, []interface{}) {
226 test := cc.NewTest(android.HostAndDeviceSupported)
227 module, props := test.Init()
228
229 android.AddCustomizer(test, &artCustomLinkerCustomizer{})
230 android.AddCustomizer(test, &artPrefer32BitCustomizer{})
231 return module, props
232}
233
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700234func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
235 ret := ctx.AConfig().Getenv(key)
236 if ret == "" {
237 return defaultValue
238 }
239 return ret
240}
241
242func envTrue(ctx android.BaseContext, key string) bool {
243 return ctx.AConfig().Getenv(key) == "true"
244}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100245
246func envFalse(ctx android.BaseContext, key string) bool {
247 return ctx.AConfig().Getenv(key) == "false"
248}