Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package art |
| 16 | |
| 17 | import ( |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | "android/soong/cc" |
| 20 | "fmt" |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 21 | "sync" |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint" |
| 24 | ) |
| 25 | |
| 26 | var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"} |
| 27 | |
| 28 | func globalFlags(ctx android.BaseContext) ([]string, []string) { |
| 29 | var cflags []string |
| 30 | var asflags []string |
| 31 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 32 | opt := envDefault(ctx, "ART_NDEBUG_OPT_FLAG", "-O3") |
| 33 | cflags = append(cflags, opt) |
| 34 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 35 | tlab := false |
| 36 | |
| 37 | gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS") |
| 38 | |
| 39 | if envTrue(ctx, "ART_TEST_DEBUG_GC") { |
| 40 | gcType = "SS" |
| 41 | tlab = true |
| 42 | } |
| 43 | |
| 44 | cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType) |
| 45 | if tlab { |
| 46 | cflags = append(cflags, "-DART_USE_TLAB=1") |
| 47 | } |
| 48 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 49 | if !envFalse(ctx, "ART_ENABLE_VDEX") { |
| 50 | cflags = append(cflags, "-DART_ENABLE_VDEX") |
| 51 | } |
| 52 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 53 | imtSize := envDefault(ctx, "ART_IMT_SIZE", "43") |
| 54 | cflags = append(cflags, "-DIMT_SIZE="+imtSize) |
| 55 | |
| 56 | if envTrue(ctx, "ART_HEAP_POISONING") { |
| 57 | cflags = append(cflags, "-DART_HEAP_POISONING=1") |
| 58 | asflags = append(asflags, "-DART_HEAP_POISONING=1") |
| 59 | } |
| 60 | |
| 61 | if envTrue(ctx, "ART_USE_READ_BARRIER") { |
| 62 | // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP. |
| 63 | // The default is BAKER. |
| 64 | barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER") |
| 65 | cflags = append(cflags, |
| 66 | "-DART_USE_READ_BARRIER=1", |
| 67 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
| 68 | asflags = append(asflags, |
| 69 | "-DART_USE_READ_BARRIER=1", |
| 70 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
| 71 | |
| 72 | // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major |
| 73 | // slowdown with the read barrier config. b/26744236. |
| 74 | cflags = append(cflags, "-fstack-protector") |
| 75 | } |
| 76 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 77 | if envTrue(ctx, "ART_USE_VIXL_ARM_BACKEND") { |
| 78 | // Used to enable the new VIXL-based ARM code generator. |
| 79 | cflags = append(cflags, "-DART_USE_VIXL_ARM_BACKEND=1") |
| 80 | asflags = append(asflags, "-DART_USE_VIXL_ARM_BACKEND=1") |
| 81 | } |
| 82 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 83 | return cflags, asflags |
| 84 | } |
| 85 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 86 | func debugFlags(ctx android.BaseContext) []string { |
| 87 | var cflags []string |
| 88 | |
| 89 | opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2") |
| 90 | cflags = append(cflags, opt) |
| 91 | |
| 92 | return cflags |
| 93 | } |
| 94 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 95 | func deviceFlags(ctx android.BaseContext) []string { |
| 96 | var cflags []string |
| 97 | deviceFrameSizeLimit := 1736 |
| 98 | if len(ctx.AConfig().SanitizeDevice()) > 0 { |
Vishwath Mohan | 1ecc4fe | 2016-09-26 09:22:42 -0700 | [diff] [blame] | 99 | deviceFrameSizeLimit = 7400 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 100 | } |
| 101 | cflags = append(cflags, |
| 102 | fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit), |
| 103 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit), |
| 104 | ) |
| 105 | |
| 106 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress()) |
| 107 | if envTrue(ctx, "ART_TARGET_LINUX") { |
| 108 | cflags = append(cflags, "-DART_TARGET_LINUX") |
| 109 | } else { |
| 110 | cflags = append(cflags, "-DART_TARGET_ANDROID") |
| 111 | } |
| 112 | minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 113 | maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
| 114 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 115 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 116 | |
| 117 | return cflags |
| 118 | } |
| 119 | |
| 120 | func hostFlags(ctx android.BaseContext) []string { |
| 121 | var cflags []string |
| 122 | hostFrameSizeLimit := 1736 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 123 | if len(ctx.AConfig().SanitizeHost()) > 0 { |
| 124 | // art/test/137-cfi/cfi.cc |
| 125 | // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess' |
| 126 | hostFrameSizeLimit = 6400 |
| 127 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 128 | cflags = append(cflags, |
| 129 | fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit), |
| 130 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit), |
| 131 | ) |
| 132 | |
| 133 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress()) |
| 134 | minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 135 | maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
| 136 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 137 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 138 | |
| 139 | return cflags |
| 140 | } |
| 141 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 142 | func globalDefaults(ctx android.LoadHookContext) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 143 | type props struct { |
| 144 | Target struct { |
| 145 | Android struct { |
| 146 | Cflags []string |
| 147 | } |
| 148 | Host struct { |
| 149 | Cflags []string |
| 150 | } |
| 151 | } |
| 152 | Cflags []string |
| 153 | Asflags []string |
| 154 | } |
| 155 | |
| 156 | p := &props{} |
| 157 | p.Cflags, p.Asflags = globalFlags(ctx) |
| 158 | p.Target.Android.Cflags = deviceFlags(ctx) |
| 159 | p.Target.Host.Cflags = hostFlags(ctx) |
| 160 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 161 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 162 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 163 | func debugDefaults(ctx android.LoadHookContext) { |
| 164 | type props struct { |
| 165 | Cflags []string |
| 166 | } |
| 167 | |
| 168 | p := &props{} |
| 169 | p.Cflags = debugFlags(ctx) |
| 170 | ctx.AppendProperties(p) |
| 171 | } |
| 172 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 173 | func customLinker(ctx android.LoadHookContext) { |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 174 | linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "") |
| 175 | if linker != "" { |
| 176 | type props struct { |
| 177 | DynamicLinker string |
| 178 | } |
| 179 | |
| 180 | p := &props{} |
| 181 | p.DynamicLinker = linker |
| 182 | ctx.AppendProperties(p) |
| 183 | } |
| 184 | } |
| 185 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 186 | func prefer32Bit(ctx android.LoadHookContext) { |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 187 | if envTrue(ctx, "HOST_PREFER_32_BIT") { |
| 188 | type props struct { |
| 189 | Target struct { |
| 190 | Host struct { |
| 191 | Compile_multilib string |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | p := &props{} |
| 197 | p.Target.Host.Compile_multilib = "prefer32" |
| 198 | ctx.AppendProperties(p) |
| 199 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 202 | func testMap(config android.Config) map[string][]string { |
| 203 | return config.Once("artTests", func() interface{} { |
| 204 | return make(map[string][]string) |
| 205 | }).(map[string][]string) |
| 206 | } |
| 207 | |
| 208 | func testInstall(ctx android.InstallHookContext) { |
| 209 | testMap := testMap(ctx.AConfig()) |
| 210 | |
| 211 | var name string |
| 212 | if ctx.Host() { |
| 213 | name = "host_" |
| 214 | } else { |
| 215 | name = "device_" |
| 216 | } |
| 217 | name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName() |
| 218 | |
| 219 | artTestMutex.Lock() |
| 220 | defer artTestMutex.Unlock() |
| 221 | |
| 222 | tests := testMap[name] |
| 223 | tests = append(tests, ctx.Path().RelPathString()) |
| 224 | testMap[name] = tests |
| 225 | } |
| 226 | |
| 227 | var artTestMutex sync.Mutex |
| 228 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 229 | func init() { |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 230 | android.RegisterModuleType("art_cc_library", artLibrary) |
| 231 | android.RegisterModuleType("art_cc_binary", artBinary) |
| 232 | android.RegisterModuleType("art_cc_test", artTest) |
| 233 | android.RegisterModuleType("art_cc_test_library", artTestLibrary) |
| 234 | android.RegisterModuleType("art_cc_defaults", artDefaultsFactory) |
| 235 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 236 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 240 | module, props := artDefaultsFactory() |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 241 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 242 | |
| 243 | return module, props |
| 244 | } |
| 245 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 246 | func artDebugDefaultsFactory() (blueprint.Module, []interface{}) { |
| 247 | module, props := artDefaultsFactory() |
| 248 | android.AddLoadHook(module, debugDefaults) |
| 249 | |
| 250 | return module, props |
| 251 | } |
| 252 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 253 | func artDefaultsFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 254 | c := &codegenProperties{} |
| 255 | module, props := cc.DefaultsFactory(c) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 256 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 257 | |
| 258 | return module, props |
| 259 | } |
| 260 | |
| 261 | func artLibrary() (blueprint.Module, []interface{}) { |
| 262 | library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true) |
| 263 | module, props := library.Init() |
| 264 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 265 | props = installCodegenCustomizer(module, props, true) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 266 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 267 | return module, props |
| 268 | } |
| 269 | |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 270 | func artBinary() (blueprint.Module, []interface{}) { |
| 271 | binary, _ := cc.NewBinary(android.HostAndDeviceSupported) |
| 272 | module, props := binary.Init() |
| 273 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 274 | android.AddLoadHook(module, customLinker) |
| 275 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 276 | return module, props |
| 277 | } |
| 278 | |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 279 | func artTest() (blueprint.Module, []interface{}) { |
| 280 | test := cc.NewTest(android.HostAndDeviceSupported) |
| 281 | module, props := test.Init() |
| 282 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 283 | props = installCodegenCustomizer(module, props, false) |
| 284 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 285 | android.AddLoadHook(module, customLinker) |
| 286 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 287 | android.AddInstallHook(module, testInstall) |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 288 | return module, props |
| 289 | } |
| 290 | |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 291 | func artTestLibrary() (blueprint.Module, []interface{}) { |
| 292 | test := cc.NewTestLibrary(android.HostAndDeviceSupported) |
| 293 | module, props := test.Init() |
| 294 | |
| 295 | props = installCodegenCustomizer(module, props, false) |
| 296 | |
| 297 | android.AddLoadHook(module, prefer32Bit) |
| 298 | android.AddInstallHook(module, testInstall) |
| 299 | return module, props |
| 300 | } |
| 301 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 302 | func envDefault(ctx android.BaseContext, key string, defaultValue string) string { |
| 303 | ret := ctx.AConfig().Getenv(key) |
| 304 | if ret == "" { |
| 305 | return defaultValue |
| 306 | } |
| 307 | return ret |
| 308 | } |
| 309 | |
| 310 | func envTrue(ctx android.BaseContext, key string) bool { |
| 311 | return ctx.AConfig().Getenv(key) == "true" |
| 312 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 313 | |
| 314 | func envFalse(ctx android.BaseContext, key string) bool { |
| 315 | return ctx.AConfig().Getenv(key) == "false" |
| 316 | } |