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 | "fmt" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 19 | "log" |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 20 | "path/filepath" |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 21 | "strings" |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 22 | "sync" |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint/proptools" |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 25 | |
| 26 | "android/soong/android" |
| 27 | "android/soong/apex" |
| 28 | "android/soong/cc" |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 29 | "android/soong/cc/config" |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
Vladimir Marko | be0d3cf | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 32 | var supportedArches = []string{"arm", "arm64", "x86", "x86_64"} |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 33 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 34 | func globalFlags(ctx android.LoadHookContext) ([]string, []string) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 35 | var cflags []string |
| 36 | var asflags []string |
| 37 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 38 | opt := ctx.Config().GetenvWithDefault("ART_NDEBUG_OPT_FLAG", "-O3") |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 39 | cflags = append(cflags, opt) |
| 40 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 41 | tlab := false |
| 42 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 43 | gcType := ctx.Config().GetenvWithDefault("ART_DEFAULT_GC_TYPE", "CMS") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 44 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 45 | if ctx.Config().IsEnvTrue("ART_TEST_DEBUG_GC") { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 46 | gcType = "SS" |
| 47 | tlab = true |
| 48 | } |
| 49 | |
| 50 | cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType) |
| 51 | if tlab { |
| 52 | cflags = append(cflags, "-DART_USE_TLAB=1") |
| 53 | } |
| 54 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 55 | if ctx.Config().IsEnvTrue("ART_HEAP_POISONING") { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 56 | cflags = append(cflags, "-DART_HEAP_POISONING=1") |
| 57 | asflags = append(asflags, "-DART_HEAP_POISONING=1") |
| 58 | } |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 59 | if ctx.Config().IsEnvTrue("ART_USE_CXX_INTERPRETER") { |
David Srbecky | 8ed45c8 | 2018-11-08 15:08:57 +0000 | [diff] [blame] | 60 | cflags = append(cflags, "-DART_USE_CXX_INTERPRETER=1") |
| 61 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 62 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 63 | if !ctx.Config().IsEnvFalse("ART_USE_READ_BARRIER") && ctx.Config().ArtUseReadBarrier() { |
Roland Levillain | b81e9e9 | 2017-04-20 17:35:32 +0100 | [diff] [blame] | 64 | // Used to change the read barrier type. Valid values are BAKER, BROOKS, |
| 65 | // TABLELOOKUP. The default is BAKER. |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 66 | barrierType := ctx.Config().GetenvWithDefault("ART_READ_BARRIER_TYPE", "BAKER") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 67 | cflags = append(cflags, |
| 68 | "-DART_USE_READ_BARRIER=1", |
| 69 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
| 70 | asflags = append(asflags, |
| 71 | "-DART_USE_READ_BARRIER=1", |
| 72 | "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 75 | if !ctx.Config().IsEnvFalse("ART_USE_GENERATIONAL_CC") { |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 76 | cflags = append(cflags, "-DART_USE_GENERATIONAL_CC=1") |
| 77 | } |
| 78 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 79 | cdexLevel := ctx.Config().GetenvWithDefault("ART_DEFAULT_COMPACT_DEX_LEVEL", "fast") |
Mathieu Chartier | 8d1a996 | 2016-08-17 16:39:45 -0700 | [diff] [blame] | 80 | cflags = append(cflags, "-DART_DEFAULT_COMPACT_DEX_LEVEL="+cdexLevel) |
Mathieu Chartier | a7f6b81 | 2017-12-11 13:34:29 -0800 | [diff] [blame] | 81 | |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 82 | // We need larger stack overflow guards for ASAN, as the compiled code will have |
| 83 | // larger frame sizes. For simplicity, just use global not-target-specific cflags. |
| 84 | // Note: We increase this for both debug and non-debug, as the overflow gap will |
| 85 | // be compiled into managed code. We always preopt (and build core images) with |
| 86 | // the debug version. So make the gap consistent (and adjust for the worst). |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 87 | if len(ctx.Config().SanitizeDevice()) > 0 || len(ctx.Config().SanitizeHost()) > 0 { |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 88 | cflags = append(cflags, |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 89 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
Evgenii Stepanov | 9e3954d | 2019-09-12 15:58:52 -0700 | [diff] [blame] | 90 | "-DART_STACK_OVERFLOW_GAP_arm64=16384", |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 91 | "-DART_STACK_OVERFLOW_GAP_x86=16384", |
| 92 | "-DART_STACK_OVERFLOW_GAP_x86_64=20480") |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 93 | } else { |
| 94 | cflags = append(cflags, |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 95 | "-DART_STACK_OVERFLOW_GAP_arm=8192", |
| 96 | "-DART_STACK_OVERFLOW_GAP_arm64=8192", |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 97 | "-DART_STACK_OVERFLOW_GAP_x86=8192", |
| 98 | "-DART_STACK_OVERFLOW_GAP_x86_64=8192") |
Andreas Gampe | 655c6fd | 2017-05-24 21:42:10 -0700 | [diff] [blame] | 99 | } |
Andreas Gampe | bc9f10c | 2017-05-19 08:28:06 -0700 | [diff] [blame] | 100 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 101 | if ctx.Config().IsEnvTrue("ART_ENABLE_ADDRESS_SANITIZER") { |
Andreas Gampe | dbf0e0f | 2017-07-11 08:34:48 -0700 | [diff] [blame] | 102 | // Used to enable full sanitization, i.e., user poisoning, under ASAN. |
| 103 | cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 104 | asflags = append(asflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 105 | } |
| 106 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 107 | if !ctx.Config().IsEnvFalse("USE_D8_DESUGAR") { |
Alan Leung | 8f514ee | 2017-12-08 14:08:25 -0800 | [diff] [blame] | 108 | cflags = append(cflags, "-DUSE_D8_DESUGAR=1") |
| 109 | } |
| 110 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 111 | return cflags, asflags |
| 112 | } |
| 113 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 114 | func debugFlags(ctx android.LoadHookContext) []string { |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 115 | var cflags []string |
| 116 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 117 | opt := ctx.Config().GetenvWithDefault("ART_DEBUG_OPT_FLAG", "-O2") |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 118 | cflags = append(cflags, opt) |
| 119 | |
| 120 | return cflags |
| 121 | } |
| 122 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 123 | func deviceFlags(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 124 | var cflags []string |
| 125 | deviceFrameSizeLimit := 1736 |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 126 | if len(ctx.Config().SanitizeDevice()) > 0 { |
Vishwath Mohan | 1ecc4fe | 2016-09-26 09:22:42 -0700 | [diff] [blame] | 127 | deviceFrameSizeLimit = 7400 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 128 | } |
| 129 | cflags = append(cflags, |
| 130 | fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit), |
| 131 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit), |
| 132 | ) |
| 133 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 134 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgDeviceBaseAddress()) |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 135 | minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 136 | maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 137 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 138 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 139 | |
| 140 | return cflags |
| 141 | } |
| 142 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 143 | func hostFlags(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 144 | var cflags []string |
| 145 | hostFrameSizeLimit := 1736 |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 146 | if len(ctx.Config().SanitizeHost()) > 0 { |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 147 | // art/test/137-cfi/cfi.cc |
| 148 | // error: stack frame size of 1944 bytes in function 'Java_Main_unwindInProcess' |
David Srbecky | 9cc67b1 | 2018-10-25 10:10:35 +0000 | [diff] [blame] | 149 | hostFrameSizeLimit = 6400 |
Colin Cross | 3174b68 | 2016-09-19 12:25:31 -0700 | [diff] [blame] | 150 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 151 | cflags = append(cflags, |
| 152 | fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit), |
| 153 | fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit), |
| 154 | ) |
| 155 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 156 | cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.Config().LibartImgHostBaseAddress()) |
| 157 | minDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000") |
| 158 | maxDelta := ctx.Config().GetenvWithDefault("LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000") |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 159 | cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta) |
| 160 | cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta) |
| 161 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 162 | if len(ctx.Config().SanitizeHost()) > 0 && !ctx.Config().IsEnvFalse("ART_ENABLE_ADDRESS_SANITIZER") { |
Andreas Gampe | fcc7d67 | 2017-07-19 10:30:22 -0700 | [diff] [blame] | 163 | // We enable full sanitization on the host by default. |
| 164 | cflags = append(cflags, "-DART_ENABLE_ADDRESS_SANITIZER=1") |
| 165 | } |
| 166 | |
David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 167 | clang_path := filepath.Join(config.ClangDefaultBase, ctx.Config().PrebuiltOS(), config.ClangDefaultVersion) |
| 168 | cflags = append(cflags, "-DART_CLANG_PATH=\""+clang_path+"\"") |
| 169 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 170 | return cflags |
| 171 | } |
| 172 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 173 | func globalDefaults(ctx android.LoadHookContext) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 174 | type props struct { |
| 175 | Target struct { |
| 176 | Android struct { |
| 177 | Cflags []string |
| 178 | } |
| 179 | Host struct { |
| 180 | Cflags []string |
| 181 | } |
| 182 | } |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 183 | Cflags []string |
| 184 | Asflags []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 185 | Sanitize struct { |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 186 | Recover []string |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 187 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | p := &props{} |
| 191 | p.Cflags, p.Asflags = globalFlags(ctx) |
| 192 | p.Target.Android.Cflags = deviceFlags(ctx) |
| 193 | p.Target.Host.Cflags = hostFlags(ctx) |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 194 | |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 195 | if ctx.Config().IsEnvTrue("ART_DEX_FILE_ACCESS_TRACKING") { |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 196 | p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING") |
Colin Cross | 2db58b6 | 2017-06-27 10:38:31 -0700 | [diff] [blame] | 197 | p.Sanitize.Recover = []string{ |
Bharadwaj Kalandhabhatta | 0bb4031 | 2017-06-01 10:47:00 -0700 | [diff] [blame] | 198 | "address", |
| 199 | } |
| 200 | } |
| 201 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 202 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 203 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 204 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 205 | // Hook that adds flags that are implicit for all cc_art_* modules. |
| 206 | func addImplicitFlags(ctx android.LoadHookContext) { |
| 207 | type props struct { |
| 208 | Target struct { |
| 209 | Android struct { |
| 210 | Cflags []string |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | p := &props{} |
| 216 | if ctx.Config().IsEnvTrue("ART_TARGET_LINUX") { |
| 217 | p.Target.Android.Cflags = []string{"-DART_TARGET", "-DART_TARGET_LINUX"} |
| 218 | } else { |
| 219 | p.Target.Android.Cflags = []string{"-DART_TARGET", "-DART_TARGET_ANDROID"} |
| 220 | } |
| 221 | |
| 222 | ctx.AppendProperties(p) |
| 223 | } |
| 224 | |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 225 | func debugDefaults(ctx android.LoadHookContext) { |
| 226 | type props struct { |
| 227 | Cflags []string |
| 228 | } |
| 229 | |
| 230 | p := &props{} |
| 231 | p.Cflags = debugFlags(ctx) |
| 232 | ctx.AppendProperties(p) |
| 233 | } |
| 234 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 235 | func customLinker(ctx android.LoadHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 236 | linker := ctx.Config().Getenv("CUSTOM_TARGET_LINKER") |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 237 | type props struct { |
| 238 | DynamicLinker string |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 239 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 240 | |
| 241 | p := &props{} |
| 242 | if linker != "" { |
| 243 | p.DynamicLinker = linker |
| 244 | } |
| 245 | |
| 246 | ctx.AppendProperties(p) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 249 | func prefer32Bit(ctx android.LoadHookContext) { |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 250 | type props struct { |
| 251 | Target struct { |
| 252 | Host struct { |
| 253 | Compile_multilib *string |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
Colin Cross | 6326d1b | 2016-09-06 10:24:28 -0700 | [diff] [blame] | 256 | } |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 257 | |
| 258 | p := &props{} |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 259 | if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") { |
Colin Cross | 84b6933 | 2017-11-01 14:23:17 -0700 | [diff] [blame] | 260 | p.Target.Host.Compile_multilib = proptools.StringPtr("prefer32") |
| 261 | } |
| 262 | |
Martin Stjernholm | e1a4451 | 2020-01-31 22:43:43 +0000 | [diff] [blame] | 263 | // Prepend to make it overridable in the blueprints. Note that it doesn't work |
| 264 | // to override the property in a cc_defaults module. |
| 265 | ctx.PrependProperties(p) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 268 | var testMapKey = android.NewOnceKey("artTests") |
| 269 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 270 | func testMap(config android.Config) map[string][]string { |
Colin Cross | b81d22d | 2019-02-06 12:42:54 -0800 | [diff] [blame] | 271 | return config.Once(testMapKey, func() interface{} { |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 272 | return make(map[string][]string) |
| 273 | }).(map[string][]string) |
| 274 | } |
| 275 | |
| 276 | func testInstall(ctx android.InstallHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 277 | testMap := testMap(ctx.Config()) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 278 | |
| 279 | var name string |
| 280 | if ctx.Host() { |
| 281 | name = "host_" |
| 282 | } else { |
| 283 | name = "device_" |
| 284 | } |
| 285 | name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName() |
| 286 | |
| 287 | artTestMutex.Lock() |
| 288 | defer artTestMutex.Unlock() |
| 289 | |
| 290 | tests := testMap[name] |
Colin Cross | 8307206 | 2019-10-02 16:06:58 -0700 | [diff] [blame] | 291 | tests = append(tests, ctx.Path().ToMakePath().String()) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 292 | testMap[name] = tests |
| 293 | } |
| 294 | |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 295 | var testcasesContentKey = android.NewOnceKey("artTestcasesContent") |
| 296 | |
| 297 | func testcasesContent(config android.Config) map[string]string { |
| 298 | return config.Once(testcasesContentKey, func() interface{} { |
| 299 | return make(map[string]string) |
| 300 | }).(map[string]string) |
| 301 | } |
| 302 | |
| 303 | // Binaries and libraries also need to be copied in the testcases directory for |
| 304 | // running tests on host. This method adds module to the list of needed files. |
| 305 | // The 'key' is the file in testcases and 'value' is the path to copy it from. |
| 306 | // The actual copy will be done in make since soong does not do installations. |
| 307 | func addTestcasesFile(ctx android.InstallHookContext) { |
Colin Cross | 71f7633 | 2021-07-20 11:57:48 -0700 | [diff] [blame] | 308 | if ctx.Os() != ctx.Config().BuildOS || ctx.Module().IsSkipInstall() { |
Martin Stjernholm | a3a828d | 2020-12-23 03:29:10 +0000 | [diff] [blame] | 309 | return |
| 310 | } |
| 311 | |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 312 | testcasesContent := testcasesContent(ctx.Config()) |
| 313 | |
| 314 | artTestMutex.Lock() |
| 315 | defer artTestMutex.Unlock() |
| 316 | |
Martin Stjernholm | a3a828d | 2020-12-23 03:29:10 +0000 | [diff] [blame] | 317 | src := ctx.SrcPath().String() |
| 318 | path := strings.Split(ctx.Path().ToMakePath().String(), "/") |
| 319 | // Keep last two parts of the install path (e.g. bin/dex2oat). |
| 320 | dst := strings.Join(path[len(path)-2:], "/") |
| 321 | if oldSrc, ok := testcasesContent[dst]; ok { |
| 322 | ctx.ModuleErrorf("Conflicting sources for %s: %s and %s", dst, oldSrc, src) |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 323 | } |
Martin Stjernholm | a3a828d | 2020-12-23 03:29:10 +0000 | [diff] [blame] | 324 | testcasesContent[dst] = src |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 327 | var artTestMutex sync.Mutex |
| 328 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 329 | func init() { |
Paul Duffin | 0c89d57 | 2019-06-27 14:21:12 +0100 | [diff] [blame] | 330 | artModuleTypes := []string{ |
| 331 | "art_cc_library", |
| 332 | "art_cc_library_static", |
| 333 | "art_cc_binary", |
| 334 | "art_cc_test", |
| 335 | "art_cc_test_library", |
| 336 | "art_cc_defaults", |
| 337 | "libart_cc_defaults", |
| 338 | "libart_static_cc_defaults", |
| 339 | "art_global_defaults", |
| 340 | "art_debug_defaults", |
Roland Levillain | 4fb71cc | 2019-09-11 18:39:59 +0100 | [diff] [blame] | 341 | "art_apex_test_host", |
Paul Duffin | 0c89d57 | 2019-06-27 14:21:12 +0100 | [diff] [blame] | 342 | } |
| 343 | android.AddNeverAllowRules( |
| 344 | android.NeverAllow(). |
| 345 | NotIn("art", "external/vixl"). |
| 346 | ModuleType(artModuleTypes...)) |
| 347 | |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 348 | android.RegisterModuleType("art_cc_library", artLibrary) |
Steven Moreland | 73030ed | 2019-01-03 14:23:28 -0800 | [diff] [blame] | 349 | android.RegisterModuleType("art_cc_library_static", artStaticLibrary) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 350 | android.RegisterModuleType("art_cc_binary", artBinary) |
| 351 | android.RegisterModuleType("art_cc_test", artTest) |
| 352 | android.RegisterModuleType("art_cc_test_library", artTestLibrary) |
| 353 | android.RegisterModuleType("art_cc_defaults", artDefaultsFactory) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 354 | android.RegisterModuleType("libart_cc_defaults", libartDefaultsFactory) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 355 | android.RegisterModuleType("libart_static_cc_defaults", libartStaticDefaultsFactory) |
Colin Cross | 96548c9 | 2016-10-12 14:26:55 -0700 | [diff] [blame] | 356 | android.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory) |
| 357 | android.RegisterModuleType("art_debug_defaults", artDebugDefaultsFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 358 | |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 359 | // ART apex is special because it must include dexpreopt files for bootclasspath jars. |
| 360 | android.RegisterModuleType("art_apex", artApexBundleFactory) |
| 361 | android.RegisterModuleType("art_apex_test", artTestApexBundleFactory) |
| 362 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 363 | // TODO: This makes the module disable itself for host if HOST_PREFER_32_BIT is |
| 364 | // set. We need this because the multilib types of binaries listed in the apex |
| 365 | // rule must match the declared type. This is normally not difficult but HOST_PREFER_32_BIT |
| 366 | // changes this to 'prefer32' on all host binaries. Since HOST_PREFER_32_BIT is |
| 367 | // only used for testing we can just disable the module. |
| 368 | // See b/120617876 for more information. |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 369 | android.RegisterModuleType("art_apex_test_host", artHostTestApexBundleFactory) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 372 | func artApexBundleFactory() android.Module { |
| 373 | return apex.ApexBundleFactory(false /*testApex*/, true /*artApex*/) |
| 374 | } |
| 375 | |
| 376 | func artTestApexBundleFactory() android.Module { |
| 377 | return apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/) |
| 378 | } |
| 379 | |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 380 | func artHostTestApexBundleFactory() android.Module { |
Ulyana Trafimovich | 7a20cbd | 2019-11-08 11:27:31 +0000 | [diff] [blame] | 381 | module := apex.ApexBundleFactory(true /*testApex*/, true /*artApex*/) |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 382 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Colin Cross | dd3b7aa | 2019-07-31 13:47:39 -0700 | [diff] [blame] | 383 | if ctx.Config().IsEnvTrue("HOST_PREFER_32_BIT") { |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 384 | type props struct { |
| 385 | Target struct { |
| 386 | Host struct { |
| 387 | Enabled *bool |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | p := &props{} |
| 393 | p.Target.Host.Enabled = proptools.BoolPtr(false) |
| 394 | ctx.AppendProperties(p) |
| 395 | log.Print("Disabling host build of " + ctx.ModuleName() + " for HOST_PREFER_32_BIT=true") |
| 396 | } |
| 397 | }) |
| 398 | |
| 399 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 402 | func artGlobalDefaultsFactory() android.Module { |
| 403 | module := artDefaultsFactory() |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 404 | android.AddLoadHook(module, addImplicitFlags) |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 405 | android.AddLoadHook(module, globalDefaults) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 406 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 407 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 410 | func artDebugDefaultsFactory() android.Module { |
| 411 | module := artDefaultsFactory() |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 412 | android.AddLoadHook(module, debugDefaults) |
| 413 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 414 | return module |
Colin Cross | be332ed | 2016-09-21 13:23:53 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 417 | func artDefaultsFactory() android.Module { |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 418 | c := &codegenProperties{} |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 419 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 420 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) }) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 421 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 422 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 425 | func libartDefaultsFactory() android.Module { |
| 426 | c := &codegenProperties{} |
| 427 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 428 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticAndSharedLibrary) }) |
Nicolas Geoffray | 8a22907 | 2018-05-10 16:34:14 +0100 | [diff] [blame] | 429 | |
| 430 | return module |
| 431 | } |
| 432 | |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 433 | func libartStaticDefaultsFactory() android.Module { |
| 434 | c := &codegenProperties{} |
| 435 | module := cc.DefaultsFactory(c) |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 436 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, staticLibrary) }) |
Andreas Gampe | ec5ed06 | 2018-01-26 16:20:02 -0800 | [diff] [blame] | 437 | |
| 438 | return module |
| 439 | } |
| 440 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 441 | func artLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 442 | module := cc.LibraryFactory() |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 443 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 444 | installCodegenCustomizer(module, staticAndSharedLibrary) |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 445 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 446 | android.AddLoadHook(module, addImplicitFlags) |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 447 | android.AddInstallHook(module, addTestcasesFile) |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 448 | return module |
| 449 | } |
| 450 | |
| 451 | func artStaticLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 452 | module := cc.LibraryStaticFactory() |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 453 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 454 | installCodegenCustomizer(module, staticLibrary) |
Colin Cross | fe6064a | 2016-08-30 13:49:26 -0700 | [diff] [blame] | 455 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 456 | android.AddLoadHook(module, addImplicitFlags) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 457 | return module |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 460 | func artBinary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 461 | module := cc.BinaryFactory() |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 462 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 463 | android.AddLoadHook(module, addImplicitFlags) |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 464 | android.AddLoadHook(module, customLinker) |
| 465 | android.AddLoadHook(module, prefer32Bit) |
David Srbecky | 1cf46a3 | 2020-06-22 15:39:00 +0100 | [diff] [blame] | 466 | android.AddInstallHook(module, addTestcasesFile) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 467 | return module |
Colin Cross | 123989f | 2016-09-07 14:12:50 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 470 | func artTest() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 471 | module := cc.TestFactory() |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 472 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 473 | installCodegenCustomizer(module, binary) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 474 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 475 | android.AddLoadHook(module, addImplicitFlags) |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 476 | android.AddLoadHook(module, customLinker) |
| 477 | android.AddLoadHook(module, prefer32Bit) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 478 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 479 | return module |
Colin Cross | c7376e0 | 2016-09-08 12:52:18 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 482 | func artTestLibrary() android.Module { |
Paul Duffin | e78b50e | 2020-02-18 12:25:40 +0000 | [diff] [blame] | 483 | module := cc.TestLibraryFactory() |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 484 | |
Colin Cross | f383ed8 | 2019-09-24 15:02:23 -0700 | [diff] [blame] | 485 | installCodegenCustomizer(module, staticAndSharedLibrary) |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 486 | |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 487 | android.AddLoadHook(module, addImplicitFlags) |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 488 | android.AddLoadHook(module, prefer32Bit) |
| 489 | android.AddInstallHook(module, testInstall) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 490 | return module |
Colin Cross | afd3c9e | 2016-09-16 13:47:21 -0700 | [diff] [blame] | 491 | } |