mirror of
https://github.com/danog/gllvm.git
synced 2024-11-30 08:09:01 +01:00
golinting [ci skip]
This commit is contained in:
parent
834220ec27
commit
e930bbf2e2
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(env_CONFIGURE_ONLY) != "" {
|
||||
if os.Getenv(envCONFIGURE_ONLY) != "" {
|
||||
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", darwin_SEGMENT_NAME, darwin_SECTION_NAME, tmpFile.Name(), "-o", objFile}
|
||||
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", darwinSEGMENT_NAME, darwinSECTION_NAME, tmpFile.Name(), "-o", objFile}
|
||||
} else {
|
||||
attachCmd = "objcopy"
|
||||
attachCmdArgs = []string{"--add-section", elf_SECTION_NAME + "=" + tmpFile.Name(), objFile}
|
||||
attachCmdArgs = []string{"--add-section", elfSECTION_NAME + "=" + tmpFile.Name(), objFile}
|
||||
}
|
||||
|
||||
// Run the attach command and ignore errors
|
||||
execCmd(attachCmd, attachCmdArgs, "")
|
||||
|
||||
// Copy bitcode file to store, if necessary
|
||||
if bcStorePath := os.Getenv(env_BC_STORE_PATH); bcStorePath != "" {
|
||||
if bcStorePath := os.Getenv(envBC_STORE_PATH); 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(env_TOOLS_PATH)
|
||||
var compilerPath = os.Getenv(envTOOLS_PATH)
|
||||
switch compilerName {
|
||||
case "clang":
|
||||
var clangName = os.Getenv(env_C_COMPILER_NAME)
|
||||
var clangName = os.Getenv(envC_COMPILER_NAME)
|
||||
if clangName != "" {
|
||||
return compilerPath + clangName
|
||||
}
|
||||
return compilerPath + compilerName
|
||||
case "clang++":
|
||||
var clangppName = os.Getenv(env_C_COMPILER_NAME)
|
||||
var clangppName = os.Getenv(envC_COMPILER_NAME)
|
||||
if clangppName != "" {
|
||||
return compilerPath + clangppName
|
||||
}
|
||||
|
36
constants.go
36
constants.go
@ -2,28 +2,28 @@ package main
|
||||
|
||||
const (
|
||||
// Environment variables
|
||||
env_CONFIGURE_ONLY = "GLLVM_CONFIGURE_ONLY"
|
||||
env_TOOLS_PATH = "GLLVM_TOOLS_PATH"
|
||||
env_C_COMPILER_NAME = "GLLVM_CC_NAME"
|
||||
env_CXX_COMPILER_NAME = "GLLVM_CXX_NAME"
|
||||
env_LINKER_NAME = "GLLVM_LINK_NAME"
|
||||
env_AR_NAME = "GLLVM_AR_NAME"
|
||||
env_BC_STORE_PATH = "GLLVM_BC_STORE"
|
||||
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"
|
||||
|
||||
// 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)
|
||||
elf_SECTION_NAME = ".llvm_bc"
|
||||
darwin_SEGMENT_NAME = "__WLLVM"
|
||||
darwin_SECTION_NAME = "__llvm_bc"
|
||||
elfSECTION_NAME = ".llvm_bc"
|
||||
darwinSEGMENT_NAME = "__WLLVM"
|
||||
darwinSECTION_NAME = "__llvm_bc"
|
||||
)
|
||||
|
||||
const (
|
||||
// File types
|
||||
ft_UNDEFINED = iota
|
||||
ft_ELF_EXECUTABLE
|
||||
ft_ELF_OBJECT
|
||||
ft_ELF_SHARED
|
||||
ft_MACH_EXECUTABLE
|
||||
ft_MACH_OBJECT
|
||||
ft_MACH_SHARED
|
||||
ft_ARCHIVE
|
||||
ftUNDEFINED = iota
|
||||
ftELF_EXECUTABLE
|
||||
ftELF_OBJECT
|
||||
ftELF_SHARED
|
||||
ftMACH_EXECUTABLE
|
||||
ftMACH_OBJECT
|
||||
ftMACH_SHARED
|
||||
ftARCHIVE
|
||||
)
|
||||
|
54
extractor.go
54
extractor.go
@ -32,14 +32,14 @@ func extract(args []string) {
|
||||
ea := parseExtractionArgs(args)
|
||||
|
||||
switch ea.InputType {
|
||||
case ft_ELF_EXECUTABLE,
|
||||
ft_ELF_SHARED,
|
||||
ft_ELF_OBJECT,
|
||||
ft_MACH_EXECUTABLE,
|
||||
ft_MACH_SHARED,
|
||||
ft_MACH_OBJECT:
|
||||
case ftELF_EXECUTABLE,
|
||||
ftELF_SHARED,
|
||||
ftELF_OBJECT,
|
||||
ftMACH_EXECUTABLE,
|
||||
ftMACH_SHARED,
|
||||
ftMACH_OBJECT:
|
||||
handleExecutable(ea)
|
||||
case ft_ARCHIVE:
|
||||
case ftARCHIVE:
|
||||
handleArchive(ea)
|
||||
default:
|
||||
log.Fatal("Incorrect input file type.")
|
||||
@ -55,15 +55,15 @@ func parseExtractionArgs(args []string) extractionArgs {
|
||||
}
|
||||
|
||||
// Checking environment variables
|
||||
if ln := os.Getenv(env_LINKER_NAME); ln != "" {
|
||||
if toolsPath := os.Getenv(env_TOOLS_PATH); toolsPath != "" {
|
||||
if ln := os.Getenv(envLINKER_NAME); ln != "" {
|
||||
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||
ea.LinkerName = toolsPath + ln
|
||||
} else {
|
||||
ea.LinkerName = ln
|
||||
}
|
||||
}
|
||||
if an := os.Getenv(env_AR_NAME); an != "" {
|
||||
if toolsPath := os.Getenv(env_TOOLS_PATH); toolsPath != "" {
|
||||
if an := os.Getenv(envAR_NAME); an != "" {
|
||||
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||
ea.ArchiverName = toolsPath + an
|
||||
} else {
|
||||
ea.ArchiverName = an
|
||||
@ -117,21 +117,21 @@ func parseExtractionArgs(args []string) extractionArgs {
|
||||
} else {
|
||||
ea.ArArgs = append(ea.ArArgs, "x")
|
||||
}
|
||||
ea.ObjectTypeInArchive = ft_ELF_OBJECT
|
||||
ea.ObjectTypeInArchive = ftELF_OBJECT
|
||||
case "darwin":
|
||||
ea.Extractor = extractSectionDarwin
|
||||
ea.ArArgs = append(ea.ArArgs, "-x")
|
||||
if ea.IsVerbose {
|
||||
ea.ArArgs = append(ea.ArArgs, "-v")
|
||||
}
|
||||
ea.ObjectTypeInArchive = ft_MACH_OBJECT
|
||||
ea.ObjectTypeInArchive = ftMACH_OBJECT
|
||||
default:
|
||||
log.Fatal("Unsupported platform: ", platform)
|
||||
}
|
||||
|
||||
// Create output filename if not given
|
||||
if ea.OutputFile == "" {
|
||||
if ea.InputType == ft_ARCHIVE {
|
||||
if ea.InputType == ftARCHIVE {
|
||||
var ext string
|
||||
if ea.IsBuildBitcodeArchive {
|
||||
ext = ".a.bc"
|
||||
@ -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(darwin_SECTION_NAME)
|
||||
section := machoFile.Section(darwinSECTION_NAME)
|
||||
sectionContents, errContents := section.Data()
|
||||
if errContents != nil {
|
||||
log.Fatal("Error reading the ", darwin_SECTION_NAME, " section of Mach-O file ", inputFile, ".")
|
||||
log.Fatal("Error reading the ", darwinSECTION_NAME, " 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(elf_SECTION_NAME)
|
||||
section := elfFile.Section(elfSECTION_NAME)
|
||||
sectionContents, errContents := section.Data()
|
||||
if errContents != nil {
|
||||
log.Fatal("Error reading the ", elf_SECTION_NAME, " section of ELF file ", inputFile, ".")
|
||||
log.Fatal("Error reading the ", elfSECTION_NAME, " 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(env_BC_STORE_PATH); bcStorePath != "" {
|
||||
if bcStorePath := os.Getenv(envBC_STORE_PATH); bcStorePath != "" {
|
||||
// Compute absolute path hash
|
||||
absBcPath, _ := filepath.Abs(bcPath)
|
||||
storeBcPath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
||||
@ -305,21 +305,21 @@ func getFileType(realPath string) (fileType int) {
|
||||
|
||||
// Test the output
|
||||
if fo := string(out); strings.Contains(fo, "ELF") && strings.Contains(fo, "executable") {
|
||||
fileType = ft_ELF_EXECUTABLE
|
||||
fileType = ftELF_EXECUTABLE
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "executable") {
|
||||
fileType = ft_MACH_EXECUTABLE
|
||||
fileType = ftMACH_EXECUTABLE
|
||||
} else if strings.Contains(fo, "ELF") && strings.Contains(fo, "shared") {
|
||||
fileType = ft_ELF_SHARED
|
||||
fileType = ftELF_SHARED
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "dynamically linked shared") {
|
||||
fileType = ft_MACH_SHARED
|
||||
fileType = ftMACH_SHARED
|
||||
} else if strings.Contains(fo, "current ar archive") {
|
||||
fileType = ft_ARCHIVE
|
||||
fileType = ftARCHIVE
|
||||
} else if strings.Contains(fo, "ELF") && strings.Contains(fo, "relocatable") {
|
||||
fileType = ft_ELF_OBJECT
|
||||
fileType = ftELF_OBJECT
|
||||
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "object") {
|
||||
fileType = ft_MACH_OBJECT
|
||||
fileType = ftMACH_OBJECT
|
||||
} else {
|
||||
fileType = ft_UNDEFINED
|
||||
fileType = ftUNDEFINED
|
||||
}
|
||||
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user