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