aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Vanotti <mvanotti@google.com>2019-07-10 17:54:20 -0700
committerDmitry Vyukov <dvyukov@google.com>2019-07-23 08:44:20 +0200
commit1b0aeaa4e84be4449a73b24a0a57c04c02589a81 (patch)
tree9016ed53c68769afe113862bda402b5da0d0fa6c
parent5aec592bda6468d616f6fa6a6c1fa2d9e6c6895a (diff)
Makefile: build fuchsia go binaries using the sdk
This commit removes a dependency on fuchsia's tools/devshell/contrib/go, which was removed recently[0]. Now to build go binaries for fuchsia we are not relying on the fuchsia.git repo at all. The code just needs a copy of the fuchsia //third_party/go repository, the fuchsia sdk and a copy of clang. Users should download the sdk and clang beforehand (see documentation for links), and then run (with the correct environment variables): ``` $ make TARGETOS=fuchsia TARGETARCH=amd64 \ SOURCEDIR=$HOME/fuchsia \ FX_SDK_PATH=${HOME}/sdk/fuchsia-sdk \ CLANG_PATH=${HOME}/sdk/clang \ fuchsia_go ``` After that, they will be able to build the syzkaller go binaries by doing: ``` $ make TARGETOS=fuchsia TARGETARCH=amd64 \ SOURCEDIR=$HOME/fuchsia \ FX_SDK_PATH=${HOME}/sdk/fuchsia-sdk \ CLANG_PATH=${HOME}/sdk/clang ``` This commits adds two scripts to tools/fuchsia, one for building go in fuchsia (just calls the ./make.all script in fuchsia's go repo), and one that replaces the devshell/contrib/go script. Given that go is unsupported in fuchsia, this change might break at any point. [0]: https://fuchsia-review.googlesource.com/c/fuchsia/+/291631
-rw-r--r--Makefile11
-rw-r--r--docs/fuchsia/README.md73
-rwxr-xr-xtools/fuchsia/build-go.sh32
-rwxr-xr-xtools/fuchsia/go26
4 files changed, 123 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 5372a899f..4bf64a8a1 100644
--- a/Makefile
+++ b/Makefile
@@ -45,8 +45,9 @@ TARGETGOOS := $(TARGETOS)
TARGETGOARCH := $(TARGETVMARCH)
ifeq ("$(TARGETOS)", "fuchsia")
- # SOURCEDIR should point to fuchsia checkout.
- GO = "$(SOURCEDIR)/tools/devshell/contrib/go"
+# SOURCEDIR should point to fuchsia checkout.
+export FX_SRC_PATH=$(SOURCEDIR)
+ GO = "tools/fuchsia/go"
endif
GITREV=$(shell git rev-parse HEAD)
@@ -202,6 +203,12 @@ ifeq ($(TARGETOS),fuchsia)
else
endif
+fuchsia_go:
+ifeq ($(TARGETOS),fuchsia)
+ ./tools/fuchsia/build-go.sh
+else
+endif
+
generate_trace2syz:
(cd tools/syz-trace2syz/parser; ragel -Z -G2 -o lex.go straceLex.rl)
(cd tools/syz-trace2syz/parser; goyacc -o strace.go -p Strace -v="" strace.y)
diff --git a/docs/fuchsia/README.md b/docs/fuchsia/README.md
index 93a212c0e..ec1a08335 100644
--- a/docs/fuchsia/README.md
+++ b/docs/fuchsia/README.md
@@ -2,36 +2,52 @@
For information about checking out and building Fuchsia see
[Getting Started](https://fuchsia.googlesource.com/fuchsia/+/master/docs/getting_started.md)
-and [Soure Code](https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/source_code/README.md).
+and [Source Code](https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/source_code/README.md).
-You need to build fuchsia for both amd64 and arm64:
+## Prerequisites
-```shell
-$ fx --dir "out/x64" set core.x64
-$ fx clean-build
-```
+To run syzkaller with a fuchsia target, you will need:
-And
+* A fuchsia checkout.
+* The [fuchsia
+ sdk](https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/).
+* [clang with fuchsia
+ support](https://chrome-infra-packages.appspot.com/p/fuchsia/clang/linux-amd64/+/).
-```shell
-$ fx --dir "out/arm64" set core.arm64
-$ fx clean-build
-```
+The rest of the document will use the following environment variables:
-Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you need to modify the `.txt` file that contains it, make sure your new definition matches the one in zircon's [syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen) file. **If the syscall was used in `executor/common_fuchsia.h`, you need to update the usages there as well**. FIDL definitions do not need manual updating because they are extracted automatically with the commands below.
+* `SOURCEDIR` path of your fuchsia checkout.
+* `FX_SDK_PATH` path where you extracted the fuchsia sdk.
+* `CLANG_PATH` path where you extracted clang.
-Once you updated the syscalls definitions, everything can be regenerated by running:
+### Build Go toolchain for fuchsia
+
+Syzkaller needs to cross-compile it's Go binaries to run in fuchsia, so first
+you need to compile a Go toolchain that can compile binaries for fuchsia.
+
+Once you downloaded and extracted the fuchsia sdk and clang, run:
```
-make extract TARGETOS=fuchsia SOURCEDIR=/path/to/fuchsia/checkout
-make generate
+$ make TARGETOS=fuchsia TARGETARCH=amd64 \
+ SOURCEDIR=path/to/fuchsia/checkout \
+ FX_SDK_PATH=path/to/fuchsia/sdk \
+ CLANG_PATH=path/to/clang \
+ fuchsia_go
```
-To build binaries:
+## Building binaries for fuchsia
+
+To build all the binaries required for running syzkaller in fuchsia, run:
+
```
-make TARGETOS=fuchsia TARGETARCH=amd64 SOURCEDIR=/path/to/fuchsia/checkout
+$ make TARGETOS=fuchsia TARGETARCH=amd64 \
+ SOURCEDIR=path/to/fuchsia/checkout \
+ FX_SDK_PATH=path/to/fuchsia/sdk \
+ CLANG_PATH=path/to/clang
```
+## Running syz-manager
+
Run `syz-manager` with a config along the lines of:
```
{
@@ -57,6 +73,29 @@ Run `syz-manager` with a config along the lines of:
}
```
+## Update syscall and fidl definitions
+
+Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you need to modify the `.txt` file that contains it, make sure your new definition matches the one in zircon's [syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen) file. **If the syscall was used in `executor/common_fuchsia.h`, you need to update the usages there as well**. FIDL definitions do not need manual updating because they are extracted automatically when you run make extract, but they require a fuchsia built for each architecture.
+
+To build fuchsia run:
+```shell
+$ fx --dir "out/x64" set core.x64
+$ fx clean-build
+```
+
+And
+
+```shell
+$ fx --dir "out/arm64" set core.arm64
+$ fx clean-build
+```
+
+Once you updated the syscalls definitions, everything can be regenerated by running:
+
+```
+make extract TARGETOS=fuchsia SOURCEDIR=/path/to/fuchsia/checkout
+make generate
+```
## How to generate syscall description for FIDL
diff --git a/tools/fuchsia/build-go.sh b/tools/fuchsia/build-go.sh
new file mode 100755
index 000000000..49ce0f418
--- /dev/null
+++ b/tools/fuchsia/build-go.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# This script can be used to compile Go for fuchsia.
+# You need to have a fuchsia checkout defined in the FX_SRC_PATH variable,
+# The fuchsia sdk in the FX_SDK_PATH variable, and a CLANG compatible with
+# fuchsia in CLANG_PATH.
+
+if [[ -z ${FX_SDK_PATH} ]]; then
+ echo "FX_SDK_PATH variable not set"
+ exit 1
+fi
+
+if [[ -z ${FX_SRC_PATH} ]]; then
+ echo "FX_SRC_PATH variable not set"
+ exit 1
+fi
+
+if [[ -z ${CLANG_PATH} ]]; then
+ echo "CLANG_PATH variable not set"
+ exit 1
+fi
+
+cd "${FX_SRC_PATH}/third_party/go/src"
+
+FUCHSIA_SHARED_LIBS=${FX_SDK_PATH}/arch/x64/lib \
+ CLANG_PREFIX=${CLANG_PATH}/bin \
+ FDIO_INCLUDE=${FX_SDK_PATH}/pkg/fdio/include \
+ ZIRCON_SYSROOT=${FX_SDK_PATH}/arch/x64/sysroot \
+ CC=${FX_SRC_PATH}/third_party/go/misc/fuchsia/clangwrap.sh \
+ CGO_ENABLED=1 \
+ GOOS=fuchsia \
+ ./make.bash
diff --git a/tools/fuchsia/go b/tools/fuchsia/go
new file mode 100755
index 000000000..bff63d190
--- /dev/null
+++ b/tools/fuchsia/go
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+if [[ -z ${FX_SDK_PATH} ]]; then
+ echo "FX_SDK_PATH variable not set"
+ exit 1
+fi
+
+if [[ -z ${FX_SRC_PATH} ]]; then
+ echo "FX_SRC_PATH variable not set"
+ exit 1
+fi
+
+if [[ -z ${CLANG_PATH} ]]; then
+ echo "CLANG_PATH variable not set"
+ exit 1
+fi
+
+FUCHSIA_SHARED_LIBS="${FX_SDK_PATH}/arch/x64/lib" \
+ CLANG_PREFIX="${CLANG_PATH}/bin" \
+ FDIO_INCLUDE="${FX_SDK_PATH}/pkg/fdio/include" \
+ ZIRCON_SYSROOT="${FX_SDK_PATH}/arch/x64/sysroot" \
+ CC="${FX_SRC_PATH}/third_party/go/misc/fuchsia/clangwrap.sh" \
+ CGO_ENABLED=1 \
+ GOOS=fuchsia \
+ GOROOT="${FX_SRC_PATH}/third_party/go" \
+ "${FX_SRC_PATH}/third_party/go/bin/go" "$@"