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