Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All rights reserved. |
| 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 cc |
| 16 | |
| 17 | import ( |
Mitch Phillips | 4de896e | 2019-08-28 16:04:36 -0700 | [diff] [blame] | 18 | "path/filepath" |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 19 | "sort" |
Mitch Phillips | a0a5e19 | 2019-09-27 14:00:06 -0700 | [diff] [blame] | 20 | "strings" |
Mitch Phillips | 4de896e | 2019-08-28 16:04:36 -0700 | [diff] [blame] | 21 | |
Victor Chang | 00c144f | 2021-02-09 12:30:33 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 24 | "android/soong/android" |
| 25 | "android/soong/cc/config" |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 26 | "android/soong/fuzz" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func init() { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 30 | android.RegisterModuleType("cc_afl_fuzz", AFLFuzzFactory) |
| 31 | android.RegisterModuleType("cc_fuzz", LibFuzzFactory) |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 32 | android.RegisterSingletonType("cc_fuzz_packaging", fuzzPackagingFactory) |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 33 | android.RegisterSingletonType("cc_afl_fuzz_packaging", fuzzAFLPackagingFactory) |
| 34 | } |
| 35 | |
| 36 | var ( |
| 37 | neededAFLTools = map[string]bool{"afl-fuzz": true, "afl-showmap": true} |
| 38 | ) |
| 39 | |
| 40 | type FuzzProperties struct { |
| 41 | AFLEnabled bool `blueprint:"mutated"` |
| 42 | AFLAddFlags bool `blueprint:"mutated"` |
| 43 | } |
| 44 | |
| 45 | type fuzzer struct { |
| 46 | Properties FuzzProperties |
| 47 | } |
| 48 | |
| 49 | func (fuzzer *fuzzer) flags(ctx ModuleContext, flags Flags) Flags { |
| 50 | if fuzzer.Properties.AFLAddFlags { |
| 51 | flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-coverage=trace-pc-guard") |
| 52 | } |
| 53 | |
| 54 | return flags |
| 55 | } |
| 56 | |
| 57 | func (fuzzer *fuzzer) props() []interface{} { |
| 58 | return []interface{}{&fuzzer.Properties} |
| 59 | } |
| 60 | |
| 61 | func fuzzMutatorDeps(mctx android.TopDownMutatorContext) { |
| 62 | currentModule, ok := mctx.Module().(*Module) |
| 63 | if !ok { |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | if currentModule.fuzzer == nil || !currentModule.fuzzer.Properties.AFLEnabled { |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | mctx.WalkDeps(func(child android.Module, parent android.Module) bool { |
| 72 | c, ok := child.(*Module) |
| 73 | if !ok { |
| 74 | return false |
| 75 | } |
| 76 | |
| 77 | if c.sanitize == nil { |
| 78 | return false |
| 79 | } |
| 80 | |
| 81 | isFuzzerPointer := c.sanitize.getSanitizerBoolPtr(Fuzzer) |
| 82 | if isFuzzerPointer == nil || !*isFuzzerPointer { |
| 83 | return false |
| 84 | } |
| 85 | |
| 86 | if c.fuzzer == nil { |
| 87 | return false |
| 88 | } |
| 89 | |
| 90 | c.fuzzer.Properties.AFLEnabled = true |
| 91 | c.fuzzer.Properties.AFLAddFlags = true |
| 92 | return true |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | func fuzzMutator(mctx android.BottomUpMutatorContext) { |
| 97 | if c, ok := mctx.Module().(*Module); ok && c.fuzzer != nil { |
| 98 | if !c.fuzzer.Properties.AFLEnabled { |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | if c.Binary() { |
| 103 | m := mctx.CreateVariations("afl") |
| 104 | m[0].(*Module).fuzzer.Properties.AFLEnabled = true |
| 105 | m[0].(*Module).fuzzer.Properties.AFLAddFlags = true |
| 106 | } else { |
| 107 | m := mctx.CreateVariations("", "afl") |
| 108 | m[0].(*Module).fuzzer.Properties.AFLEnabled = false |
| 109 | m[0].(*Module).fuzzer.Properties.AFLAddFlags = false |
| 110 | |
| 111 | m[1].(*Module).fuzzer.Properties.AFLEnabled = true |
| 112 | m[1].(*Module).fuzzer.Properties.AFLAddFlags = true |
| 113 | } |
| 114 | } |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // cc_fuzz creates a host/device fuzzer binary. Host binaries can be found at |
| 118 | // $ANDROID_HOST_OUT/fuzz/, and device binaries can be found at /data/fuzz on |
| 119 | // your device, or $ANDROID_PRODUCT_OUT/data/fuzz in your build tree. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 120 | func LibFuzzFactory() android.Module { |
| 121 | module := NewFuzzer(android.HostAndDeviceSupported, fuzz.Cc) |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 122 | return module.Init() |
| 123 | } |
| 124 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 125 | // cc_afl_fuzz creates a host/device AFL++ fuzzer binary. |
| 126 | // AFL++ is an open source framework used to fuzz libraries |
| 127 | // Host binaries can be found at $ANDROID_HOST_OUT/afl_fuzz/ and device |
| 128 | // binaries can be found at $ANDROID_PRODUCT_OUT/data/afl_fuzz in your |
| 129 | // build tree |
| 130 | func AFLFuzzFactory() android.Module { |
| 131 | module := NewFuzzer(android.HostAndDeviceSupported, fuzz.AFL) |
| 132 | return module.Init() |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | type fuzzBinary struct { |
| 136 | *binaryDecorator |
| 137 | *baseCompiler |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 138 | fuzzPackagedModule fuzz.FuzzPackagedModule |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 139 | installedSharedDeps []string |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 140 | fuzzType fuzz.FuzzType |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 143 | func (fuzz *fuzzBinary) fuzzBinary() bool { |
| 144 | return true |
| 145 | } |
| 146 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 147 | func (fuzz *fuzzBinary) linkerProps() []interface{} { |
| 148 | props := fuzz.binaryDecorator.linkerProps() |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 149 | props = append(props, &fuzz.fuzzPackagedModule.FuzzProperties) |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 150 | return props |
| 151 | } |
| 152 | |
| 153 | func (fuzz *fuzzBinary) linkerInit(ctx BaseModuleContext) { |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 154 | fuzz.binaryDecorator.linkerInit(ctx) |
| 155 | } |
| 156 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 157 | func (fuzzBin *fuzzBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { |
| 158 | if fuzzBin.fuzzType == fuzz.AFL { |
| 159 | deps.HeaderLibs = append(deps.HeaderLibs, "libafl_headers") |
| 160 | deps = fuzzBin.binaryDecorator.linkerDeps(ctx, deps) |
| 161 | return deps |
| 162 | |
| 163 | } else { |
| 164 | deps.StaticLibs = append(deps.StaticLibs, config.LibFuzzerRuntimeLibrary(ctx.toolchain())) |
| 165 | deps = fuzzBin.binaryDecorator.linkerDeps(ctx, deps) |
| 166 | return deps |
| 167 | } |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 171 | flags = fuzz.binaryDecorator.linkerFlags(ctx, flags) |
Mitch Phillips | 1f7f54f | 2019-11-14 14:50:47 -0800 | [diff] [blame] | 172 | // RunPaths on devices isn't instantiated by the base linker. `../lib` for |
| 173 | // installed fuzz targets (both host and device), and `./lib` for fuzz |
| 174 | // target packages. |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 175 | flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/../lib`) |
Mitch Phillips | 1f7f54f | 2019-11-14 14:50:47 -0800 | [diff] [blame] | 176 | flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/lib`) |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 177 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 178 | return flags |
| 179 | } |
| 180 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 181 | func UnstrippedOutputFile(module android.Module) android.Path { |
| 182 | if mod, ok := module.(LinkableInterface); ok { |
| 183 | return mod.UnstrippedOutputFile() |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 184 | } |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 185 | panic("UnstrippedOutputFile called on non-LinkableInterface module: " + module.Name()) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 188 | // IsValidSharedDependency takes a module and determines if it is a unique shared library |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 189 | // that should be installed in the fuzz target output directories. This function |
| 190 | // returns true, unless: |
Victor Chang | 00c144f | 2021-02-09 12:30:33 +0000 | [diff] [blame] | 191 | // - The module is not an installable shared library, or |
Kris Alder | 756ec8d | 2021-08-27 22:08:29 +0000 | [diff] [blame] | 192 | // - The module is a header or stub, or |
Martin Stjernholm | 02460ab | 2020-10-06 02:36:43 +0100 | [diff] [blame] | 193 | // - The module is a prebuilt and its source is available, or |
| 194 | // - The module is a versioned member of an SDK snapshot. |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 195 | func IsValidSharedDependency(dependency android.Module) bool { |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 196 | // TODO(b/144090547): We should be parsing these modules using |
| 197 | // ModuleDependencyTag instead of the current brute-force checking. |
| 198 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 199 | linkable, ok := dependency.(LinkableInterface) |
| 200 | if !ok || !linkable.CcLibraryInterface() { |
| 201 | // Discard non-linkables. |
| 202 | return false |
| 203 | } |
| 204 | |
| 205 | if !linkable.Shared() { |
| 206 | // Discard static libs. |
| 207 | return false |
| 208 | } |
| 209 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 210 | if lib := moduleLibraryInterface(dependency); lib != nil && lib.buildStubs() && linkable.CcLibrary() { |
Mitch Phillips | f50bddb | 2019-11-12 14:03:31 -0800 | [diff] [blame] | 211 | // Discard stubs libs (only CCLibrary variants). Prebuilt libraries should not |
| 212 | // be excluded on the basis of they're not CCLibrary()'s. |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 213 | return false |
| 214 | } |
| 215 | |
Mitch Phillips | f50bddb | 2019-11-12 14:03:31 -0800 | [diff] [blame] | 216 | // We discarded module stubs libraries above, but the LLNDK prebuilts stubs |
| 217 | // libraries must be handled differently - by looking for the stubDecorator. |
| 218 | // Discard LLNDK prebuilts stubs as well. |
| 219 | if ccLibrary, isCcLibrary := dependency.(*Module); isCcLibrary { |
| 220 | if _, isLLndkStubLibrary := ccLibrary.linker.(*stubDecorator); isLLndkStubLibrary { |
| 221 | return false |
| 222 | } |
Victor Chang | 00c144f | 2021-02-09 12:30:33 +0000 | [diff] [blame] | 223 | // Discard installable:false libraries because they are expected to be absent |
| 224 | // in runtime. |
Colin Cross | 1bc9412 | 2021-10-28 13:25:54 -0700 | [diff] [blame] | 225 | if !proptools.BoolDefault(ccLibrary.Installable(), true) { |
Victor Chang | 00c144f | 2021-02-09 12:30:33 +0000 | [diff] [blame] | 226 | return false |
| 227 | } |
Mitch Phillips | f50bddb | 2019-11-12 14:03:31 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Martin Stjernholm | 02460ab | 2020-10-06 02:36:43 +0100 | [diff] [blame] | 230 | // If the same library is present both as source and a prebuilt we must pick |
| 231 | // only one to avoid a conflict. Always prefer the source since the prebuilt |
| 232 | // probably won't be built with sanitizers enabled. |
Paul Duffin | f7c99f5 | 2021-04-28 10:41:21 +0100 | [diff] [blame] | 233 | if prebuilt := android.GetEmbeddedPrebuilt(dependency); prebuilt != nil && prebuilt.SourceExists() { |
Martin Stjernholm | 02460ab | 2020-10-06 02:36:43 +0100 | [diff] [blame] | 234 | return false |
| 235 | } |
| 236 | |
| 237 | // Discard versioned members of SDK snapshots, because they will conflict with |
| 238 | // unversioned ones. |
| 239 | if sdkMember, ok := dependency.(android.SdkAware); ok && !sdkMember.ContainingSdk().Unversioned() { |
| 240 | return false |
| 241 | } |
| 242 | |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 243 | return true |
| 244 | } |
| 245 | |
| 246 | func sharedLibraryInstallLocation( |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 247 | libraryPath android.Path, isHost bool, fuzzDir string, archString string) string { |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 248 | installLocation := "$(PRODUCT_OUT)/data" |
| 249 | if isHost { |
| 250 | installLocation = "$(HOST_OUT)" |
| 251 | } |
| 252 | installLocation = filepath.Join( |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 253 | installLocation, fuzzDir, archString, "lib", libraryPath.Base()) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 254 | return installLocation |
| 255 | } |
| 256 | |
Mitch Phillips | 0bf9713 | 2020-03-06 09:38:12 -0800 | [diff] [blame] | 257 | // Get the device-only shared library symbols install directory. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 258 | func sharedLibrarySymbolsInstallLocation(libraryPath android.Path, fuzzDir string, archString string) string { |
| 259 | return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryPath.Base()) |
Mitch Phillips | 0bf9713 | 2020-03-06 09:38:12 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 262 | func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) { |
| 263 | installBase := "fuzz" |
| 264 | if fuzzBin.fuzzType == fuzz.AFL { |
| 265 | installBase = "afl_fuzz" |
| 266 | } |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 267 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 268 | fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join( |
| 269 | installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName()) |
| 270 | fuzzBin.binaryDecorator.baseInstaller.dir64 = filepath.Join( |
| 271 | installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName()) |
| 272 | fuzzBin.binaryDecorator.baseInstaller.install(ctx, file) |
| 273 | |
| 274 | fuzzBin.fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzzBin.fuzzPackagedModule.FuzzProperties.Corpus) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 275 | builder := android.NewRuleBuilder(pctx, ctx) |
Mitch Phillips | 8a2bc0b | 2019-10-17 15:04:01 -0700 | [diff] [blame] | 276 | intermediateDir := android.PathForModuleOut(ctx, "corpus") |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 277 | for _, entry := range fuzzBin.fuzzPackagedModule.Corpus { |
Mitch Phillips | 8a2bc0b | 2019-10-17 15:04:01 -0700 | [diff] [blame] | 278 | builder.Command().Text("cp"). |
| 279 | Input(entry). |
| 280 | Output(intermediateDir.Join(ctx, entry.Base())) |
| 281 | } |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 282 | builder.Build("copy_corpus", "copy corpus") |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 283 | fuzzBin.fuzzPackagedModule.CorpusIntermediateDir = intermediateDir |
Mitch Phillips | 8a2bc0b | 2019-10-17 15:04:01 -0700 | [diff] [blame] | 284 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 285 | fuzzBin.fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzBin.fuzzPackagedModule.FuzzProperties.Data) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 286 | builder = android.NewRuleBuilder(pctx, ctx) |
Tri Vo | ad172d8 | 2019-11-27 13:45:45 -0800 | [diff] [blame] | 287 | intermediateDir = android.PathForModuleOut(ctx, "data") |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 288 | for _, entry := range fuzzBin.fuzzPackagedModule.Data { |
Tri Vo | ad172d8 | 2019-11-27 13:45:45 -0800 | [diff] [blame] | 289 | builder.Command().Text("cp"). |
| 290 | Input(entry). |
| 291 | Output(intermediateDir.Join(ctx, entry.Rel())) |
| 292 | } |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 293 | builder.Build("copy_data", "copy data") |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 294 | fuzzBin.fuzzPackagedModule.DataIntermediateDir = intermediateDir |
Tri Vo | ad172d8 | 2019-11-27 13:45:45 -0800 | [diff] [blame] | 295 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 296 | if fuzzBin.fuzzPackagedModule.FuzzProperties.Dictionary != nil { |
| 297 | fuzzBin.fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzzBin.fuzzPackagedModule.FuzzProperties.Dictionary) |
| 298 | if fuzzBin.fuzzPackagedModule.Dictionary.Ext() != ".dict" { |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 299 | ctx.PropertyErrorf("dictionary", |
| 300 | "Fuzzer dictionary %q does not have '.dict' extension", |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 301 | fuzzBin.fuzzPackagedModule.Dictionary.String()) |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
Kris Alder | f979ee3 | 2019-10-22 10:52:01 -0700 | [diff] [blame] | 304 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 305 | if fuzzBin.fuzzPackagedModule.FuzzProperties.Fuzz_config != nil { |
Kris Alder | db97af4 | 2019-10-30 10:17:04 -0700 | [diff] [blame] | 306 | configPath := android.PathForModuleOut(ctx, "config").Join(ctx, "config.json") |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 307 | android.WriteFileRule(ctx, configPath, fuzzBin.fuzzPackagedModule.FuzzProperties.Fuzz_config.String()) |
| 308 | fuzzBin.fuzzPackagedModule.Config = configPath |
Kris Alder | f979ee3 | 2019-10-22 10:52:01 -0700 | [diff] [blame] | 309 | } |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 310 | |
| 311 | // Grab the list of required shared libraries. |
Mitch Phillips | c0b442f | 2020-04-27 16:44:58 -0700 | [diff] [blame] | 312 | seen := make(map[string]bool) |
Colin Cross | dc809f9 | 2019-11-20 15:58:32 -0800 | [diff] [blame] | 313 | var sharedLibraries android.Paths |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 314 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Mitch Phillips | c0b442f | 2020-04-27 16:44:58 -0700 | [diff] [blame] | 315 | if seen[child.Name()] { |
Colin Cross | dc809f9 | 2019-11-20 15:58:32 -0800 | [diff] [blame] | 316 | return false |
| 317 | } |
Mitch Phillips | c0b442f | 2020-04-27 16:44:58 -0700 | [diff] [blame] | 318 | seen[child.Name()] = true |
Colin Cross | dc809f9 | 2019-11-20 15:58:32 -0800 | [diff] [blame] | 319 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 320 | if IsValidSharedDependency(child) { |
Colin Cross | dc809f9 | 2019-11-20 15:58:32 -0800 | [diff] [blame] | 321 | sharedLibraries = append(sharedLibraries, child.(*Module).UnstrippedOutputFile()) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 322 | return true |
| 323 | } |
| 324 | return false |
| 325 | }) |
| 326 | |
| 327 | for _, lib := range sharedLibraries { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 328 | fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps, |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 329 | sharedLibraryInstallLocation( |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 330 | lib, ctx.Host(), installBase, ctx.Arch().ArchType.String())) |
Mitch Phillips | 0bf9713 | 2020-03-06 09:38:12 -0800 | [diff] [blame] | 331 | |
| 332 | // Also add the dependency on the shared library symbols dir. |
| 333 | if !ctx.Host() { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 334 | fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps, |
| 335 | sharedLibrarySymbolsInstallLocation(lib, installBase, ctx.Arch().ArchType.String())) |
Mitch Phillips | 0bf9713 | 2020-03-06 09:38:12 -0800 | [diff] [blame] | 336 | } |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 337 | } |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 340 | func NewFuzzer(hod android.HostOrDeviceSupported, fuzzType fuzz.FuzzType) *Module { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 341 | module, binary := newBinary(hod, false) |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 342 | baseInstallerPath := "fuzz" |
| 343 | if fuzzType == fuzz.AFL { |
| 344 | baseInstallerPath = "afl_fuzz" |
| 345 | } |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 346 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 347 | binary.baseInstaller = NewBaseInstaller(baseInstallerPath, baseInstallerPath, InstallInData) |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 348 | module.sanitize.SetSanitizer(Fuzzer, true) |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 349 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 350 | fuzzBin := &fuzzBinary{ |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 351 | binaryDecorator: binary, |
| 352 | baseCompiler: NewBaseCompiler(), |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 353 | fuzzType: fuzzType, |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 354 | } |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 355 | module.compiler = fuzzBin |
| 356 | module.linker = fuzzBin |
| 357 | module.installer = fuzzBin |
Colin Cross | eec9b28 | 2019-07-18 16:20:52 -0700 | [diff] [blame] | 358 | |
| 359 | // The fuzzer runtime is not present for darwin host modules, disable cc_fuzz modules when targeting darwin. |
| 360 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Alex Light | 71123ec | 2019-07-24 13:34:19 -0700 | [diff] [blame] | 361 | disableDarwinAndLinuxBionic := struct { |
Colin Cross | eec9b28 | 2019-07-18 16:20:52 -0700 | [diff] [blame] | 362 | Target struct { |
| 363 | Darwin struct { |
| 364 | Enabled *bool |
| 365 | } |
Alex Light | 71123ec | 2019-07-24 13:34:19 -0700 | [diff] [blame] | 366 | Linux_bionic struct { |
| 367 | Enabled *bool |
| 368 | } |
Colin Cross | eec9b28 | 2019-07-18 16:20:52 -0700 | [diff] [blame] | 369 | } |
| 370 | }{} |
Alex Light | 71123ec | 2019-07-24 13:34:19 -0700 | [diff] [blame] | 371 | disableDarwinAndLinuxBionic.Target.Darwin.Enabled = BoolPtr(false) |
| 372 | disableDarwinAndLinuxBionic.Target.Linux_bionic.Enabled = BoolPtr(false) |
| 373 | ctx.AppendProperties(&disableDarwinAndLinuxBionic) |
Colin Cross | eec9b28 | 2019-07-18 16:20:52 -0700 | [diff] [blame] | 374 | }) |
| 375 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 376 | if fuzzType == fuzz.AFL { |
| 377 | // Add cc_objects to Srcs |
| 378 | fuzzBin.baseCompiler.Properties.Srcs = append(fuzzBin.baseCompiler.Properties.Srcs, ":aflpp_driver", ":afl-compiler-rt") |
| 379 | module.fuzzer.Properties.AFLEnabled = true |
| 380 | module.compiler.appendCflags([]string{ |
| 381 | "-Wno-unused-result", |
| 382 | "-Wno-unused-parameter", |
| 383 | "-Wno-unused-function", |
| 384 | }) |
| 385 | } |
| 386 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 387 | return module |
| 388 | } |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 389 | |
| 390 | // Responsible for generating GNU Make rules that package fuzz targets into |
| 391 | // their architecture & target/host specific zip file. |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 392 | type ccFuzzPackager struct { |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 393 | fuzz.FuzzPackager |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 394 | fuzzPackagingArchModules string |
| 395 | fuzzTargetSharedDepsInstallPairs string |
| 396 | allFuzzTargetsName string |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | func fuzzPackagingFactory() android.Singleton { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 400 | |
| 401 | fuzzPackager := &ccFuzzPackager{ |
| 402 | fuzzPackagingArchModules: "SOONG_FUZZ_PACKAGING_ARCH_MODULES", |
| 403 | fuzzTargetSharedDepsInstallPairs: "FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS", |
| 404 | allFuzzTargetsName: "ALL_FUZZ_TARGETS", |
| 405 | } |
| 406 | fuzzPackager.FuzzType = fuzz.Cc |
| 407 | return fuzzPackager |
| 408 | } |
| 409 | |
| 410 | func fuzzAFLPackagingFactory() android.Singleton { |
| 411 | fuzzPackager := &ccFuzzPackager{ |
| 412 | fuzzPackagingArchModules: "SOONG_AFL_FUZZ_PACKAGING_ARCH_MODULES", |
| 413 | fuzzTargetSharedDepsInstallPairs: "AFL_FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS", |
| 414 | allFuzzTargetsName: "ALL_AFL_FUZZ_TARGETS", |
| 415 | } |
| 416 | fuzzPackager.FuzzType = fuzz.AFL |
| 417 | return fuzzPackager |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 418 | } |
| 419 | |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 420 | func (s *ccFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) { |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 421 | // Map between each architecture + host/device combination, and the files that |
| 422 | // need to be packaged (in the tuple of {source file, destination folder in |
| 423 | // archive}). |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 424 | archDirs := make(map[fuzz.ArchOs][]fuzz.FileToZip) |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 425 | |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 426 | // List of individual fuzz targets, so that 'make fuzz' also installs the targets |
| 427 | // to the correct output directories as well. |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 428 | s.FuzzTargets = make(map[string]bool) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 429 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 430 | // Map tracking whether each shared library has an install rule to avoid duplicate install rules from |
| 431 | // multiple fuzzers that depend on the same shared library. |
| 432 | sharedLibraryInstalled := make(map[string]bool) |
| 433 | |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 434 | ctx.VisitAllModules(func(module android.Module) { |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 435 | ccModule, ok := module.(*Module) |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 436 | if !ok || ccModule.Properties.PreventInstall { |
| 437 | return |
| 438 | } |
| 439 | |
| 440 | // Discard non-fuzz targets. |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 441 | if ok := fuzz.IsValid(ccModule.FuzzModule); !ok { |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 442 | return |
| 443 | } |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 444 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 445 | sharedLibsInstallDirPrefix := "lib" |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 446 | fuzzModule, ok := ccModule.compiler.(*fuzzBinary) |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 447 | if !ok || fuzzModule.fuzzType != s.FuzzType { |
| 448 | // check is module is a tool needed to be zipped for AFL |
| 449 | if _, aflTool := neededAFLTools[ccModule.Name()]; aflTool && s.FuzzType == fuzz.AFL { |
| 450 | sharedLibsInstallDirPrefix = "lib64" |
| 451 | } else { |
| 452 | return |
| 453 | } |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 456 | hostOrTargetString := "target" |
| 457 | if ccModule.Host() { |
| 458 | hostOrTargetString = "host" |
| 459 | } |
| 460 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 461 | fpm := fuzz.FuzzPackagedModule{} |
| 462 | if ok { |
| 463 | fpm = fuzzModule.fuzzPackagedModule |
| 464 | } |
| 465 | |
| 466 | intermediatePath := "fuzz" |
| 467 | if s.FuzzType == fuzz.AFL { |
| 468 | intermediatePath = "afl_fuzz" |
| 469 | } |
| 470 | |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 471 | archString := ccModule.Arch().ArchType.String() |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 472 | archDir := android.PathForIntermediates(ctx, intermediatePath, hostOrTargetString, archString) |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 473 | archOs := fuzz.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()} |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 474 | |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 475 | // Grab the list of required shared libraries. |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 476 | sharedLibraries := fuzz.CollectAllSharedDependencies(ctx, module, UnstrippedOutputFile, IsValidSharedDependency) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 477 | |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 478 | var files []fuzz.FileToZip |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 479 | builder := android.NewRuleBuilder(pctx, ctx) |
Mitch Phillips | 2edbe8e | 2019-11-13 08:36:07 -0800 | [diff] [blame] | 480 | |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 481 | // Package the corpus, data, dict and config into a zipfile. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 482 | files = s.PackageArtifacts(ctx, module, fpm, archDir, builder) |
Tri Vo | ad172d8 | 2019-11-27 13:45:45 -0800 | [diff] [blame] | 483 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 484 | // Package shared libraries |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 485 | files = append(files, GetSharedLibsToZip(sharedLibraries, ccModule, &s.FuzzPackager, archString, sharedLibsInstallDirPrefix, &sharedLibraryInstalled)...) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 486 | |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 487 | // The executable. |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 488 | files = append(files, fuzz.FileToZip{ccModule.UnstrippedOutputFile(), ""}) |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 489 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 490 | archDirs[archOs], ok = s.BuildZipFile(ctx, module, fpm, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs) |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 491 | if !ok { |
| 492 | return |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 493 | } |
| 494 | }) |
| 495 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 496 | s.CreateFuzzPackage(ctx, archDirs, s.FuzzType, pctx) |
Mitch Phillips | a0a5e19 | 2019-09-27 14:00:06 -0700 | [diff] [blame] | 497 | } |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 498 | |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 499 | func (s *ccFuzzPackager) MakeVars(ctx android.MakeVarsContext) { |
| 500 | packages := s.Packages.Strings() |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 501 | sort.Strings(packages) |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 502 | sort.Strings(s.FuzzPackager.SharedLibInstallStrings) |
Mitch Phillips | a0a5e19 | 2019-09-27 14:00:06 -0700 | [diff] [blame] | 503 | // TODO(mitchp): Migrate this to use MakeVarsContext::DistForGoal() when it's |
| 504 | // ready to handle phony targets created in Soong. In the meantime, this |
| 505 | // exports the phony 'fuzz' target and dependencies on packages to |
| 506 | // core/main.mk so that we can use dist-for-goals. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 507 | if s.FuzzType == fuzz.AFL { |
| 508 | s.FuzzTargets["afl-fuzz"] = true |
| 509 | s.FuzzTargets["afl-showmap"] = true |
| 510 | } |
| 511 | |
| 512 | ctx.Strict(s.fuzzPackagingArchModules, strings.Join(packages, " ")) |
| 513 | |
| 514 | ctx.Strict(s.fuzzTargetSharedDepsInstallPairs, |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 515 | strings.Join(s.FuzzPackager.SharedLibInstallStrings, " ")) |
Mitch Phillips | e1ee1a1 | 2019-10-17 19:20:41 -0700 | [diff] [blame] | 516 | |
| 517 | // Preallocate the slice of fuzz targets to minimise memory allocations. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 518 | s.PreallocateSlice(ctx, s.allFuzzTargetsName) |
Mitch Phillips | d3254b4 | 2019-09-24 13:03:28 -0700 | [diff] [blame] | 519 | } |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 520 | |
| 521 | // GetSharedLibsToZip finds and marks all the transiently-dependent shared libraries for |
| 522 | // packaging. |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 523 | func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, s *fuzz.FuzzPackager, archString string, destinationPathPrefix string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip { |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 524 | var files []fuzz.FileToZip |
| 525 | |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 526 | fuzzDir := "fuzz" |
| 527 | if s.FuzzType == fuzz.AFL { |
| 528 | fuzzDir = "afl_fuzz" |
| 529 | } |
| 530 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 531 | for _, library := range sharedLibraries { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 532 | files = append(files, fuzz.FileToZip{library, destinationPathPrefix}) |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 533 | |
| 534 | // For each architecture-specific shared library dependency, we need to |
| 535 | // install it to the output directory. Setup the install destination here, |
| 536 | // which will be used by $(copy-many-files) in the Make backend. |
| 537 | installDestination := sharedLibraryInstallLocation( |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 538 | library, module.Host(), fuzzDir, archString) |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 539 | if (*sharedLibraryInstalled)[installDestination] { |
| 540 | continue |
| 541 | } |
| 542 | (*sharedLibraryInstalled)[installDestination] = true |
| 543 | |
| 544 | // Escape all the variables, as the install destination here will be called |
| 545 | // via. $(eval) in Make. |
| 546 | installDestination = strings.ReplaceAll( |
| 547 | installDestination, "$", "$$") |
| 548 | s.SharedLibInstallStrings = append(s.SharedLibInstallStrings, |
| 549 | library.String()+":"+installDestination) |
| 550 | |
| 551 | // Ensure that on device, the library is also reinstalled to the /symbols/ |
| 552 | // dir. Symbolized DSO's are always installed to the device when fuzzing, but |
| 553 | // we want symbolization tools (like `stack`) to be able to find the symbols |
| 554 | // in $ANDROID_PRODUCT_OUT/symbols automagically. |
| 555 | if !module.Host() { |
Cory Barker | f4b1c3a | 2022-06-07 20:12:06 +0000 | [diff] [blame^] | 556 | symbolsInstallDestination := sharedLibrarySymbolsInstallLocation(library, fuzzDir, archString) |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 557 | symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$") |
| 558 | s.SharedLibInstallStrings = append(s.SharedLibInstallStrings, |
| 559 | library.String()+":"+symbolsInstallDestination) |
| 560 | } |
| 561 | } |
| 562 | return files |
| 563 | } |