From f50bddb790424d31c7f475b072b81b98fb802bda Mon Sep 17 00:00:00 2001 From: Mitch Phillips Date: Tue, 12 Nov 2019 14:03:31 -0800 Subject: [PATCH] Prebuilt shared libraries should be collected for fuzz targets. Currently, prebuilt shared libraries fail the linkable.CcLibrary() check, as the module returned by NewPrebuiltSharedLibrary uses a prebuiltLibraryLinker as the module.linker, rather than a libraryDecorator (which is the check by CcLibrary()). We also need to ensure that we discard LLNDK stubs libraries, so we manually categorise and discard them as well. They unfortunately are are cc.Modules that aren't CcLibraries, as they use a custom linker object as well (stubDecorator). Fixes: 144415986 Test: m fuzz Change-Id: I3b85ef66d1602cb8c035a0a90bddf30674e2eb71 --- cc/fuzz.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cc/fuzz.go b/cc/fuzz.go index ef7db7981..15eafc864 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -123,19 +123,23 @@ func collectAllSharedDependencies( // Enumerate the first level of dependencies, as we discard all non-library // modules in the BFS loop below. ctx.VisitDirectDeps(module, func(dep android.Module) { - fringe = append(fringe, dep) + if isValidSharedDependency(dep, sharedDeps) { + fringe = append(fringe, dep) + } }) for i := 0; i < len(fringe); i++ { module := fringe[i] - if !isValidSharedDependency(module, sharedDeps) { + if _, exists := sharedDeps[module.Name()]; exists { continue } ccModule := module.(*Module) sharedDeps[ccModule.Name()] = ccModule.UnstrippedOutputFile() ctx.VisitDirectDeps(module, func(dep android.Module) { - fringe = append(fringe, dep) + if isValidSharedDependency(dep, sharedDeps) { + fringe = append(fringe, dep) + } }) } } @@ -155,10 +159,21 @@ func isValidSharedDependency( if linkable, ok := dependency.(LinkableInterface); !ok || // Discard non-linkables. !linkable.CcLibraryInterface() || !linkable.Shared() || // Discard static libs. linkable.UseVndk() || // Discard vendor linked libraries. - !linkable.CcLibrary() || linkable.BuildStubs() { // Discard stubs libs (only CCLibrary variants). + // Discard stubs libs (only CCLibrary variants). Prebuilt libraries should not + // be excluded on the basis of they're not CCLibrary()'s. + (linkable.CcLibrary() && linkable.BuildStubs()) { return false } + // We discarded module stubs libraries above, but the LLNDK prebuilts stubs + // libraries must be handled differently - by looking for the stubDecorator. + // Discard LLNDK prebuilts stubs as well. + if ccLibrary, isCcLibrary := dependency.(*Module); isCcLibrary { + if _, isLLndkStubLibrary := ccLibrary.linker.(*stubDecorator); isLLndkStubLibrary { + return false + } + } + // If this library has already been traversed, we don't need to do any more work. if _, exists := sharedDeps[dependency.Name()]; exists { return false