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