diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-10-12 12:11:12 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-10-12 15:22:20 +0200 |
| commit | 89b5a5097a095577d19574ae2fe3070e5af2a065 (patch) | |
| tree | 873483fd5ff14396065e7af0ca02319967e59d53 /pkg/build | |
| parent | 16a9c9e0fe35ce296944c5682f4a54d52bd67e71 (diff) | |
all: add support for custom linker
Add this as an option to syz-ci and syz-build tools.
Otherwise we cannot use clang + ld.lld for kernel builds.
Diffstat (limited to 'pkg/build')
| -rw-r--r-- | pkg/build/build.go | 16 | ||||
| -rw-r--r-- | pkg/build/linux.go | 13 |
2 files changed, 17 insertions, 12 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go index cabb8046e..4baed2b95 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -28,6 +28,7 @@ type Params struct { KernelDir string OutputDir string Compiler string + Linker string Ccache string UserspaceDir string CmdlineFile string @@ -47,13 +48,14 @@ type ImageDetails struct { // If CmdlineFile is not empty, contents of the file are appended to the kernel command line. // If SysctlFile is not empty, contents of the file are appended to the image /etc/sysctl.conf. // Output is stored in OutputDir and includes (everything except for image is optional): -// - image: the image -// - key: ssh key for the image -// - kernel: kernel for injected boot -// - initrd: initrd for injected boot -// - kernel.config: actual kernel config used during build -// - obj/: directory with kernel object files (this should match KernelObject -// specified in sys/targets, e.g. vmlinux for linux) +// - image: the image +// - key: ssh key for the image +// - kernel: kernel for injected boot +// - initrd: initrd for injected boot +// - kernel.config: actual kernel config used during build +// - obj/: directory with kernel object files (this should match KernelObject +// specified in sys/targets, e.g. vmlinux for linux) +// // The returned structure contains a kernel ID that will be the same for kernels // with the same runtime behavior, and different for kernels with different runtime // behavior. Binary equal builds, or builds that differ only in e.g. debug info, diff --git a/pkg/build/linux.go b/pkg/build/linux.go index be9a38377..9fae48fc6 100644 --- a/pkg/build/linux.go +++ b/pkg/build/linux.go @@ -148,9 +148,9 @@ func (linux) writeFile(file string, data []byte) error { return osutil.SandboxChown(file) } -func runMakeImpl(arch, compiler, ccache, kernelDir string, addArgs ...string) error { +func runMakeImpl(arch, compiler, linker, ccache, kernelDir string, addArgs ...string) error { target := targets.Get(targets.Linux, arch) - args := LinuxMakeArgs(target, compiler, ccache, "") + args := LinuxMakeArgs(target, compiler, linker, ccache, "") args = append(args, addArgs...) cmd := osutil.Command("make", args...) if err := osutil.Sandbox(cmd, true, true); err != nil { @@ -175,10 +175,10 @@ func runMakeImpl(arch, compiler, ccache, kernelDir string, addArgs ...string) er } func runMake(params Params, addArgs ...string) error { - return runMakeImpl(params.TargetArch, params.Compiler, params.Ccache, params.KernelDir, addArgs...) + return runMakeImpl(params.TargetArch, params.Compiler, params.Linker, params.Ccache, params.KernelDir, addArgs...) } -func LinuxMakeArgs(target *targets.Target, compiler, ccache, buildDir string) []string { +func LinuxMakeArgs(target *targets.Target, compiler, linker, ccache, buildDir string) []string { args := []string{ "-j", fmt.Sprint(runtime.NumCPU()), "ARCH=" + target.KernelArch, @@ -189,7 +189,7 @@ func LinuxMakeArgs(target *targets.Target, compiler, ccache, buildDir string) [] if compiler == "" { compiler = target.KernelCompiler if target.KernelLinker != "" { - args = append(args, "LD="+target.KernelLinker) + linker = target.KernelLinker } } if compiler != "" { @@ -198,6 +198,9 @@ func LinuxMakeArgs(target *targets.Target, compiler, ccache, buildDir string) [] } args = append(args, "CC="+compiler) } + if linker != "" { + args = append(args, "LD="+linker) + } if buildDir != "" { args = append(args, "O="+buildDir) } |
