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 | |
Hiroshi Yamauchi | da75ad7 | 2017-01-24 11:06:47 -0800 | [diff] [blame] | 61 | if !envFalse(ctx, "ART_USE_READ_BARRIER") && ctx.AConfig().ArtUseReadBarrier() { |
Roland Levillain | b81e9e9 | 2017-04-20 17:35:32 +0100 | [diff] [blame] | 62 | // Used to change the read barrier type. Valid values are BAKER, BROOKS, |
| 63 | // TABLELOOKUP. The default is BAKER. |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 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") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Nicolas Geoffray | 467d94a | 2017-03-16 10:24:17 +0000 | [diff] [blame] | 73 | if envTrue(ctx, "ART_USE_OLD_ARM_BACKEND") { |
| 74 | // Used to enable the old, pre-VIXL ARM code generator. |
| 75 | cflags = append(cflags, "-DART_USE_OLD_ARM_BACKEND=1") |
| 76 | asflags = append(asflags, "-DART_USE_OLD_ARM_BACKEND=1") |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 79 | // We need larger stack overflow guards for ASAN, as the compiled code will have |
| 80 | // larger frame sizes. For simplicity, just use global not-target-specific cflags. |
| 81 | // Note: We increase this for both debug and non-debug, as the overflow gap will |
| 82 | // be compiled into managed code. We always preopt (and build core images) with |
| 83 | // the debug version. So make the gap consistent (and adjust for the worst). |
| 84 | if len(ctx.AConfig().SanitizeDevice()) > 0 || len(ctx.AConfig().SanitizeHost()) > 0 { |
| 85 | cflags = append(cflags, |
| 86 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
| 87 | "-DART_STACK_OVERFLOW_GAP_arm64=8192", |
| 88 | "-DART_STACK_OVERFLOW_GAP_mips=16384", |
| 89 | "-DART_STACK_OVERFLOW_GAP_mips64=16384", |
Andreas Gampe | 3e00363 | 2017-06-05 15:06:16 -0700 | [diff] [blame] | 90 | "-DART_STACK_OVERFLOW_GAP_x86=16384", |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 91 | "-DART_STACK_OVERFLOW_GAP_x86_64=20480") |
| 92 | } else { |
| 93 | cflags = append(cflags, |
| 94 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
| 95 | "-DART_STACK_OVERFLOW_GAP_arm64=8192", |
| 96 | "-DART_STACK_OVERFLOW_GAP_mips=16384", |
| 97 | "-DART_STACK_OVERFLOW_GAP_mips64=16384", |
| 98 | "-DART_STACK_OVERFLOW_GAP_x86=8192", |
| 99 | "-DART_STACK_OVERFLOW_GAP_x86_64=8192") |
| 100 | } |
Andreas Gampe | bc9f10c | 2017-05-19 08:28:06 -0700 | [diff] [blame] | 101 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 102 | return cflags, asflags |
| 103 | } |
| 104 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 105 | func debugFlags(ctx android.BaseContext) []string { |
| 106 | var cflags []string |
| 107 | |
| 108 | opt := envDefault(ctx, "ART_DEBUG_OPT_FLAG", "-O2") |
| 109 | cflags = append(cflags, opt) |
| 110 | |
| 111 | return cflags |
| 112 | } |
| 113 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 114 | func deviceFlags(ctx android.BaseContext) []string { |
| 115 | var cflags []string |
| 116 | deviceFrameSizeLimit := 1736 |
| 117 | if len(ctx.AConfig().SanitizeDevice()) > 0 { |
Vishwath Mohan | 1ecc4fe | 2016-09-26 09:22:42 -0700 | [diff] [blame] | 118 | deviceFrameSizeLimit = 7400 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 119 | } |
| 120 | cflags = append(cflags, |
| 121 | fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit), |
| 122 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit), |
| 123 | ) |
| 124 | |
| 125 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress()) |
| 126 | if envTrue(ctx, "ART_TARGET_LINUX") { |
| 127 | cflags = append(cflags, "-DART_TARGET_LINUX") |
| 128 | } else { |
| 129 | cflags = append(cflags, "-DART_TARGET_ANDROID") |
| 130 | } |
| 131 | minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 132 | maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
| 133 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 134 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 135 | |
| 136 | return cflags |
| 137 | } |
| 138 | |
| 139 | func hostFlags(ctx android.BaseContext) []string { |
| 140 | var cflags []string |
| 141 | hostFrameSizeLimit := 1736 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 142 | if len(ctx.AConfig().SanitizeHost()) > 0 { |
| 143 | // art/test/137-cfi/cfi.cc |
| 144 | // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess' |
| 145 | hostFrameSizeLimit = 6400 |
| 146 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 147 | cflags = append(cflags, |
| 148 | fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit), |
| 149 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit), |
| 150 | ) |
| 151 | |
| 152 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress()) |
| 153 | minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 154 | maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
| 155 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 156 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 157 | |
| 158 | return cflags |
| 159 | } |
| 160 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 161 | func globalDefaults(ctx android.LoadHookContext) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 162 | type props struct { |
| 163 | Target struct { |
| 164 | Android struct { |
| 165 | Cflags []string |
| 166 | } |
| 167 | Host struct { |
| 168 | Cflags []string |
| 169 | } |
| 170 | } |
| 171 | Cflags []string |
| 172 | Asflags []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 173 | Sanitize struct { |
| 174 | Recover []string |
| 175 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | p := &props{} |
| 179 | p.Cflags, p.Asflags = globalFlags(ctx) |
| 180 | p.Target.Android.Cflags = deviceFlags(ctx) |
| 181 | p.Target.Host.Cflags = hostFlags(ctx) |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 182 | |
| 183 | if envTrue(ctx, "ART_DEX_FILE_ACCESS_TRACKING") { |
| 184 | p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING") |
| 185 | p.Sanitize.Recover = []string { |
| 186 | "address", |
| 187 | } |
| 188 | } |
| 189 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 190 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 191 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 192 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 193 | func debugDefaults(ctx android.LoadHookContext) { |
| 194 | type props struct { |
| 195 | Cflags []string |
| 196 | } |
| 197 | |
| 198 | p := &props{} |
| 199 | p.Cflags = debugFlags(ctx) |
| 200 | ctx.AppendProperties(p) |
| 201 | } |
| 202 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 203 | func customLinker(ctx android.LoadHookContext) { |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 204 | linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "") |
| 205 | if linker != "" { |
| 206 | type props struct { |
| 207 | DynamicLinker string |
| 208 | } |
| 209 | |
| 210 | p := &props{} |
| 211 | p.DynamicLinker = linker |
| 212 | ctx.AppendProperties(p) |
| 213 | } |
| 214 | } |
| 215 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 216 | func prefer32Bit(ctx android.LoadHookContext) { |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 217 | if envTrue(ctx, "HOST_PREFER_32_BIT") { |
| 218 | type props struct { |
| 219 | Target struct { |
| 220 | Host struct { |
| 221 | Compile_multilib string |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | p := &props{} |
| 227 | p.Target.Host.Compile_multilib = "prefer32" |
| 228 | ctx.AppendProperties(p) |
| 229 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 232 | func testMap(config android.Config) map[string][]string { |
| 233 | return config.Once("artTests", func() interface{} { |
| 234 | return make(map[string][]string) |
| 235 | }).(map[string][]string) |
| 236 | } |
| 237 | |
| 238 | func testInstall(ctx android.InstallHookContext) { |
| 239 | testMap := testMap(ctx.AConfig()) |
| 240 | |
| 241 | var name string |
| 242 | if ctx.Host() { |
| 243 | name = "host_" |
| 244 | } else { |
| 245 | name = "device_" |
| 246 | } |
| 247 | name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName() |
| 248 | |
| 249 | artTestMutex.Lock() |
| 250 | defer artTestMutex.Unlock() |
| 251 | |
| 252 | tests := testMap[name] |
| 253 | tests = append(tests, ctx.Path().RelPathString()) |
| 254 | testMap[name] = tests |
| 255 | } |
| 256 | |
| 257 | var artTestMutex sync.Mutex |
| 258 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 259 | func init() { |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 260 | android.RegisterModuleType("art_cc_library", artLibrary) |
| 261 | android.RegisterModuleType("art_cc_binary", artBinary) |
| 262 | android.RegisterModuleType("art_cc_test", artTest) |
| 263 | android.RegisterModuleType("art_cc_test_library", artTestLibrary) |
| 264 | android.RegisterModuleType("art_cc_defaults", artDefaultsFactory) |
| 265 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 266 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 270 | module, props := artDefaultsFactory() |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 271 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 272 | |
| 273 | return module, props |
| 274 | } |
| 275 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 276 | func artDebugDefaultsFactory() (blueprint.Module, []interface{}) { |
| 277 | module, props := artDefaultsFactory() |
| 278 | android.AddLoadHook(module, debugDefaults) |
| 279 | |
| 280 | return module, props |
| 281 | } |
| 282 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 283 | func artDefaultsFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 284 | c := &codegenProperties{} |
| 285 | module, props := cc.DefaultsFactory(c) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 286 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 287 | |
| 288 | return module, props |
| 289 | } |
| 290 | |
| 291 | func artLibrary() (blueprint.Module, []interface{}) { |
Colin Cross | 9791626 | 2016-12-09 14:47:29 -0800 | [diff] [blame] | 292 | library, _ := cc.NewLibrary(android.HostAndDeviceSupported) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 293 | module, props := library.Init() |
| 294 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 295 | props = installCodegenCustomizer(module, props, true) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 296 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 297 | return module, props |
| 298 | } |
| 299 | |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 300 | func artBinary() (blueprint.Module, []interface{}) { |
| 301 | binary, _ := cc.NewBinary(android.HostAndDeviceSupported) |
| 302 | module, props := binary.Init() |
| 303 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 304 | android.AddLoadHook(module, customLinker) |
| 305 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 306 | return module, props |
| 307 | } |
| 308 | |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 309 | func artTest() (blueprint.Module, []interface{}) { |
| 310 | test := cc.NewTest(android.HostAndDeviceSupported) |
| 311 | module, props := test.Init() |
| 312 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 313 | props = installCodegenCustomizer(module, props, false) |
| 314 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 315 | android.AddLoadHook(module, customLinker) |
| 316 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 317 | android.AddInstallHook(module, testInstall) |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 318 | return module, props |
| 319 | } |
| 320 | |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 321 | func artTestLibrary() (blueprint.Module, []interface{}) { |
| 322 | test := cc.NewTestLibrary(android.HostAndDeviceSupported) |
| 323 | module, props := test.Init() |
| 324 | |
| 325 | props = installCodegenCustomizer(module, props, false) |
| 326 | |
| 327 | android.AddLoadHook(module, prefer32Bit) |
| 328 | android.AddInstallHook(module, testInstall) |
| 329 | return module, props |
| 330 | } |
| 331 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 332 | func envDefault(ctx android.BaseContext, key string, defaultValue string) string { |
| 333 | ret := ctx.AConfig().Getenv(key) |
| 334 | if ret == "" { |
| 335 | return defaultValue |
| 336 | } |
| 337 | return ret |
| 338 | } |
| 339 | |
| 340 | func envTrue(ctx android.BaseContext, key string) bool { |
| 341 | return ctx.AConfig().Getenv(key) == "true" |
| 342 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 343 | |
| 344 | func envFalse(ctx android.BaseContext, key string) bool { |
| 345 | return ctx.AConfig().Getenv(key) == "false" |
| 346 | } |