mirror of
https://github.com/danog/gllvm.git
synced 2024-11-27 01:44:41 +01:00
golinting [ci skip]
This commit is contained in:
parent
e930bbf2e2
commit
d84ff829af
14
compiler.go
14
compiler.go
@ -20,7 +20,7 @@ type bitcodeToObjectLink struct {
|
||||
func compile(args []string, compilerName string) {
|
||||
var compilerExecName = getCompilerExecName(compilerName)
|
||||
var configureOnly bool
|
||||
if os.Getenv(envCONFIGURE_ONLY) != "" {
|
||||
if os.Getenv(envCONFIGUREONLY) != "" {
|
||||
configureOnly = true
|
||||
}
|
||||
var pr = parse(args)
|
||||
@ -113,17 +113,17 @@ func attachBitcodePathToObject(bcFile, objFile string) {
|
||||
var attachCmdArgs []string
|
||||
if runtime.GOOS == "darwin" {
|
||||
attachCmd = "ld"
|
||||
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", darwinSEGMENT_NAME, darwinSECTION_NAME, tmpFile.Name(), "-o", objFile}
|
||||
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", darwinSEGMENTNAME, darwinSECTIONNAME, tmpFile.Name(), "-o", objFile}
|
||||
} else {
|
||||
attachCmd = "objcopy"
|
||||
attachCmdArgs = []string{"--add-section", elfSECTION_NAME + "=" + tmpFile.Name(), objFile}
|
||||
attachCmdArgs = []string{"--add-section", elfSECTIONNAME + "=" + tmpFile.Name(), objFile}
|
||||
}
|
||||
|
||||
// Run the attach command and ignore errors
|
||||
execCmd(attachCmd, attachCmdArgs, "")
|
||||
|
||||
// Copy bitcode file to store, if necessary
|
||||
if bcStorePath := os.Getenv(envBC_STORE_PATH); bcStorePath != "" {
|
||||
if bcStorePath := os.Getenv(envBCSTOREPATH); bcStorePath != "" {
|
||||
destFilePath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
||||
in, _ := os.Open(absBcPath)
|
||||
defer in.Close()
|
||||
@ -175,16 +175,16 @@ func execCompile(compilerExecName string, pr parserResult, wg *sync.WaitGroup) {
|
||||
}
|
||||
|
||||
func getCompilerExecName(compilerName string) string {
|
||||
var compilerPath = os.Getenv(envTOOLS_PATH)
|
||||
var compilerPath = os.Getenv(envTOOLSPATH)
|
||||
switch compilerName {
|
||||
case "clang":
|
||||
var clangName = os.Getenv(envC_COMPILER_NAME)
|
||||
var clangName = os.Getenv(envCCOMPILERNAME)
|
||||
if clangName != "" {
|
||||
return compilerPath + clangName
|
||||
}
|
||||
return compilerPath + compilerName
|
||||
case "clang++":
|
||||
var clangppName = os.Getenv(envC_COMPILER_NAME)
|
||||
var clangppName = os.Getenv(envCCOMPILERNAME)
|
||||
if clangppName != "" {
|
||||
return compilerPath + clangppName
|
||||
}
|
||||
|
32
constants.go
32
constants.go
@ -2,28 +2,28 @@ package main
|
||||
|
||||
const (
|
||||
// Environment variables
|
||||
envCONFIGURE_ONLY = "GLLVM_CONFIGURE_ONLY"
|
||||
envTOOLS_PATH = "GLLVM_TOOLS_PATH"
|
||||
envC_COMPILER_NAME = "GLLVM_CC_NAME"
|
||||
envCXX_COMPILER_NAME = "GLLVM_CXX_NAME"
|
||||
envLINKER_NAME = "GLLVM_LINK_NAME"
|
||||
envAR_NAME = "GLLVM_AR_NAME"
|
||||
envBC_STORE_PATH = "GLLVM_BC_STORE"
|
||||
envCONFIGUREONLY = "GLLVM_CONFIGURE_ONLY"
|
||||
envTOOLSPATH = "GLLVM_TOOLS_PATH"
|
||||
envCCOMPILERNAME = "GLLVM_CC_NAME"
|
||||
envCXXCOMPILERNAME = "GLLVM_CXX_NAME"
|
||||
envLINKERNAME = "GLLVM_LINK_NAME"
|
||||
envARNAME = "GLLVM_AR_NAME"
|
||||
envBCSTOREPATH = "GLLVM_BC_STORE"
|
||||
|
||||
// Gllvm functioning (once we have it working we can change the W to G; but for the time being leave it so that extract-bc works)
|
||||
elfSECTION_NAME = ".llvm_bc"
|
||||
darwinSEGMENT_NAME = "__WLLVM"
|
||||
darwinSECTION_NAME = "__llvm_bc"
|
||||
elfSECTIONNAME = ".llvm_bc"
|
||||
darwinSEGMENTNAME = "__WLLVM"
|
||||
darwinSECTIONNAME = "__llvm_bc"
|
||||
)
|
||||
|
||||
const (
|
||||
// File types
|
||||
ftUNDEFINED = iota
|
||||
ftELF_EXECUTABLE
|
||||
ftELF_OBJECT
|
||||
ftELF_SHARED
|
||||
ftMACH_EXECUTABLE
|
||||
ftMACH_OBJECT
|
||||
ftMACH_SHARED
|
||||
ftELFEXECUTABLE
|
||||
ftELFOBJECT
|
||||
ftELFSHARED
|
||||
ftMACHEXECUTABLE
|
||||
ftMACHOBJECT
|
||||
ftMACHSHARED
|
||||
ftARCHIVE
|
||||
)
|
||||
|
46
extractor.go
46
extractor.go
@ -32,12 +32,12 @@ func extract(args []string) {
|
||||
ea := parseExtractionArgs(args)
|
||||
|
||||
switch ea.InputType {
|
||||
case ftELF_EXECUTABLE,
|
||||
ftELF_SHARED,
|
||||
ftELF_OBJECT,
|
||||
ftMACH_EXECUTABLE,
|
||||
ftMACH_SHARED,
|
||||
ftMACH_OBJECT:
|
||||
case ftELFEXECUTABLE,
|
||||
ftELFSHARED,
|
||||
ftELFOBJECT,
|
||||
ftMACHEXECUTABLE,
|
||||
ftMACHSHARED,
|
||||
ftMACHOBJECT:
|
||||
handleExecutable(ea)
|
||||
case ftARCHIVE:
|
||||
handleArchive(ea)
|
||||
@ -55,15 +55,15 @@ func parseExtractionArgs(args []string) extractionArgs {
|
||||
}
|
||||
|
||||
// Checking environment variables
|
||||
if ln := os.Getenv(envLINKER_NAME); ln != "" {
|
||||
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||
if ln := os.Getenv(envLINKERNAME); ln != "" {
|
||||
if toolsPath := os.Getenv(envTOOLSPATH); toolsPath != "" {
|
||||
ea.LinkerName = toolsPath + ln
|
||||
} else {
|
||||
ea.LinkerName = ln
|
||||
}
|
||||
}
|
||||
if an := os.Getenv(envAR_NAME); an != "" {
|
||||
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||
if an := os.Getenv(envARNAME); an != "" {
|
||||
if toolsPath := os.Getenv(envTOOLSPATH); toolsPath != "" {
|
||||
ea.ArchiverName = toolsPath + an
|
||||
} else {
|
||||
ea.ArchiverName = an
|
||||
@ -117,14 +117,14 @@ func parseExtractionArgs(args []string) extractionArgs {
|
||||
} else {
|
||||
ea.ArArgs = append(ea.ArArgs, "x")
|
||||
}
|
||||
ea.ObjectTypeInArchive = ftELF_OBJECT
|
||||
ea.ObjectTypeInArchive = ftELFOBJECT
|
||||
case "darwin":
|
||||
ea.Extractor = extractSectionDarwin
|
||||
ea.ArArgs = append(ea.ArArgs, "-x")
|
||||
if ea.IsVerbose {
|
||||
ea.ArArgs = append(ea.ArArgs, "-v")
|
||||
}
|
||||
ea.ObjectTypeInArchive = ftMACH_OBJECT
|
||||
ea.ObjectTypeInArchive = ftMACHOBJECT
|
||||
default:
|
||||
log.Fatal("Unsupported platform: ", platform)
|
||||
}
|
||||
@ -254,10 +254,10 @@ func extractSectionDarwin(inputFile string) (contents []string) {
|
||||
if err != nil {
|
||||
log.Fatal("Mach-O file ", inputFile, " could not be read.")
|
||||
}
|
||||
section := machoFile.Section(darwinSECTION_NAME)
|
||||
section := machoFile.Section(darwinSECTIONNAME)
|
||||
sectionContents, errContents := section.Data()
|
||||
if errContents != nil {
|
||||
log.Fatal("Error reading the ", darwinSECTION_NAME, " section of Mach-O file ", inputFile, ".")
|
||||
log.Fatal("Error reading the ", darwinSECTIONNAME, " section of Mach-O file ", inputFile, ".")
|
||||
}
|
||||
contents = strings.Split(strings.TrimSuffix(string(sectionContents), "\n"), "\n")
|
||||
return
|
||||
@ -268,10 +268,10 @@ func extractSectionUnix(inputFile string) (contents []string) {
|
||||
if err != nil {
|
||||
log.Fatal("ELF file ", inputFile, " could not be read.")
|
||||
}
|
||||
section := elfFile.Section(elfSECTION_NAME)
|
||||
section := elfFile.Section(elfSECTIONNAME)
|
||||
sectionContents, errContents := section.Data()
|
||||
if errContents != nil {
|
||||
log.Fatal("Error reading the ", elfSECTION_NAME, " section of ELF file ", inputFile, ".")
|
||||
log.Fatal("Error reading the ", elfSECTIONNAME, " section of ELF file ", inputFile, ".")
|
||||
}
|
||||
contents = strings.Split(strings.TrimSuffix(string(sectionContents), "\n"), "\n")
|
||||
return
|
||||
@ -281,7 +281,7 @@ func extractSectionUnix(inputFile string) (contents []string) {
|
||||
func resolveBitcodePath(bcPath string) string {
|
||||
if _, err := os.Stat(bcPath); os.IsNotExist(err) {
|
||||
// If the bitcode file does not exist, try to find it in the store
|
||||
if bcStorePath := os.Getenv(envBC_STORE_PATH); bcStorePath != "" {
|
||||
if bcStorePath := os.Getenv(envBCSTOREPATH); bcStorePath != "" {
|
||||
// Compute absolute path hash
|
||||
absBcPath, _ := filepath.Abs(bcPath)
|
||||
storeBcPath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
||||
@ -305,19 +305,19 @@ func getFileType(realPath string) (fileType int) {
|
||||
|
||||
// Test the output
|
||||
if fo := string(out); strings.Contains(fo, "ELF") && strings.Contains(fo, "executable") {
|
||||
fileType = ftELF_EXECUTABLE
|
||||
fileType = ftELFEXECUTABLE
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "executable") {
|
||||
fileType = ftMACH_EXECUTABLE
|
||||
fileType = ftMACHEXECUTABLE
|
||||
} else if strings.Contains(fo, "ELF") && strings.Contains(fo, "shared") {
|
||||
fileType = ftELF_SHARED
|
||||
fileType = ftELFSHARED
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "dynamically linked shared") {
|
||||
fileType = ftMACH_SHARED
|
||||
fileType = ftMACHSHARED
|
||||
} else if strings.Contains(fo, "current ar archive") {
|
||||
fileType = ftARCHIVE
|
||||
} else if strings.Contains(fo, "ELF") && strings.Contains(fo, "relocatable") {
|
||||
fileType = ftELF_OBJECT
|
||||
fileType = ftELFOBJECT
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "object") {
|
||||
fileType = ftMACH_OBJECT
|
||||
fileType = ftMACHOBJECT
|
||||
} else {
|
||||
fileType = ftUNDEFINED
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user