From 08903954e1e703a8d066a2bb30955196a5b70366 Mon Sep 17 00:00:00 2001 From: "Ian A. Mason" Date: Thu, 24 May 2018 17:41:49 -0700 Subject: [PATCH] Various fixes, including one for the dead_strip issue. Issue #22. --- examples/issue19/Makefile | 10 ++-- examples/linux-kernel/install-kernel.sh | 8 ++-- shared/compiler.go | 27 ++++++++++- shared/constants.go | 5 +- shared/extractor.go | 2 +- shared/parser.go | 62 ++++++++++++------------- shared/utils.go | 2 +- 7 files changed, 70 insertions(+), 46 deletions(-) diff --git a/examples/issue19/Makefile b/examples/issue19/Makefile index c546a33..86be390 100644 --- a/examples/issue19/Makefile +++ b/examples/issue19/Makefile @@ -1,9 +1,8 @@ +all: test - - -one: - ${CC} test.c -fsanitize=address -o test +#one: +# ${CC} test.c -dead_strip -fsanitize=address -o test test.o: @@ -11,10 +10,9 @@ test.o: test: test.o - ${CC} test.o -fsanitize=address -o test + ${CC} test.o -dead_strip -fsanitize=address -o test clean: rm -f test.o test .test* *~ - diff --git a/examples/linux-kernel/install-kernel.sh b/examples/linux-kernel/install-kernel.sh index 469b736..fb59236 100755 --- a/examples/linux-kernel/install-kernel.sh +++ b/examples/linux-kernel/install-kernel.sh @@ -1,11 +1,11 @@ #!/usr/bin/env bash ### Copy vmlinux into the bootable linux folder and install the new kernel -cp $HOME/standalone-build/vmlinux $HOME/bootable-linux/ +cp $HOME/standalone-build/vmlinux $HOME/linux-stable/ -cd $HOME/bootable-linux +cd $HOME/linux-stable -scripts/sortextable vmlinux +scripts/sortextable vmlinux nm -n vmlinux | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( .L\)' > System.map -make CC=clang HOSTCC=clang +make CC=gclang HOSTCC=gclang sudo make modules_install install diff --git a/shared/compiler.go b/shared/compiler.go index f2e274f..0e707fc 100644 --- a/shared/compiler.go +++ b/shared/compiler.go @@ -211,6 +211,8 @@ func compileTimeLinkFiles(compilerExecName string, pr parserResult, objFiles []s LogError("%v %v failed to link: %v.", compilerExecName, args, err) //was LogFatal return + } else { + LogInfo("LINKING: %v %v", compilerExecName, args) } } @@ -241,7 +243,30 @@ func buildBitcodeFile(compilerExecName string, pr parserResult, srcFile string, // Tries to build object file func execCompile(compilerExecName string, pr parserResult, wg *sync.WaitGroup, ok *bool) { defer (*wg).Done() - success, err := execCmd(compilerExecName, pr.InputList, "") + //iam: strickly speaking we should do more work here depending on whether this is + // a compile only, a link only, or ... + // But for the now, we just remove forbidden arguments + var success bool + var err error + if len(pr.ForbiddenFlags) > 0 { + filteredArgs := pr.InputList[:0] + for _, arg := range pr.InputList { + found := false + for _, bad := range pr.ForbiddenFlags { + if bad == arg { + found = true + break + } + } + if !found { + filteredArgs = append(filteredArgs, arg) + } + } + success, err = execCmd(compilerExecName, filteredArgs, "") + } else { + success, err = execCmd(compilerExecName, pr.InputList, "") + } + if !success { LogError("Failed to compile using given arguments:\n%v %v\nexit status: %v\n", compilerExecName, pr.InputList, err) *ok = false diff --git a/shared/constants.go b/shared/constants.go index b9f8dd2..5290660 100644 --- a/shared/constants.go +++ b/shared/constants.go @@ -43,10 +43,11 @@ package shared // May 2 2018 handleArchives rewritten to handle multiple occurrences of files with the same name. // corresponds with wllvm 1.2.0. Gonna try and keep them in synch. // 1.2.1 May 13th 2018 -fsanitize= needs to be compile AND link. +// 1.2.2 May 24th 2018 Fix extracting from archives on darwin, plus travis build for both linux and darwin. // -const gllvmVersion = "1.2.1" -const gllvmReleaseDate = "May 23 2018" +const gllvmVersion = "1.2.2" +const gllvmReleaseDate = "May 24 2018" const osDARWIN = "darwin" const osLINUX = "linux" diff --git a/shared/extractor.go b/shared/extractor.go index 61ab35c..a40c304 100644 --- a/shared/extractor.go +++ b/shared/extractor.go @@ -324,7 +324,7 @@ func listArchiveFiles(inputFile string) (contents []string) { func extractFile(archive string, filename string, instance int) bool { var arArgs []string - if runtime.GOOS != osDARWIN { + if runtime.GOOS != osDARWIN { arArgs = append(arArgs, "xN") arArgs = append(arArgs, strconv.Itoa(instance)) } else { diff --git a/shared/parser.go b/shared/parser.go index feffe9a..2ca9a51 100644 --- a/shared/parser.go +++ b/shared/parser.go @@ -40,7 +40,6 @@ import ( "path" "path/filepath" "regexp" - "runtime" "strings" ) @@ -51,6 +50,7 @@ type parserResult struct { OutputFilename string CompileArgs []string LinkArgs []string + ForbiddenFlags []string IsVerbose bool IsDependencyOnly bool IsPreprocessOnly bool @@ -219,10 +219,10 @@ func parse(argList []string) parserResult { "-Xassembler": {1, pr.defaultBinaryCallback}, "-Xlinker": {1, pr.defaultBinaryCallback}, - "-l": {1, pr.linkBinaryCallback}, - "-L": {1, pr.linkBinaryCallback}, - "-T": {1, pr.linkBinaryCallback}, - "-u": {1, pr.linkBinaryCallback}, + "-l": {1, pr.linkBinaryCallback}, + "-L": {1, pr.linkBinaryCallback}, + "-T": {1, pr.linkBinaryCallback}, + "-u": {1, pr.linkBinaryCallback}, "-install_name": {1, pr.linkBinaryCallback}, "-e": {1, pr.linkBinaryCallback}, @@ -248,7 +248,8 @@ func parse(argList []string) parserResult { "-coverage": {0, pr.compileLinkUnaryCallback}, "--coverage": {0, pr.compileLinkUnaryCallback}, - "-Wl,-dead_strip": {0, pr.darwinWarningLinkUnaryCallback}, + "-Wl,-dead_strip": {0, pr.warningLinkUnaryCallback}, + "-dead_strip": {0, pr.warningLinkUnaryCallback}, //iam: tor does this. We lose the bitcode :-( } var argPatterns = map[string]flagInfo{ @@ -263,25 +264,27 @@ func parse(argList []string) parserResult { `^-B.+$`: {0, pr.compileLinkUnaryCallback}, `^-isystem.+$`: {0, pr.compileLinkUnaryCallback}, `^-U.+$`: {0, pr.compileUnaryCallback}, - `^-Wl,.+$`: {0, pr.linkUnaryCallback}, - `^-W[^l].*$`: {0, pr.compileUnaryCallback}, - `^-fsanitize=.+$`: {0, pr.compileLinkUnaryCallback}, - `^-f.+$`: {0, pr.compileUnaryCallback}, - `^-rtlib=.+$`: {0, pr.linkUnaryCallback}, - `^-std=.+$`: {0, pr.compileUnaryCallback}, - `^-stdlib=.+$`: {0, pr.compileLinkUnaryCallback}, - `^-mtune=.+$`: {0, pr.compileUnaryCallback}, - `^--sysroot=.+$`: {0, pr.compileUnaryCallback}, - `^-print-prog-name=.*$`: {0, pr.compileUnaryCallback}, - `^-print-file-name=.*$`: {0, pr.compileUnaryCallback}, - `^-mmacosx-version-min=.+$`: {0, pr.compileLinkUnaryCallback}, - `^-mstack-alignment=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^-march=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^-mregparm=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^-mcmodel=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^-mpreferred-stack-boundary=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^-mindirect-branch=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff - `^--param=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + //iam: need to be careful here, not mix up linker and warning flags. + `^-Wl,.+$`: {0, pr.linkUnaryCallback}, + `^-W[^l].*$`: {0, pr.compileUnaryCallback}, + `^-W[l][^,].*$`: {0, pr.compileUnaryCallback}, //iam: tor has a few -Wl... + `^-fsanitize=.+$`: {0, pr.compileLinkUnaryCallback}, + `^-f.+$`: {0, pr.compileUnaryCallback}, + `^-rtlib=.+$`: {0, pr.linkUnaryCallback}, + `^-std=.+$`: {0, pr.compileUnaryCallback}, + `^-stdlib=.+$`: {0, pr.compileLinkUnaryCallback}, + `^-mtune=.+$`: {0, pr.compileUnaryCallback}, + `^--sysroot=.+$`: {0, pr.compileUnaryCallback}, + `^-print-prog-name=.*$`: {0, pr.compileUnaryCallback}, + `^-print-file-name=.*$`: {0, pr.compileUnaryCallback}, + `^-mmacosx-version-min=.+$`: {0, pr.compileLinkUnaryCallback}, + `^-mstack-alignment=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^-march=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^-mregparm=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^-mcmodel=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^-mpreferred-stack-boundary=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^-mindirect-branch=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff + `^--param=.+$`: {0, pr.compileUnaryCallback}, //iam: linux kernel stuff } @@ -406,12 +409,9 @@ func (pr *parserResult) compileUnaryCallback(flag string, _ []string) { pr.CompileArgs = append(pr.CompileArgs, flag) } -func (pr *parserResult) darwinWarningLinkUnaryCallback(flag string, _ []string) { - if runtime.GOOS == osDARWIN { - fmt.Println("The flag", flag, "cannot be used with this tool.") - } else { - pr.LinkArgs = append(pr.LinkArgs, flag) - } +func (pr *parserResult) warningLinkUnaryCallback(flag string, _ []string) { + LogWarning("The flag %v cannot be used with this tool, we ignore it, else we lose the bitcode section.\n", flag) + pr.ForbiddenFlags = append(pr.ForbiddenFlags, flag) } func (pr *parserResult) defaultBinaryCallback(_ string, _ []string) { diff --git a/shared/utils.go b/shared/utils.go index 85ddcff..db4f744 100644 --- a/shared/utils.go +++ b/shared/utils.go @@ -51,7 +51,7 @@ func execCmd(cmdExecName string, args []string, workingDir string) (success bool if err != nil { ecode = 1 } - LogDebug("execCmd: %v %v in %v had exitCode %v\n", cmdExecName, args, workingDir, ecode) + LogDebug("execCmd: %v %v had exitCode %v\n", cmdExecName, args, ecode) if err != nil { LogDebug("execCmd: error was %v\n", err) }