aboutsummaryrefslogtreecommitdiffstats
path: root/csource
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-01-08 15:28:38 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-01-09 20:20:49 +0100
commitc5f38186d296b1e4ce59cb51889bce481cce266d (patch)
tree35898518a1507f8acc4e5b3ee0529eb9a0c95d85 /csource
parent43d5c364a2cad2f4673499a74345088904b2c876 (diff)
csource: compile with -Werror
Check for compiler warnings during compilation. Don't require -std=c99. Fix existing compiler warnings.
Diffstat (limited to 'csource')
-rw-r--r--csource/common.go4
-rw-r--r--csource/csource.go14
-rw-r--r--csource/csource_test.go2
3 files changed, 10 insertions, 10 deletions
diff --git a/csource/common.go b/csource/common.go
index f63674724..5310ef0b5 100644
--- a/csource/common.go
+++ b/csource/common.go
@@ -49,8 +49,9 @@ const int kRetryStatus = 69;
__attribute__((noreturn)) void doexit(int status)
{
+ volatile unsigned i;
syscall(__NR_exit_group, status);
- for (volatile unsigned i = 0;; i++) {
+ for (i = 0;; i++) {
}
}
@@ -649,7 +650,6 @@ void loop()
uint64_t start = current_time_ms();
for (;;) {
int res = waitpid(-1, &status, __WALL | WNOHANG);
- int errno0 = errno;
if (res == pid)
break;
usleep(1000);
diff --git a/csource/csource.go b/csource/csource.go
index 6d4d3d46e..764db92ed 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -108,7 +108,7 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
if !opts.Threaded && !opts.Collide {
fmt.Fprintf(w, "void %v()\n{\n", name)
if opts.Repro {
- fmt.Fprintf(w, "\twrite(1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
+ fmt.Fprintf(w, "\tsyscall(SYS_write, 1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
}
fmt.Fprintf(w, "\tmemset(r, -1, sizeof(r));\n")
for _, c := range calls {
@@ -131,7 +131,7 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
fmt.Fprintf(w, "\tpthread_t th[%v];\n", 2*len(calls))
fmt.Fprintf(w, "\n")
if opts.Repro {
- fmt.Fprintf(w, "\twrite(1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
+ fmt.Fprintf(w, "\tsyscall(SYS_write, 1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
}
fmt.Fprintf(w, "\tmemset(r, -1, sizeof(r));\n")
fmt.Fprintf(w, "\tsrand(getpid());\n")
@@ -297,18 +297,18 @@ func preprocessCommonHeader(opts Options, handled map[string]int) (string, error
return out, nil
}
-// Build builds a C/C++ program from source file src
-// and returns name of the resulting binary.
-func Build(src string) (string, error) {
+// Build builds a C/C++ program from source src and returns name of the resulting binary.
+// lang can be "c" or "c++".
+func Build(lang, src string) (string, error) {
bin, err := ioutil.TempFile("", "syzkaller")
if err != nil {
return "", fmt.Errorf("failed to create temp file: %v", err)
}
bin.Close()
- out, err := exec.Command("gcc", "-x", "c", "-std=gnu99", src, "-o", bin.Name(), "-pthread", "-static", "-O1", "-g").CombinedOutput()
+ out, err := exec.Command("gcc", "-x", lang, "-Wall", "-Werror", src, "-o", bin.Name(), "-pthread", "-static", "-O1", "-g").CombinedOutput()
if err != nil {
// Some distributions don't have static libraries.
- out, err = exec.Command("gcc", "-x", "c++", "-std=gnu++11", src, "-o", bin.Name(), "-pthread", "-O1", "-g").CombinedOutput()
+ out, err = exec.Command("gcc", "-x", lang, "-Wall", "-Werror", src, "-o", bin.Name(), "-pthread", "-O1", "-g").CombinedOutput()
}
if err != nil {
os.Remove(bin.Name())
diff --git a/csource/csource_test.go b/csource/csource_test.go
index ff35a2883..e8c1fc3a4 100644
--- a/csource/csource_test.go
+++ b/csource/csource_test.go
@@ -78,7 +78,7 @@ func testOne(t *testing.T, p *prog.Prog, opts Options) {
t.Fatalf("%v", err)
}
defer os.Remove(srcf)
- bin, err := Build(srcf)
+ bin, err := Build("c", srcf)
if err != nil {
t.Logf("program:\n%s\n", p.Serialize())
t.Fatalf("%v", err)