mirror of
https://github.com/danog/gllvm.git
synced 2024-11-30 04:09:02 +01:00
Dusting away the bitrot, plus adding a COMPILING and LINKING line in the INFO log.
This commit is contained in:
parent
48db30df93
commit
65d0c8c002
14
Makefile
14
Makefile
@ -5,11 +5,12 @@ help:
|
|||||||
@echo ''
|
@echo ''
|
||||||
@echo 'Here are the targets:'
|
@echo 'Here are the targets:'
|
||||||
@echo ''
|
@echo ''
|
||||||
@echo 'To test : "make check"'
|
@echo 'To test : "make test"'
|
||||||
@echo 'To develop : "make develop"'
|
@echo 'To develop : "make develop"'
|
||||||
@echo 'To install : "make install"'
|
@echo 'To install : "make install"'
|
||||||
@echo 'To format : "make format"'
|
@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 'To clean : "make clean"'
|
||||||
@echo ''
|
@echo ''
|
||||||
|
|
||||||
@ -20,14 +21,17 @@ develop:
|
|||||||
go install github.com/SRI-CSL/gllvm/cmd/...
|
go install github.com/SRI-CSL/gllvm/cmd/...
|
||||||
|
|
||||||
|
|
||||||
check: develop
|
test: develop
|
||||||
go test -v ./tests
|
go test -v ./tests
|
||||||
|
|
||||||
format:
|
format:
|
||||||
gofmt -s -w shared/*.go tests/*.go cmd/*/*.go
|
gofmt -s -w shared/*.go tests/*.go cmd/*/*.go
|
||||||
|
|
||||||
lint:
|
check:
|
||||||
golint ./shared/ ./tests/ ./cmd/...
|
staticcheck ./...
|
||||||
|
|
||||||
|
vet:
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f data/*hello data/*.bc [td]*/.*.c.o [td]*/*.o [td]*/.*.c.o.bc data/*.notanextensionthatwerecognize
|
rm -f data/*hello data/*.bc [td]*/.*.c.o [td]*/*.o [td]*/.*.c.o.bc data/*.notanextensionthatwerecognize
|
||||||
|
@ -35,7 +35,6 @@ package shared
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -84,8 +83,8 @@ func Compile(args []string, compiler string) (exitCode int) {
|
|||||||
if compiler == "flang" {
|
if compiler == "flang" {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go execCompile(compilerExecName, pr, &wg, &ok)
|
go execCompile(compilerExecName, pr, &wg, &ok)
|
||||||
wg.Wait();
|
wg.Wait()
|
||||||
wg.Add(1);
|
wg.Add(1)
|
||||||
go buildAndAttachBitcode(compilerExecName, pr, &bcObjLinks, &newObjectFiles, &wg)
|
go buildAndAttachBitcode(compilerExecName, pr, &bcObjLinks, &newObjectFiles, &wg)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
} else {
|
} else {
|
||||||
@ -191,7 +190,7 @@ func injectPath(extension, bcFile, objFile string) (success bool) {
|
|||||||
// Store bitcode path to temp file
|
// Store bitcode path to temp file
|
||||||
var absBcPath, _ = filepath.Abs(bcFile)
|
var absBcPath, _ = filepath.Abs(bcFile)
|
||||||
tmpContent := []byte(absBcPath + "\n")
|
tmpContent := []byte(absBcPath + "\n")
|
||||||
tmpFile, err := ioutil.TempFile("", "gllvm")
|
tmpFile, err := os.CreateTemp("", "gllvm")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("attachBitcodePathToObject: %v\n", err)
|
LogError("attachBitcodePathToObject: %v\n", err)
|
||||||
return
|
return
|
||||||
@ -313,10 +312,12 @@ func execCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, o
|
|||||||
// But for the now, we just remove forbidden arguments
|
// But for the now, we just remove forbidden arguments
|
||||||
var success bool
|
var success bool
|
||||||
var err error
|
var err error
|
||||||
|
var linking = false
|
||||||
// start afresh
|
// start afresh
|
||||||
arguments := []string{}
|
arguments := []string{}
|
||||||
// we are linking rather than compiling
|
// we are linking rather than compiling
|
||||||
if len(pr.InputFiles) == 0 && len(pr.LinkArgs) > 0 {
|
if len(pr.InputFiles) == 0 && len(pr.LinkArgs) > 0 {
|
||||||
|
linking = true
|
||||||
if pr.IsLTO {
|
if pr.IsLTO {
|
||||||
arguments = append(arguments, LLVMLtoLDFLAGS...)
|
arguments = append(arguments, LLVMLtoLDFLAGS...)
|
||||||
}
|
}
|
||||||
@ -338,6 +339,11 @@ func execCompile(compilerExecName string, pr ParserResult, wg *sync.WaitGroup, o
|
|||||||
} else {
|
} else {
|
||||||
arguments = append(arguments, pr.InputList...)
|
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)
|
LogDebug("Calling execCmd(%v, %v)", compilerExecName, arguments)
|
||||||
success, err = execCmd(compilerExecName, arguments, "")
|
success, err = execCmd(compilerExecName, arguments, "")
|
||||||
if !success {
|
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
|
// GetCompilerExecName returns the full path of the executable
|
||||||
func GetCompilerExecName(compiler string) string {
|
func GetCompilerExecName(compiler string) string {
|
||||||
switch compiler {
|
switch compiler {
|
||||||
|
@ -39,7 +39,6 @@ import (
|
|||||||
"debug/macho"
|
"debug/macho"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -467,7 +466,7 @@ func handleArchive(ea ExtractionArgs) (success bool) {
|
|||||||
LogInfo("handleArchive: ExtractionArgs = %v\n", ea)
|
LogInfo("handleArchive: ExtractionArgs = %v\n", ea)
|
||||||
|
|
||||||
// Create tmp dir
|
// Create tmp dir
|
||||||
tmpDirName, err := ioutil.TempDir("", "gllvm")
|
tmpDirName, err := os.MkdirTemp("", "gllvm")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("The temporary directory in which to extract object files could not be created.")
|
LogError("The temporary directory in which to extract object files could not be created.")
|
||||||
return
|
return
|
||||||
@ -607,7 +606,7 @@ func fetchArgMax(ea ExtractionArgs) (argMax int) {
|
|||||||
func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argMax int, linkArgs []string) (success bool) {
|
func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argMax int, linkArgs []string) (success bool) {
|
||||||
var tmpFileList []string
|
var tmpFileList []string
|
||||||
// Create tmp dir
|
// Create tmp dir
|
||||||
tmpDirName, err := ioutil.TempDir(".", "glinking")
|
tmpDirName, err := os.MkdirTemp(".", "glinking")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("The temporary directory in which to put temporary linking files could not be created.")
|
LogError("The temporary directory in which to put temporary linking files could not be created.")
|
||||||
return
|
return
|
||||||
@ -619,7 +618,7 @@ func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argM
|
|||||||
LogInfo("Keeping the temporary folder")
|
LogInfo("Keeping the temporary folder")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpFile, err := ioutil.TempFile(tmpDirName, "tmp")
|
tmpFile, err := os.CreateTemp(tmpDirName, "tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("The temporary linking file could not be created.")
|
LogError("The temporary linking file could not be created.")
|
||||||
return
|
return
|
||||||
@ -643,7 +642,7 @@ func linkBitcodeFilesIncrementally(ea ExtractionArgs, filesToLink []string, argM
|
|||||||
if ea.Verbose {
|
if ea.Verbose {
|
||||||
linkArgs = append(linkArgs, "-v")
|
linkArgs = append(linkArgs, "-v")
|
||||||
}
|
}
|
||||||
tmpFile, err = ioutil.TempFile(tmpDirName, "tmp")
|
tmpFile, err = os.CreateTemp(tmpDirName, "tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("Could not generate a temp file in %s because %v.\n", tmpDirName, err)
|
LogError("Could not generate a temp file in %s because %v.\n", tmpDirName, err)
|
||||||
success = false
|
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"
|
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")
|
section2 := "Build-time location of extracted files:\n" + strings.Join(artifactFiles, "\n")
|
||||||
contents := []byte(section1 + section2)
|
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)
|
LogError("There was an error while writing the manifest file: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
contents := []byte("\n" + strings.Join(bcFiles, "\n") + "\n")
|
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)
|
LogError("There was an error while writing the manifest file: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,6 @@ type sanityArgs struct {
|
|||||||
// 2. Checks that the compiler settings make sense.
|
// 2. Checks that the compiler settings make sense.
|
||||||
// 3. Checks that the needed LLVM utilities exists.
|
// 3. Checks that the needed LLVM utilities exists.
|
||||||
// 4. Check that the store, if set, exists.
|
// 4. Check that the store, if set, exists.
|
||||||
//
|
|
||||||
func SanityCheck() {
|
func SanityCheck() {
|
||||||
|
|
||||||
sa := parseSanitySwitches()
|
sa := parseSanitySwitches()
|
||||||
|
Loading…
Reference in New Issue
Block a user