aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-11-17 11:20:17 -0800
committerDmitry Vyukov <dvyukov@google.com>2018-11-17 11:42:22 -0800
commitd1a88510856c352db84d1b8ffa252c0a9ce30dec (patch)
treeb76c193cb11f94d1ae7532409e12d2255b43ee41
parent7d395878aa6d662c1880c5b2a7ab76378cc96b7f (diff)
sys/targest: introduce target.BuildOS
We can't cross-compile native binaries from just any OS to any other. For most OSes we can do only native compilation. Some can only be compiled from linux. To date we avoided this problem completely (mostly assumed linux build OS). Make this notion of what can build what explicit.
-rw-r--r--Makefile8
-rw-r--r--pkg/csource/csource_test.go6
-rw-r--r--sys/targets/targets.go18
-rw-r--r--tools/syz-env/env.go2
4 files changed, 30 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 8c931312f..1828ab1c5 100644
--- a/Makefile
+++ b/Makefile
@@ -110,10 +110,16 @@ target:
# executor uses stacks of limited size, so no jumbo frames.
executor:
+ifeq ($(BUILDOS),$(NATIVEBUILDOS))
mkdir -p ./bin/$(TARGETOS)_$(TARGETARCH)
$(CC) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) executor/executor.cc \
-pthread -Wall -Wframe-larger-than=8192 -Wparentheses -Werror -O2 $(ADDCFLAGS) $(CFLAGS) \
-DGOOS_$(TARGETOS)=1 -DGOARCH_$(TARGETARCH)=1 -DGIT_REVISION=\"$(REV)\"
+else
+ $(info ************************************************************************************)
+ $(info Building executor for ${TARGETOS} is not supported on ${BUILDOS}. Executor will not be built.)
+ $(info ************************************************************************************)
+endif
manager:
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o ./bin/syz-manager github.com/google/syzkaller/syz-manager
@@ -268,7 +274,7 @@ arch_openbsd_amd64_target:
arch_windows_amd64_target:
env GOOG=windows GOARCH=amd64 $(GO) install ./syz-fuzzer
- env TARGETOS=windows TARGETARCH=amd64 $(MAKE) fuzzer execprog stress
+ env TARGETOS=windows TARGETARCH=amd64 $(MAKE) target
arch_test:
env TARGETOS=test TARGETARCH=64 $(MAKE) executor
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index 8545efba8..9743b6356 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -14,6 +14,7 @@ import (
"github.com/google/syzkaller/prog"
_ "github.com/google/syzkaller/sys"
+ "github.com/google/syzkaller/sys/targets"
)
func TestGenerate(t *testing.T) {
@@ -23,11 +24,10 @@ func TestGenerate(t *testing.T) {
}
t.Parallel()
for _, target := range prog.AllTargets() {
- switch target.OS {
- case "netbsd", "windows":
+ target := target
+ if runtime.GOOS != targets.Get(target.OS, target.Arch).BuildOS {
continue
}
- target := target
t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {
if target.OS == "linux" && target.Arch == "arm" {
// This currently fails (at least with my arm-linux-gnueabihf-gcc-4.8) with:
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index 54b2b36fc..88d2c7277 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -4,6 +4,7 @@
package targets
import (
+ "fmt"
"os"
"os/exec"
"runtime"
@@ -32,6 +33,10 @@ type Target struct {
}
type osCommon struct {
+ // What OS can build native binaries for this OS.
+ // If not set, defaults to itself (i.e. native build).
+ // Later we can extend this to be a list, but so far we don't have more than one OS.
+ BuildOS string
// Does the OS use syscall numbers (e.g. Linux) or has interface based on functions (e.g. fuchsia).
SyscallNumbers bool
// E.g. "__NR_" or "SYS_".
@@ -288,6 +293,7 @@ var oses = map[string]osCommon{
CPP: "ecpp",
},
"fuchsia": {
+ BuildOS: "linux",
SyscallNumbers: false,
ExecutorUsesShmem: false,
ExecutorUsesForkServer: false,
@@ -303,6 +309,7 @@ var oses = map[string]osCommon{
CPP: "cpp",
},
"akaros": {
+ BuildOS: "linux",
SyscallNumbers: true,
SyscallPrefix: "SYS_",
ExecutorUsesShmem: false,
@@ -354,6 +361,17 @@ func initTarget(target *Target, OS, arch string) {
if target.CCompiler == "" {
target.CCompiler = target.CCompilerPrefix + "gcc"
}
+ if target.BuildOS == "" {
+ target.BuildOS = OS
+ }
+ if OS == "test" {
+ target.BuildOS = "linux"
+ }
+ if runtime.GOOS != target.BuildOS {
+ // Spoil native binaries if they are not usable, so that nobody tries to use them later.
+ target.CCompiler = fmt.Sprintf("cant-build-%v-on-%v", target.OS, runtime.GOOS)
+ target.CPP = target.CCompiler
+ }
}
func checkStaticBuild(target *Target) {
diff --git a/tools/syz-env/env.go b/tools/syz-env/env.go
index 775f05ca2..a5fc4fbb1 100644
--- a/tools/syz-env/env.go
+++ b/tools/syz-env/env.go
@@ -29,6 +29,8 @@ func main() {
Val string
}
vars := []Var{
+ {"BUILDOS", runtime.GOOS},
+ {"NATIVEBUILDOS", target.BuildOS},
{"HOSTOS", hostOS},
{"HOSTARCH", hostArch},
{"TARGETOS", targetOS},