Dusting away the bitrot, plus adding a COMPILING and LINKING line in the INFO log.

This commit is contained in:
Ian A. Mason 2022-09-06 16:54:43 -07:00
parent 48db30df93
commit 65d0c8c002
8 changed files with 74 additions and 101 deletions

View File

@ -5,11 +5,12 @@ help:
@echo ''
@echo 'Here are the targets:'
@echo ''
@echo 'To test : "make check"'
@echo 'To test : "make test"'
@echo 'To develop : "make develop"'
@echo 'To install : "make install"'
@echo 'To format : "make format"'
@echo 'To lint : "make lint"'
@echo 'To vet : "make vet"'
@echo 'To staticcheck : "make check"'
@echo 'To clean : "make clean"'
@echo ''
@ -20,14 +21,17 @@ develop:
go install github.com/SRI-CSL/gllvm/cmd/...
check: develop
test: develop
go test -v ./tests
format:
gofmt -s -w shared/*.go tests/*.go cmd/*/*.go
lint:
golint ./shared/ ./tests/ ./cmd/...
check:
staticcheck ./...
vet:
go vet ./...
clean:
rm -f data/*hello data/*.bc [td]*/.*.c.o [td]*/*.o [td]*/.*.c.o.bc data/*.notanextensionthatwerecognize

View File

@ -35,7 +35,6 @@ package shared
import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -84,8 +83,8 @@ func Compile(args []string, compiler string) (exitCode int) {
if compiler == "flang" {
wg.Add(1)
go execCompile(compilerExecName, pr, &wg, &ok)
wg.Wait();
wg.Add(1);
wg.Wait()
wg.Add(1)
go buildAndAttachBitcode(compilerExecName, pr, &bcObjLinks, &newObjectFiles, &wg)
wg.Wait()
} else {
@ -191,7 +190,7 @@ func injectPath(extension, bcFile, objFile string) (success bool) {
// Store bitcode path to temp file
var absBcPath, _ = filepath.Abs(bcFile)
tmpContent := []byte(absBcPath + "\n")
tmpFile, err := ioutil.TempFile("", "gllvm")
tmpFile, err := os.CreateTemp("", "gllvm")
if err != nil {
LogError("attachBitcodePathToObject: %v\n", err)
return
@ -313,10 +312,12 @@ func execCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, o
// But for the now, we just remove forbidden arguments
var success bool
var err error
var linking = false
// start afresh
arguments := []string{}
// we are linking rather than compiling
if len(pr.InputFiles) == 0 && len(pr.LinkArgs) > 0 {
linking = true
if pr.IsLTO {
arguments = append(arguments, LLVMLtoLDFLAGS...)
}
@ -338,6 +339,11 @@ func execCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, o
} else {
arguments = append(arguments, pr.InputList...)
}
if linking {
LogInfo("LINKING with %v using %v", compilerExecName, arguments)
} else {
LogInfo("COMPILING with %v using %v", compilerExecName, arguments)
}
LogDebug("Calling execCmd(%v, %v)", compilerExecName, arguments)
success, err = execCmd(compilerExecName, arguments, "")
if !success {
@ -346,41 +352,6 @@ func execCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, o
}
}
// Tries to build object file
func oldExecCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, ok *bool) {
defer (*wg).Done()
//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
}
}
// GetCompilerExecName returns the full path of the executable
func GetCompilerExecName(compiler string) string {
switch compiler {

View File

@ -39,7 +39,6 @@ import (
"debug/macho"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
@ -467,7 +466,7 @@ func handleArchive(ea ExtractionArgs) (success bool) {
LogInfo("handleArchive: ExtractionArgs = %v\n", ea)
// Create tmp dir
tmpDirName, err := ioutil.TempDir("", "gllvm")
tmpDirName, err := os.MkdirTemp("", "gllvm")
if err != nil {
LogError("The temporary directory in which to extract object files could not be created.")
return
@ -607,7 +606,7 @@ func fetchArgMax(ea ExtractionArgs) (argMax int) {
func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argMax int, linkArgs []string) (success bool) {
var tmpFileList []string
// Create tmp dir
tmpDirName, err := ioutil.TempDir(".", "glinking")
tmpDirName, err := os.MkdirTemp(".", "glinking")
if err != nil {
LogError("The temporary directory in which to put temporary linking files could not be created.")
return
@ -619,7 +618,7 @@ func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argM
LogInfo("Keeping the temporary folder")
}
tmpFile, err := ioutil.TempFile(tmpDirName, "tmp")
tmpFile, err := os.CreateTemp(tmpDirName, "tmp")
if err != nil {
LogError("The temporary linking file could not be created.")
return
@ -643,7 +642,7 @@ func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argM
if ea.Verbose {
linkArgs = append(linkArgs, "-v")
}
tmpFile, err = ioutil.TempFile(tmpDirName, "tmp")
tmpFile, err = os.CreateTemp(tmpDirName, "tmp")
if err != nil {
LogError("Could not generate a temp file in %s because %v.\n", tmpDirName, err)
success = false
@ -778,13 +777,13 @@ func writeManifest(ea ExtractionArgs, bcFiles []string, artifactFiles []string)
section1 := "Physical location of extracted files:\n" + strings.Join(bcFiles, "\n") + "\n\n"
section2 := "Build-time location of extracted files:\n" + strings.Join(artifactFiles, "\n")
contents := []byte(section1 + section2)
if err := ioutil.WriteFile(manifestFilename, contents, 0644); err != nil {
if err := os.WriteFile(manifestFilename, contents, 0644); err != nil {
LogError("There was an error while writing the manifest file: ", err)
return
}
} else {
contents := []byte("\n" + strings.Join(bcFiles, "\n") + "\n")
if err := ioutil.WriteFile(manifestFilename, contents, 0644); err != nil {
if err := os.WriteFile(manifestFilename, contents, 0644); err != nil {
LogError("There was an error while writing the manifest file: ", err)
return
}

View File

@ -108,7 +108,6 @@ type sanityArgs struct {
// 2. Checks that the compiler settings make sense.
// 3. Checks that the needed LLVM utilities exists.
// 4. Check that the store, if set, exists.
//
func SanityCheck() {
sa := parseSanitySwitches()