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