aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-08-19 01:52:46 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-08-19 01:53:59 +0200
commit7067e78fd655232314eaa3d964004ed9600e02be (patch)
tree76aa3d3fe1ae7fe5172b40335c5b6055f4dc8881
parent48613af61c42e8a3b4925d7fc7b8ca8350e96f9b (diff)
executor: fix gcc warnings in fuchsia generated code
gcc complains about function declarations not being prototypes, signed/unsigned cast mismatch and casts between incompatible functions. Fix them.
-rw-r--r--executor/common.h26
-rw-r--r--executor/common_fuchsia.h21
-rw-r--r--pkg/csource/csource.go2
-rw-r--r--pkg/csource/generated.go44
-rw-r--r--sys/targets/targets.go2
5 files changed, 52 insertions, 43 deletions
diff --git a/executor/common.h b/executor/common.h
index 6b8b43a33..81e60397f 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -55,7 +55,7 @@ static __thread jmp_buf segv_env;
#if GOOS_akaros
#include <parlib/parlib.h>
-static void recover()
+static void recover(void)
{
_longjmp(segv_env, 1);
}
@@ -86,7 +86,7 @@ static void segv_handler(int sig, siginfo_t* info, void* ctx)
doexit(sig);
}
-static void install_segv_handler()
+static void install_segv_handler(void)
{
struct sigaction sa;
#if GOOS_linux
@@ -142,7 +142,7 @@ static void sleep_ms(uint64 ms)
#if SYZ_EXECUTOR || SYZ_THREADED || SYZ_REPEAT && SYZ_EXECUTOR_USES_FORK_SERVER
#include <time.h>
-static uint64 current_time_ms()
+static uint64 current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
@@ -156,7 +156,7 @@ static uint64 current_time_ms()
#include <sys/stat.h>
#include <unistd.h>
-static void use_temporary_dir()
+static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
@@ -406,9 +406,9 @@ static void* thr(void* arg)
}
#if SYZ_REPEAT
-static void execute_one()
+static void execute_one(void)
#else
-static void loop()
+static void loop(void)
#endif
{
#if SYZ_REPRO
@@ -424,7 +424,7 @@ static void loop()
again:
#endif
for (call = 0; call < [[NUM_CALLS]]; call++) {
- for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
+ for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
@@ -459,7 +459,7 @@ again:
#endif
#if SYZ_EXECUTOR || SYZ_REPEAT
-static void execute_one();
+static void execute_one(void);
#if SYZ_EXECUTOR_USES_FORK_SERVER
#include <signal.h>
#include <sys/types.h>
@@ -475,7 +475,7 @@ static void execute_one();
static void reply_handshake();
#endif
-static void loop()
+static void loop(void)
{
#if SYZ_HAVE_SETUP_LOOP
setup_loop();
@@ -605,7 +605,7 @@ static void loop()
}
}
#else
-static void loop()
+static void loop(void)
{
execute_one();
}
@@ -623,9 +623,9 @@ static void loop()
#if SYZ_THREADED
void execute_call(int call)
#elif SYZ_REPEAT
-void execute_one()
+void execute_one(void)
#else
-void loop()
+void loop(void)
#endif
{
[[SYSCALLS]]
@@ -644,7 +644,7 @@ int main(int argc, char** argv)
if (argc == 2 && strcmp(argv[1], "child") == 0)
child();
#else
-int main()
+int main(void)
{
[[MMAP_DATA]]
#endif
diff --git a/executor/common_fuchsia.h b/executor/common_fuchsia.h
index 6740c0e95..219aee865 100644
--- a/executor/common_fuchsia.h
+++ b/executor/common_fuchsia.h
@@ -3,7 +3,6 @@
// This file is shared between executor and csource package.
-#include <ddk/driver.h>
#include <fcntl.h>
#include <lib/fdio/util.h>
#include <poll.h>
@@ -22,6 +21,10 @@
#include <zircon/process.h>
#include <zircon/syscalls.h>
+#if SYZ_EXECUTOR || __NR_get_root_resource
+#include <ddk/driver.h>
+#endif
+
#if SYZ_EXECUTOR || SYZ_HANDLE_SEGV
#include <pthread.h>
#include <setjmp.h>
@@ -33,7 +36,7 @@
static __thread int skip_segv;
static __thread jmp_buf segv_env;
-static void segv_handler()
+static void segv_handler(void)
{
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED)) {
debug("recover: skipping\n");
@@ -91,7 +94,7 @@ static void* ex_handler(void* arg)
return 0;
}
-static void install_segv_handler()
+static void install_segv_handler(void)
{
zx_status_t status;
zx_handle_t port;
@@ -185,28 +188,28 @@ long syz_mmap(size_t addr, size_t size)
#endif
#if SYZ_EXECUTOR || __NR_syz_process_self
-static long syz_process_self()
+static long syz_process_self(void)
{
return zx_process_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_thread_self
-static long syz_thread_self()
+static long syz_thread_self(void)
{
return zx_thread_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_vmar_root_self
-static long syz_vmar_root_self()
+static long syz_vmar_root_self(void)
{
return zx_vmar_root_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_job_default
-static long syz_job_default()
+static long syz_job_default(void)
{
return zx_job_default();
}
@@ -242,3 +245,7 @@ static int do_sandbox_none(void)
#define do_sandbox_setuid() 0
#define do_sandbox_namespace() 0
#endif
+
+// Ugly way to work around gcc's "error: function called through a non-compatible type".
+// The macro is used in generated C code.
+#define CAST(f) ({void* p = (void*)f; p; })
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 46d1711f7..69be3ff2a 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -218,7 +218,7 @@ func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCo
if args != "" {
args = args[1:]
}
- fmt.Fprintf(w, "((long(*)(%v))%v)(", args, callName)
+ fmt.Fprintf(w, "((long(*)(%v))CAST(%v))(", args, callName)
}
for ai, arg := range call.Args {
if native || ai > 0 {
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index 595a87095..4f8d32f15 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -49,7 +49,7 @@ static __thread jmp_buf segv_env;
#if GOOS_akaros
#include <parlib/parlib.h>
-static void recover()
+static void recover(void)
{
_longjmp(segv_env, 1);
}
@@ -74,7 +74,7 @@ static void segv_handler(int sig, siginfo_t* info, void* ctx)
doexit(sig);
}
-static void install_segv_handler()
+static void install_segv_handler(void)
{
struct sigaction sa;
#if GOOS_linux
@@ -127,7 +127,7 @@ static void sleep_ms(uint64 ms)
#if SYZ_EXECUTOR || SYZ_THREADED || SYZ_REPEAT && SYZ_EXECUTOR_USES_FORK_SERVER
#include <time.h>
-static uint64 current_time_ms()
+static uint64 current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
@@ -141,7 +141,7 @@ static uint64 current_time_ms()
#include <sys/stat.h>
#include <unistd.h>
-static void use_temporary_dir()
+static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
@@ -407,7 +407,6 @@ static int do_sandbox_none(void)
#elif GOOS_fuchsia
-#include <ddk/driver.h>
#include <fcntl.h>
#include <lib/fdio/util.h>
#include <poll.h>
@@ -426,6 +425,10 @@ static int do_sandbox_none(void)
#include <zircon/process.h>
#include <zircon/syscalls.h>
+#if SYZ_EXECUTOR || __NR_get_root_resource
+#include <ddk/driver.h>
+#endif
+
#if SYZ_EXECUTOR || SYZ_HANDLE_SEGV
#include <pthread.h>
#include <setjmp.h>
@@ -437,7 +440,7 @@ static int do_sandbox_none(void)
static __thread int skip_segv;
static __thread jmp_buf segv_env;
-static void segv_handler()
+static void segv_handler(void)
{
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED)) {
debug("recover: skipping\n");
@@ -495,7 +498,7 @@ static void* ex_handler(void* arg)
return 0;
}
-static void install_segv_handler()
+static void install_segv_handler(void)
{
zx_status_t status;
zx_handle_t port;
@@ -587,28 +590,28 @@ long syz_mmap(size_t addr, size_t size)
#endif
#if SYZ_EXECUTOR || __NR_syz_process_self
-static long syz_process_self()
+static long syz_process_self(void)
{
return zx_process_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_thread_self
-static long syz_thread_self()
+static long syz_thread_self(void)
{
return zx_thread_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_vmar_root_self
-static long syz_vmar_root_self()
+static long syz_vmar_root_self(void)
{
return zx_vmar_root_self();
}
#endif
#if SYZ_EXECUTOR || __NR_syz_job_default
-static long syz_job_default()
+static long syz_job_default(void)
{
return zx_job_default();
}
@@ -644,6 +647,7 @@ static int do_sandbox_none(void)
#define do_sandbox_setuid() 0
#define do_sandbox_namespace() 0
#endif
+#define CAST(f) ({void* p = (void*)f; p; })
#elif GOOS_linux
@@ -3759,9 +3763,9 @@ static void* thr(void* arg)
}
#if SYZ_REPEAT
-static void execute_one()
+static void execute_one(void)
#else
-static void loop()
+static void loop(void)
#endif
{
#if SYZ_REPRO
@@ -3777,7 +3781,7 @@ static void loop()
again:
#endif
for (call = 0; call < [[NUM_CALLS]]; call++) {
- for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
+ for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
@@ -3812,7 +3816,7 @@ again:
#endif
#if SYZ_EXECUTOR || SYZ_REPEAT
-static void execute_one();
+static void execute_one(void);
#if SYZ_EXECUTOR_USES_FORK_SERVER
#include <signal.h>
#include <sys/types.h>
@@ -3828,7 +3832,7 @@ static void execute_one();
static void reply_handshake();
#endif
-static void loop()
+static void loop(void)
{
#if SYZ_HAVE_SETUP_LOOP
setup_loop();
@@ -3939,7 +3943,7 @@ static void loop()
}
}
#else
-static void loop()
+static void loop(void)
{
execute_one();
}
@@ -3954,9 +3958,9 @@ static void loop()
#if SYZ_THREADED
void execute_call(int call)
#elif SYZ_REPEAT
-void execute_one()
+void execute_one(void)
#else
-void loop()
+void loop(void)
#endif
{
[[SYSCALLS]]
@@ -3973,7 +3977,7 @@ int main(int argc, char** argv)
if (argc == 2 && strcmp(argv[1], "child") == 0)
child();
#else
-int main()
+int main(void)
{
[[MMAP_DATA]]
#endif
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index ea742f14e..b9a278aec 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -185,7 +185,6 @@ var List = map[string]map[string]*Target{
CCompiler: os.ExpandEnv("${SOURCEDIR}/buildtools/linux-x64/clang/bin/clang++"),
CrossCFlags: []string{
"-Wno-deprecated",
- "-Wno-error",
"--target=x86_64-fuchsia",
"-lfdio",
"-lzircon",
@@ -203,7 +202,6 @@ var List = map[string]map[string]*Target{
CCompiler: os.ExpandEnv("${SOURCEDIR}/buildtools/linux-x64/clang/bin/clang++"),
CrossCFlags: []string{
"-Wno-deprecated",
- "-Wno-error",
"--target=aarch64-fuchsia",
"-lfdio",
"-lzircon",