aboutsummaryrefslogtreecommitdiffstats
path: root/sys/syz-extract/linux.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-15 15:07:21 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-21 14:22:40 +0100
commit647eaa71d93ba0981b6c25d8cce229c83b6c136c (patch)
treed24d4e86e7ccba817edc78ce762def9d6999afce /sys/syz-extract/linux.go
parent5c40c193708a05601d516f8482ceded20b5b9979 (diff)
pkg/build: support cross-compilation for linux
We currently only support native build in pkg/build (does not even pass ARCH). Move the existing cross-compilation logic from sys/syz-extract/linux.go and reuse it in both places.
Diffstat (limited to 'sys/syz-extract/linux.go')
-rw-r--r--sys/syz-extract/linux.go27
1 files changed, 3 insertions, 24 deletions
diff --git a/sys/syz-extract/linux.go b/sys/syz-extract/linux.go
index 47e5d20e6..53dd8b09a 100644
--- a/sys/syz-extract/linux.go
+++ b/sys/syz-extract/linux.go
@@ -10,6 +10,7 @@ import (
"strings"
"time"
+ "github.com/google/syzkaller/pkg/build"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/sys/targets"
@@ -79,35 +80,13 @@ func (*linux) prepareArch(arch *Arch) error {
if !arch.build {
return nil
}
- target := arch.target
- var cflags []string
- for _, flag := range target.CFlags {
- if !strings.HasPrefix(flag, "-W") {
- cflags = append(cflags, flag)
- }
- }
kernelDir := arch.sourceDir
- buildDir := arch.buildDir
- makeArgs := []string{
- "ARCH=" + target.KernelArch,
- "CFLAGS=" + strings.Join(cflags, " "),
- "O=" + buildDir,
- "-j", fmt.Sprint(runtime.NumCPU()),
- }
- if target.Triple != "" {
- makeArgs = append(makeArgs, "CROSS_COMPILE="+target.Triple+"-")
- }
- if target.KernelCompiler != "" {
- makeArgs = append(makeArgs, "CC="+target.KernelCompiler)
- }
- if target.KernelLinker != "" {
- makeArgs = append(makeArgs, "LD="+target.KernelLinker)
- }
+ makeArgs := build.LinuxMakeArgs(arch.target, "", "", arch.buildDir)
out, err := osutil.RunCmd(time.Hour, kernelDir, "make", append(makeArgs, "defconfig")...)
if err != nil {
return fmt.Errorf("make defconfig failed: %v\n%s", err, out)
}
- _, err = osutil.RunCmd(time.Minute, buildDir, filepath.Join(kernelDir, "scripts", "config"),
+ _, err = osutil.RunCmd(time.Minute, arch.buildDir, filepath.Join(kernelDir, "scripts", "config"),
// powerpc arch is configured to be big-endian by default, but we want little-endian powerpc.
// Since all of our archs are little-endian for now, we just blindly switch it.
"-d", "CPU_BIG_ENDIAN", "-e", "CPU_LITTLE_ENDIAN",