Merge "fuzz packaging: implement system/vendor split" into main
This commit is contained in:
52
cc/fuzz.go
52
cc/fuzz.go
@@ -144,20 +144,25 @@ func (fuzzBin *fuzzBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
subdir := "lib"
|
||||||
|
if ctx.inVendor() {
|
||||||
|
subdir = "lib/vendor"
|
||||||
|
}
|
||||||
|
|
||||||
flags = fuzz.binaryDecorator.linkerFlags(ctx, flags)
|
flags = fuzz.binaryDecorator.linkerFlags(ctx, flags)
|
||||||
// RunPaths on devices isn't instantiated by the base linker. `../lib` for
|
// RunPaths on devices isn't instantiated by the base linker. `../lib` for
|
||||||
// installed fuzz targets (both host and device), and `./lib` for fuzz
|
// installed fuzz targets (both host and device), and `./lib` for fuzz
|
||||||
// target packages.
|
// target packages.
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/lib`)
|
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/`+subdir)
|
||||||
|
|
||||||
// When running on device, fuzz targets with vendor: true set will be in
|
// When running on device, fuzz targets with vendor: true set will be in
|
||||||
// fuzzer_name/vendor/fuzzer_name (note the extra 'vendor' and thus need to
|
// fuzzer_name/vendor/fuzzer_name (note the extra 'vendor' and thus need to
|
||||||
// link with libraries in ../../lib/. Non-vendor binaries only need to look
|
// link with libraries in ../../lib/. Non-vendor binaries only need to look
|
||||||
// one level up, in ../lib/.
|
// one level up, in ../lib/.
|
||||||
if ctx.inVendor() {
|
if ctx.inVendor() {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/../../lib`)
|
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/../../`+subdir)
|
||||||
} else {
|
} else {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/../lib`)
|
flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN/../`+subdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
@@ -221,19 +226,27 @@ func IsValidSharedDependency(dependency android.Module) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SharedLibraryInstallLocation(
|
func SharedLibraryInstallLocation(
|
||||||
libraryBase string, isHost bool, fuzzDir string, archString string) string {
|
libraryBase string, isHost bool, isVendor bool, fuzzDir string, archString string) string {
|
||||||
installLocation := "$(PRODUCT_OUT)/data"
|
installLocation := "$(PRODUCT_OUT)/data"
|
||||||
if isHost {
|
if isHost {
|
||||||
installLocation = "$(HOST_OUT)"
|
installLocation = "$(HOST_OUT)"
|
||||||
}
|
}
|
||||||
|
subdir := "lib"
|
||||||
|
if isVendor {
|
||||||
|
subdir = "lib/vendor"
|
||||||
|
}
|
||||||
installLocation = filepath.Join(
|
installLocation = filepath.Join(
|
||||||
installLocation, fuzzDir, archString, "lib", libraryBase)
|
installLocation, fuzzDir, archString, subdir, libraryBase)
|
||||||
return installLocation
|
return installLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the device-only shared library symbols install directory.
|
// Get the device-only shared library symbols install directory.
|
||||||
func SharedLibrarySymbolsInstallLocation(libraryBase string, fuzzDir string, archString string) string {
|
func SharedLibrarySymbolsInstallLocation(libraryBase string, isVendor bool, fuzzDir string, archString string) string {
|
||||||
return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryBase)
|
subdir := "lib"
|
||||||
|
if isVendor {
|
||||||
|
subdir = "lib/vendor"
|
||||||
|
}
|
||||||
|
return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, subdir, libraryBase)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
|
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
|
||||||
@@ -244,16 +257,29 @@ func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
|
|||||||
// Grab the list of required shared libraries.
|
// Grab the list of required shared libraries.
|
||||||
fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx)
|
fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx)
|
||||||
|
|
||||||
|
// TODO: does not mirror Android linkernamespaces
|
||||||
|
// the logic here has special cases for vendor, but it would need more work to
|
||||||
|
// work in arbitrary partitions, so just surface errors early for a few cases
|
||||||
|
//
|
||||||
|
// Even without these, there are certain situations across linkernamespaces
|
||||||
|
// that this won't support. For instance, you might have:
|
||||||
|
//
|
||||||
|
// my_fuzzer (vendor) -> libbinder_ndk (core) -> libbinder (vendor)
|
||||||
|
//
|
||||||
|
// This dependency chain wouldn't be possible to express in the current
|
||||||
|
// logic because all the deps currently match the variant of the source
|
||||||
|
// module.
|
||||||
|
|
||||||
for _, ruleBuilderInstall := range fuzzBin.sharedLibraries {
|
for _, ruleBuilderInstall := range fuzzBin.sharedLibraries {
|
||||||
install := ruleBuilderInstall.To
|
install := ruleBuilderInstall.To
|
||||||
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
|
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
|
||||||
SharedLibraryInstallLocation(
|
SharedLibraryInstallLocation(
|
||||||
install, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
|
install, ctx.Host(), ctx.inVendor(), installBase, ctx.Arch().ArchType.String()))
|
||||||
|
|
||||||
// Also add the dependency on the shared library symbols dir.
|
// Also add the dependency on the shared library symbols dir.
|
||||||
if !ctx.Host() {
|
if !ctx.Host() {
|
||||||
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
|
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
|
||||||
SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
|
SharedLibrarySymbolsInstallLocation(install, ctx.inVendor(), installBase, ctx.Arch().ArchType.String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,6 +438,10 @@ func (s *ccRustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sharedLibsInstallDirPrefix := "lib"
|
sharedLibsInstallDirPrefix := "lib"
|
||||||
|
if ccModule.InVendor() {
|
||||||
|
sharedLibsInstallDirPrefix = "lib/vendor"
|
||||||
|
}
|
||||||
|
|
||||||
if !ccModule.IsFuzzModule() {
|
if !ccModule.IsFuzzModule() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -504,7 +534,7 @@ func GetSharedLibsToZip(sharedLibraries android.RuleBuilderInstalls, module Link
|
|||||||
// install it to the output directory. Setup the install destination here,
|
// install it to the output directory. Setup the install destination here,
|
||||||
// which will be used by $(copy-many-files) in the Make backend.
|
// which will be used by $(copy-many-files) in the Make backend.
|
||||||
installDestination := SharedLibraryInstallLocation(
|
installDestination := SharedLibraryInstallLocation(
|
||||||
install, module.Host(), fuzzDir, archString)
|
install, module.Host(), module.InVendor(), fuzzDir, archString)
|
||||||
if (*sharedLibraryInstalled)[installDestination] {
|
if (*sharedLibraryInstalled)[installDestination] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -522,7 +552,7 @@ func GetSharedLibsToZip(sharedLibraries android.RuleBuilderInstalls, module Link
|
|||||||
// we want symbolization tools (like `stack`) to be able to find the symbols
|
// we want symbolization tools (like `stack`) to be able to find the symbols
|
||||||
// in $ANDROID_PRODUCT_OUT/symbols automagically.
|
// in $ANDROID_PRODUCT_OUT/symbols automagically.
|
||||||
if !module.Host() {
|
if !module.Host() {
|
||||||
symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(install, fuzzDir, archString)
|
symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(install, module.InVendor(), fuzzDir, archString)
|
||||||
symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$")
|
symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$")
|
||||||
s.SharedLibInstallStrings = append(s.SharedLibInstallStrings,
|
s.SharedLibInstallStrings = append(s.SharedLibInstallStrings,
|
||||||
library.String()+":"+symbolsInstallDestination)
|
library.String()+":"+symbolsInstallDestination)
|
||||||
|
@@ -142,12 +142,12 @@ func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
|
|||||||
|
|
||||||
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
||||||
cc.SharedLibraryInstallLocation(
|
cc.SharedLibraryInstallLocation(
|
||||||
install, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
|
install, ctx.Host(), ctx.InstallInVendor(), installBase, ctx.Arch().ArchType.String()))
|
||||||
|
|
||||||
// Also add the dependency on the shared library symbols dir.
|
// Also add the dependency on the shared library symbols dir.
|
||||||
if !ctx.Host() {
|
if !ctx.Host() {
|
||||||
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
||||||
cc.SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
|
cc.SharedLibrarySymbolsInstallLocation(install, ctx.InstallInVendor(), installBase, ctx.Arch().ArchType.String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user