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