aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-04-16 16:12:58 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-04-17 07:57:15 +0000
commitb3008567ea0fa2942115d4c4013a16f3ff0e4952 (patch)
tree1ba093e631ae9f70a915c4d1a9f77770da58a0f9
parent5b14b31251d4cc2e33eb313e29b037262c597679 (diff)
all: use LLVM=1 for building Linux with clang
This is the standard way now. Since our configuration permits multiple parameter value combinations, explicitly check for the compiler and linker that were to be passed via CC and LD, and replace that with LLVM=1 if they were clang and ld.lld correspondingly. Update syz-kconf to rely on pkg/build's exported functionality for generating Linux kernel build arguments.
-rw-r--r--pkg/build/linux.go13
-rw-r--r--sys/targets/targets.go11
-rw-r--r--tools/syz-kconf/kconf.go26
3 files changed, 31 insertions, 19 deletions
diff --git a/pkg/build/linux.go b/pkg/build/linux.go
index 47c84c551..daf771e87 100644
--- a/pkg/build/linux.go
+++ b/pkg/build/linux.go
@@ -200,10 +200,17 @@ func LinuxMakeArgs(target *targets.Target, compiler, linker, ccache, buildDir st
if ccache != "" {
compiler = ccache + " " + compiler
}
- args = append(args, "CC="+compiler)
}
- if linker != "" {
- args = append(args, "LD="+linker)
+ // The standard way to build Linux with clang is to pass LLVM=1 instead of CC= and LD=.
+ if compiler == targets.DefaultLLVMCompiler && (linker == "" || linker == targets.DefaultLLVMLinker) {
+ args = append(args, "LLVM=1")
+ } else {
+ if compiler != "" {
+ args = append(args, "CC="+compiler)
+ }
+ if linker != "" {
+ args = append(args, "LD="+linker)
+ }
}
if buildDir != "" {
args = append(args, "O="+buildDir)
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index 2cf001473..50f5c5121 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -881,6 +881,11 @@ func (target *Target) Timeouts(slowdown int) Timeouts {
return timeouts
}
+const (
+ DefaultLLVMCompiler = "clang"
+ DefaultLLVMLinker = "ld.lld"
+)
+
func (target *Target) setCompiler(clang bool) {
// setCompiler may be called effectively twice for target.other,
// so first we remove flags the previous call may have added.
@@ -895,9 +900,9 @@ func (target *Target) setCompiler(clang bool) {
}
target.CFlags = target.CFlags[:pos]
if clang {
- target.CCompiler = "clang"
- target.KernelCompiler = "clang"
- target.KernelLinker = "ld.lld"
+ target.CCompiler = DefaultLLVMCompiler
+ target.KernelCompiler = DefaultLLVMCompiler
+ target.KernelLinker = DefaultLLVMLinker
if target.Triple != "" {
target.CFlags = append(target.CFlags, "--target="+target.Triple)
}
diff --git a/tools/syz-kconf/kconf.go b/tools/syz-kconf/kconf.go
index ce39cd66a..9ba2bff06 100644
--- a/tools/syz-kconf/kconf.go
+++ b/tools/syz-kconf/kconf.go
@@ -18,6 +18,7 @@ import (
"strings"
"time"
+ "github.com/google/syzkaller/pkg/build"
"github.com/google/syzkaller/pkg/kconfig"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/tool"
@@ -444,22 +445,21 @@ clean:
}
func (ctx *Context) Make(args ...string) error {
- args = append(args,
- "O="+ctx.BuildDir,
- "ARCH="+ctx.Target.KernelArch,
- "-j", fmt.Sprint(runtime.NumCPU()),
- )
- if ctx.Target.Triple != "" {
- args = append(args, "CROSS_COMPILE="+ctx.Target.Triple+"-")
- }
+ compiler, linker := "", ""
if ctx.Inst.Compiler != "" {
- args = append(args, "CC="+ctx.replaceVars(ctx.Inst.Compiler))
- } else if ctx.Target.KernelCompiler != "" {
- args = append(args, "CC="+ctx.Target.KernelCompiler)
+ compiler = ctx.replaceVars(ctx.Inst.Compiler)
}
if ctx.Inst.Linker != "" {
- args = append(args, "LD="+ctx.replaceVars(ctx.Inst.Linker))
- }
+ linker = ctx.replaceVars(ctx.Inst.Linker)
+ }
+ args = append(args, build.LinuxMakeArgs(
+ ctx.Target,
+ compiler,
+ linker,
+ "", // ccache
+ ctx.BuildDir,
+ runtime.NumCPU(),
+ )...)
_, err := osutil.RunCmd(10*time.Minute, ctx.SourceDir, "make", args...)
return err
}