From 6404acf9ce200d01fcbe0923924c9f6c22c258de Mon Sep 17 00:00:00 2001 From: Liz Prucka Date: Wed, 31 Jan 2024 13:16:27 -0600 Subject: pkg/build: copy unstripped module object files for Pixel Copy unstripped module files in the output directory to be stored in the object dir, to be used when generating module coverage. --- pkg/build/android.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'pkg/build/android.go') diff --git a/pkg/build/android.go b/pkg/build/android.go index 13a7de2e6..aabb5d534 100644 --- a/pkg/build/android.go +++ b/pkg/build/android.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "time" "github.com/google/syzkaller/pkg/config" @@ -112,6 +113,10 @@ func (a android) build(params Params) (ImageDetails, error) { } defer imageFile.Close() + if err := a.copyModuleFiles(filepath.Join(params.KernelDir, "out"), params.OutputDir); err != nil { + return details, fmt.Errorf("failed copying module files: %w", err) + } + if err := a.embedImages(imageFile, buildDistDir, "boot.img", "dtbo.img", buildCfg.VendorBootImage, "vendor_dlkm.img"); err != nil { return details, fmt.Errorf("failed to embed images: %w", err) @@ -125,6 +130,30 @@ func (a android) build(params Params) (ImageDetails, error) { return details, nil } +func (a android) copyModuleFiles(srcDir, dstDir string) error { + err := filepath.Walk(srcDir, + func(path string, info os.FileInfo, err error) error { + if err != nil { + return fmt.Errorf("error walking out dir: %w", err) + } + // Staging directories contain stripped module object files. + if strings.Contains(path, "staging") { + return nil + } + + if filepath.Ext(path) == ".ko" { + if err := osutil.CopyFile(path, filepath.Join(dstDir, info.Name())); err != nil { + return fmt.Errorf("error copying file: %w", err) + } + } + return nil + }) + if err != nil { + return fmt.Errorf("failed to copy module objects: %w", err) + } + return nil +} + func (a android) embedImages(w io.Writer, srcDir string, imageNames ...string) error { tw := tar.NewWriter(w) defer tw.Close() -- cgit mrf-deployment