aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-test/syzkaller/syzkaller/0001-sys-targets-targets.go-allow-users-to-override-hardc.patch
blob: 61f43516518d318563cc2f6378a254701e7ba6b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From aca1030d29f627314d13884ebc7b2c313d718df7 Mon Sep 17 00:00:00 2001
From: Ovidiu Panait <ovidiu.panait@windriver.com>
Date: Wed, 13 Apr 2022 17:17:54 +0300
Subject: [PATCH] sys/targets/targets.go: allow users to override hardcoded
 cross-compilers

Currently, cross compiler names are hardcoded for each os/arch combo. However,
toolchain tuples differ, especially when using vendor provided toolchains.
Allow users to specify the cross compiler for an os/arch combo using
SYZ_CC_<os>_<arch> environment variables.

Also, remove hardcoded "-march=armv6" flag to fix compilation on arm.

Upstream-Status: Inappropriate [embedded specific]

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
---
 sys/targets/targets.go | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -262,7 +262,6 @@ var List = map[string]map[string]*Target
 			PtrSize:          4,
 			PageSize:         4 << 10,
 			LittleEndian:     true,
-			CFlags:           []string{"-D__LINUX_ARM_ARCH__=6", "-march=armv6"},
 			Triple:           "arm-linux-gnueabi",
 			KernelArch:       "arm",
 			KernelHeaderArch: "arm",
@@ -700,12 +699,16 @@ func initTarget(target *Target, OS, arch
 	for i := range target.CFlags {
 		target.replaceSourceDir(&target.CFlags[i], sourceDir)
 	}
-	if OS == Linux && arch == runtime.GOARCH {
-		// Don't use cross-compiler for native compilation, there are cases when this does not work:
-		// https://github.com/google/syzkaller/pull/619
-		// https://github.com/google/syzkaller/issues/387
-		// https://github.com/google/syzkaller/commit/06db3cec94c54e1cf720cdd5db72761514569d56
-		target.Triple = ""
+	if OS == Linux {
+		if cc := os.Getenv("SYZ_CC_" + OS + "_" + arch); cc != "" {
+			target.CCompiler = cc
+		} else if arch == runtime.GOARCH {
+			// Don't use cross-compiler for native compilation, there are cases when this does not work:
+			// https://github.com/google/syzkaller/pull/619
+			// https://github.com/google/syzkaller/issues/387
+			// https://github.com/google/syzkaller/commit/06db3cec94c54e1cf720cdd5db72761514569d56
+			target.Triple = ""
+		}
 	}
 	if target.CCompiler == "" {
 		target.setCompiler(useClang)
@@ -839,7 +842,7 @@ func (target *Target) lazyInit() {
 	// On CI we want to fail loudly if cross-compilation breaks.
 	// Also fail if SOURCEDIR_GOOS is set b/c in that case user probably assumes it will work.
 	if (target.OS != runtime.GOOS || !runningOnCI) && getSourceDir(target) == "" {
-		if _, err := exec.LookPath(target.CCompiler); err != nil {
+		if _, err := exec.LookPath(strings.Fields(target.CCompiler)[0]); err != nil {
 			target.BrokenCompiler = fmt.Sprintf("%v is missing (%v)", target.CCompiler, err)
 			return
 		}