aboutsummaryrefslogtreecommitdiffstats
path: root/csource/csource.go
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/csource.go
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/csource.go')
-rw-r--r--csource/csource.go14
1 files changed, 7 insertions, 7 deletions
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())