blob: ffa92731358a981ed535306b5501d6cb083a048b [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
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 Cross1f7f3bd2016-07-27 10:12:38 -0700175func init() {
176 soong.RegisterModuleType("art_cc_library", artLibrary)
Colin Cross123989f2016-09-07 14:12:50 -0700177 soong.RegisterModuleType("art_cc_binary", artBinary)
Colin Crossc7376e02016-09-08 12:52:18 -0700178 soong.RegisterModuleType("art_cc_test", artTest)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700179 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
180 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
181}
182
183func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700184 module, props := artDefaultsFactory()
Colin Cross6e511782016-09-13 13:41:03 -0700185 android.AddLoadHook(module, globalDefaults)
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700186
187 return module, props
188}
189
190func artDefaultsFactory() (blueprint.Module, []interface{}) {
Colin Cross6e511782016-09-13 13:41:03 -0700191 c := &codegenProperties{}
192 module, props := cc.DefaultsFactory(c)
193 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c) })
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700194
195 return module, props
196}
197
198func artLibrary() (blueprint.Module, []interface{}) {
199 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
200 module, props := library.Init()
201
Colin Cross6e511782016-09-13 13:41:03 -0700202 c := &codegenProperties{}
203 android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c) })
204 props = append(props, c)
Colin Crossfe6064a2016-08-30 13:49:26 -0700205
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700206 return module, props
207}
208
Colin Cross123989f2016-09-07 14:12:50 -0700209func artBinary() (blueprint.Module, []interface{}) {
210 binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
211 module, props := binary.Init()
212
Colin Cross6e511782016-09-13 13:41:03 -0700213 android.AddLoadHook(module, customLinker)
214 android.AddLoadHook(module, prefer32Bit)
Colin Cross123989f2016-09-07 14:12:50 -0700215 return module, props
216}
217
Colin Crossc7376e02016-09-08 12:52:18 -0700218func artTest() (blueprint.Module, []interface{}) {
219 test := cc.NewTest(android.HostAndDeviceSupported)
220 module, props := test.Init()
221
Colin Cross6e511782016-09-13 13:41:03 -0700222 android.AddLoadHook(module, customLinker)
223 android.AddLoadHook(module, prefer32Bit)
Colin Crossc7376e02016-09-08 12:52:18 -0700224 return module, props
225}
226
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700227func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
228 ret := ctx.AConfig().Getenv(key)
229 if ret == "" {
230 return defaultValue
231 }
232 return ret
233}
234
235func envTrue(ctx android.BaseContext, key string) bool {
236 return ctx.AConfig().Getenv(key) == "true"
237}
David Brazdil7b49e6c2016-09-01 11:06:18 +0100238
239func envFalse(ctx android.BaseContext, key string) bool {
240 return ctx.AConfig().Getenv(key) == "false"
241}