Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame^] | 1 | From aca1030d29f627314d13884ebc7b2c313d718df7 Mon Sep 17 00:00:00 2001 |
| 2 | From: Ovidiu Panait <ovidiu.panait@windriver.com> |
| 3 | Date: Wed, 13 Apr 2022 17:17:54 +0300 |
| 4 | Subject: [PATCH] sys/targets/targets.go: allow users to override hardcoded |
| 5 | cross-compilers |
| 6 | |
| 7 | Currently, cross compiler names are hardcoded for each os/arch combo. However, |
| 8 | toolchain tuples differ, especially when using vendor provided toolchains. |
| 9 | Allow users to specify the cross compiler for an os/arch combo using |
| 10 | SYZ_CC_<os>_<arch> environment variables. |
| 11 | |
| 12 | Also, remove hardcoded "-march=armv6" flag to fix compilation on arm. |
| 13 | |
| 14 | Upstream-Status: Inappropriate [embedded specific] |
| 15 | |
| 16 | Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> |
| 17 | --- |
| 18 | sys/targets/targets.go | 19 +++++++++++-------- |
| 19 | 1 file changed, 11 insertions(+), 8 deletions(-) |
| 20 | |
| 21 | diff --git a/sys/targets/targets.go b/sys/targets/targets.go |
| 22 | index f3be708f3..19a8bb681 100644 |
| 23 | --- a/sys/targets/targets.go |
| 24 | +++ b/sys/targets/targets.go |
| 25 | @@ -258,7 +258,6 @@ var List = map[string]map[string]*Target{ |
| 26 | PtrSize: 4, |
| 27 | PageSize: 4 << 10, |
| 28 | LittleEndian: true, |
| 29 | - CFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-march=armv6"}, |
| 30 | Triple: "arm-linux-gnueabi", |
| 31 | KernelArch: "arm", |
| 32 | KernelHeaderArch: "arm", |
| 33 | @@ -670,12 +669,16 @@ func initTarget(target *Target, OS, arch string) { |
| 34 | for i := range target.CFlags { |
| 35 | target.replaceSourceDir(&target.CFlags[i], sourceDir) |
| 36 | } |
| 37 | - if OS == Linux && arch == runtime.GOARCH { |
| 38 | - // Don't use cross-compiler for native compilation, there are cases when this does not work: |
| 39 | - // https://github.com/google/syzkaller/pull/619 |
| 40 | - // https://github.com/google/syzkaller/issues/387 |
| 41 | - // https://github.com/google/syzkaller/commit/06db3cec94c54e1cf720cdd5db72761514569d56 |
| 42 | - target.Triple = "" |
| 43 | + if OS == Linux { |
| 44 | + if cc := os.Getenv("SYZ_CC_" + OS + "_" + arch); cc != "" { |
| 45 | + target.CCompiler = cc |
| 46 | + } else if arch == runtime.GOARCH { |
| 47 | + // Don't use cross-compiler for native compilation, there are cases when this does not work: |
| 48 | + // https://github.com/google/syzkaller/pull/619 |
| 49 | + // https://github.com/google/syzkaller/issues/387 |
| 50 | + // https://github.com/google/syzkaller/commit/06db3cec94c54e1cf720cdd5db72761514569d56 |
| 51 | + target.Triple = "" |
| 52 | + } |
| 53 | } |
| 54 | if target.CCompiler == "" { |
| 55 | target.setCompiler(useClang) |
| 56 | @@ -803,7 +806,7 @@ func (target *Target) lazyInit() { |
| 57 | // On CI we want to fail loudly if cross-compilation breaks. |
| 58 | // Also fail if SOURCEDIR_GOOS is set b/c in that case user probably assumes it will work. |
| 59 | if (target.OS != runtime.GOOS || !runningOnCI) && os.Getenv("SOURCEDIR_"+strings.ToUpper(target.OS)) == "" { |
| 60 | - if _, err := exec.LookPath(target.CCompiler); err != nil { |
| 61 | + if _, err := exec.LookPath(strings.Fields(target.CCompiler)[0]); err != nil { |
| 62 | target.BrokenCompiler = fmt.Sprintf("%v is missing (%v)", target.CCompiler, err) |
| 63 | return |
| 64 | } |
| 65 | -- |
| 66 | 2.25.1 |
| 67 | |