From a38fb99b3fbff0c988e64bf4bf277071e18b18af Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 21 May 2024 07:14:39 +0200 Subject: Makefile: build executor with C++ compiler Add C++ compiler and flags to the target and build executor with the C++ compiler. This will be needed to merge syz-fuzzer in to syz-executor since it will be beefier and will most likely require linking in libc++. But also this should fix #4821 since we won't use C++ flags when building C sources (we already had work-around in pkg/csource, but not in syz-extract). Fixes #4821 --- pkg/csource/build.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'pkg/csource') diff --git a/pkg/csource/build.go b/pkg/csource/build.go index 5dd1234a7..0625e9a03 100644 --- a/pkg/csource/build.go +++ b/pkg/csource/build.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" "runtime" - "slices" "strings" "testing" @@ -46,8 +45,6 @@ func BuildExecutor(t *testing.T, target *prog.Target, rootDir string, cflags ... } func build(target *prog.Target, src []byte, dir, file string, cflags ...string) (string, error) { - sysTarget := targets.Get(target.OS, target.Arch) - compiler := sysTarget.CCompiler // We call the binary syz-executor because it sometimes shows in bug titles, // and we don't want 2 different bugs for when a crash is triggered during fuzzing and during repro. bin, err := osutil.TempFile("syz-executor") @@ -66,18 +63,17 @@ func build(target *prog.Target, src []byte, dir, file string, cflags ...string) } else { flags = append(flags, file) } - flags = append(flags, sysTarget.CFlags...) + sysTarget := targets.Get(target.OS, target.Arch) + compiler, targetCFlags := sysTarget.CCompiler, sysTarget.CFlags + if file != "" && !strings.HasSuffix(file, ".c") { + compiler, targetCFlags = sysTarget.CxxCompiler, sysTarget.CxxFlags + } + flags = append(flags, targetCFlags...) + flags = append(flags, cflags...) if sysTarget.PtrSize == 4 { // We do generate uint64's for syscall arguments that overflow longs on 32-bit archs. flags = append(flags, "-Wno-overflow") } - flags = append(flags, cflags...) - if file == "" || strings.HasSuffix(file, ".c") { - // Building C source, so remove C++ flags. - flags = slices.DeleteFunc(flags, func(flag string) bool { - return strings.HasPrefix(flag, "-std=c++") - }) - } cmd := osutil.Command(compiler, flags...) cmd.Dir = dir if file == "" { -- cgit mrf-deployment