mirror of
https://github.com/danog/gllvm.git
synced 2024-12-02 21:07:50 +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) {
|
func compile(args []string, compilerName string) {
|
||||||
var compilerExecName = getCompilerExecName(compilerName)
|
var compilerExecName = getCompilerExecName(compilerName)
|
||||||
var configureOnly bool
|
var configureOnly bool
|
||||||
if os.Getenv(env_CONFIGURE_ONLY) != "" {
|
if os.Getenv(envCONFIGURE_ONLY) != "" {
|
||||||
configureOnly = true
|
configureOnly = true
|
||||||
}
|
}
|
||||||
var pr = parse(args)
|
var pr = parse(args)
|
||||||
@ -113,17 +113,17 @@ func attachBitcodePathToObject(bcFile, objFile string) {
|
|||||||
var attachCmdArgs []string
|
var attachCmdArgs []string
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
attachCmd = "ld"
|
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 {
|
} else {
|
||||||
attachCmd = "objcopy"
|
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
|
// Run the attach command and ignore errors
|
||||||
execCmd(attachCmd, attachCmdArgs, "")
|
execCmd(attachCmd, attachCmdArgs, "")
|
||||||
|
|
||||||
// Copy bitcode file to store, if necessary
|
// 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))
|
destFilePath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
||||||
in, _ := os.Open(absBcPath)
|
in, _ := os.Open(absBcPath)
|
||||||
defer in.Close()
|
defer in.Close()
|
||||||
@ -175,16 +175,16 @@ func execCompile(compilerExecName string, pr parserResult, wg *sync.WaitGroup) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCompilerExecName(compilerName string) string {
|
func getCompilerExecName(compilerName string) string {
|
||||||
var compilerPath = os.Getenv(env_TOOLS_PATH)
|
var compilerPath = os.Getenv(envTOOLS_PATH)
|
||||||
switch compilerName {
|
switch compilerName {
|
||||||
case "clang":
|
case "clang":
|
||||||
var clangName = os.Getenv(env_C_COMPILER_NAME)
|
var clangName = os.Getenv(envC_COMPILER_NAME)
|
||||||
if clangName != "" {
|
if clangName != "" {
|
||||||
return compilerPath + clangName
|
return compilerPath + clangName
|
||||||
}
|
}
|
||||||
return compilerPath + compilerName
|
return compilerPath + compilerName
|
||||||
case "clang++":
|
case "clang++":
|
||||||
var clangppName = os.Getenv(env_C_COMPILER_NAME)
|
var clangppName = os.Getenv(envC_COMPILER_NAME)
|
||||||
if clangppName != "" {
|
if clangppName != "" {
|
||||||
return compilerPath + clangppName
|
return compilerPath + clangppName
|
||||||
}
|
}
|
||||||
|
36
constants.go
36
constants.go
@ -2,28 +2,28 @@ package main
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Environment variables
|
// Environment variables
|
||||||
env_CONFIGURE_ONLY = "GLLVM_CONFIGURE_ONLY"
|
envCONFIGURE_ONLY = "GLLVM_CONFIGURE_ONLY"
|
||||||
env_TOOLS_PATH = "GLLVM_TOOLS_PATH"
|
envTOOLS_PATH = "GLLVM_TOOLS_PATH"
|
||||||
env_C_COMPILER_NAME = "GLLVM_CC_NAME"
|
envC_COMPILER_NAME = "GLLVM_CC_NAME"
|
||||||
env_CXX_COMPILER_NAME = "GLLVM_CXX_NAME"
|
envCXX_COMPILER_NAME = "GLLVM_CXX_NAME"
|
||||||
env_LINKER_NAME = "GLLVM_LINK_NAME"
|
envLINKER_NAME = "GLLVM_LINK_NAME"
|
||||||
env_AR_NAME = "GLLVM_AR_NAME"
|
envAR_NAME = "GLLVM_AR_NAME"
|
||||||
env_BC_STORE_PATH = "GLLVM_BC_STORE"
|
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)
|
// 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"
|
elfSECTION_NAME = ".llvm_bc"
|
||||||
darwin_SEGMENT_NAME = "__WLLVM"
|
darwinSEGMENT_NAME = "__WLLVM"
|
||||||
darwin_SECTION_NAME = "__llvm_bc"
|
darwinSECTION_NAME = "__llvm_bc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// File types
|
// File types
|
||||||
ft_UNDEFINED = iota
|
ftUNDEFINED = iota
|
||||||
ft_ELF_EXECUTABLE
|
ftELF_EXECUTABLE
|
||||||
ft_ELF_OBJECT
|
ftELF_OBJECT
|
||||||
ft_ELF_SHARED
|
ftELF_SHARED
|
||||||
ft_MACH_EXECUTABLE
|
ftMACH_EXECUTABLE
|
||||||
ft_MACH_OBJECT
|
ftMACH_OBJECT
|
||||||
ft_MACH_SHARED
|
ftMACH_SHARED
|
||||||
ft_ARCHIVE
|
ftARCHIVE
|
||||||
)
|
)
|
||||||
|
54
extractor.go
54
extractor.go
@ -32,14 +32,14 @@ func extract(args []string) {
|
|||||||
ea := parseExtractionArgs(args)
|
ea := parseExtractionArgs(args)
|
||||||
|
|
||||||
switch ea.InputType {
|
switch ea.InputType {
|
||||||
case ft_ELF_EXECUTABLE,
|
case ftELF_EXECUTABLE,
|
||||||
ft_ELF_SHARED,
|
ftELF_SHARED,
|
||||||
ft_ELF_OBJECT,
|
ftELF_OBJECT,
|
||||||
ft_MACH_EXECUTABLE,
|
ftMACH_EXECUTABLE,
|
||||||
ft_MACH_SHARED,
|
ftMACH_SHARED,
|
||||||
ft_MACH_OBJECT:
|
ftMACH_OBJECT:
|
||||||
handleExecutable(ea)
|
handleExecutable(ea)
|
||||||
case ft_ARCHIVE:
|
case ftARCHIVE:
|
||||||
handleArchive(ea)
|
handleArchive(ea)
|
||||||
default:
|
default:
|
||||||
log.Fatal("Incorrect input file type.")
|
log.Fatal("Incorrect input file type.")
|
||||||
@ -55,15 +55,15 @@ func parseExtractionArgs(args []string) extractionArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checking environment variables
|
// Checking environment variables
|
||||||
if ln := os.Getenv(env_LINKER_NAME); ln != "" {
|
if ln := os.Getenv(envLINKER_NAME); ln != "" {
|
||||||
if toolsPath := os.Getenv(env_TOOLS_PATH); toolsPath != "" {
|
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||||
ea.LinkerName = toolsPath + ln
|
ea.LinkerName = toolsPath + ln
|
||||||
} else {
|
} else {
|
||||||
ea.LinkerName = ln
|
ea.LinkerName = ln
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if an := os.Getenv(env_AR_NAME); an != "" {
|
if an := os.Getenv(envAR_NAME); an != "" {
|
||||||
if toolsPath := os.Getenv(env_TOOLS_PATH); toolsPath != "" {
|
if toolsPath := os.Getenv(envTOOLS_PATH); toolsPath != "" {
|
||||||
ea.ArchiverName = toolsPath + an
|
ea.ArchiverName = toolsPath + an
|
||||||
} else {
|
} else {
|
||||||
ea.ArchiverName = an
|
ea.ArchiverName = an
|
||||||
@ -117,21 +117,21 @@ func parseExtractionArgs(args []string) extractionArgs {
|
|||||||
} else {
|
} else {
|
||||||
ea.ArArgs = append(ea.ArArgs, "x")
|
ea.ArArgs = append(ea.ArArgs, "x")
|
||||||
}
|
}
|
||||||
ea.ObjectTypeInArchive = ft_ELF_OBJECT
|
ea.ObjectTypeInArchive = ftELF_OBJECT
|
||||||
case "darwin":
|
case "darwin":
|
||||||
ea.Extractor = extractSectionDarwin
|
ea.Extractor = extractSectionDarwin
|
||||||
ea.ArArgs = append(ea.ArArgs, "-x")
|
ea.ArArgs = append(ea.ArArgs, "-x")
|
||||||
if ea.IsVerbose {
|
if ea.IsVerbose {
|
||||||
ea.ArArgs = append(ea.ArArgs, "-v")
|
ea.ArArgs = append(ea.ArArgs, "-v")
|
||||||
}
|
}
|
||||||
ea.ObjectTypeInArchive = ft_MACH_OBJECT
|
ea.ObjectTypeInArchive = ftMACH_OBJECT
|
||||||
default:
|
default:
|
||||||
log.Fatal("Unsupported platform: ", platform)
|
log.Fatal("Unsupported platform: ", platform)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create output filename if not given
|
// Create output filename if not given
|
||||||
if ea.OutputFile == "" {
|
if ea.OutputFile == "" {
|
||||||
if ea.InputType == ft_ARCHIVE {
|
if ea.InputType == ftARCHIVE {
|
||||||
var ext string
|
var ext string
|
||||||
if ea.IsBuildBitcodeArchive {
|
if ea.IsBuildBitcodeArchive {
|
||||||
ext = ".a.bc"
|
ext = ".a.bc"
|
||||||
@ -254,10 +254,10 @@ func extractSectionDarwin(inputFile string) (contents []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Mach-O file ", inputFile, " could not be read.")
|
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()
|
sectionContents, errContents := section.Data()
|
||||||
if errContents != nil {
|
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")
|
contents = strings.Split(strings.TrimSuffix(string(sectionContents), "\n"), "\n")
|
||||||
return
|
return
|
||||||
@ -268,10 +268,10 @@ func extractSectionUnix(inputFile string) (contents []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("ELF file ", inputFile, " could not be read.")
|
log.Fatal("ELF file ", inputFile, " could not be read.")
|
||||||
}
|
}
|
||||||
section := elfFile.Section(elf_SECTION_NAME)
|
section := elfFile.Section(elfSECTION_NAME)
|
||||||
sectionContents, errContents := section.Data()
|
sectionContents, errContents := section.Data()
|
||||||
if errContents != nil {
|
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")
|
contents = strings.Split(strings.TrimSuffix(string(sectionContents), "\n"), "\n")
|
||||||
return
|
return
|
||||||
@ -281,7 +281,7 @@ func extractSectionUnix(inputFile string) (contents []string) {
|
|||||||
func resolveBitcodePath(bcPath string) string {
|
func resolveBitcodePath(bcPath string) string {
|
||||||
if _, err := os.Stat(bcPath); os.IsNotExist(err) {
|
if _, err := os.Stat(bcPath); os.IsNotExist(err) {
|
||||||
// If the bitcode file does not exist, try to find it in the store
|
// 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
|
// Compute absolute path hash
|
||||||
absBcPath, _ := filepath.Abs(bcPath)
|
absBcPath, _ := filepath.Abs(bcPath)
|
||||||
storeBcPath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
storeBcPath := path.Join(bcStorePath, getHashedPath(absBcPath))
|
||||||
@ -305,21 +305,21 @@ func getFileType(realPath string) (fileType int) {
|
|||||||
|
|
||||||
// Test the output
|
// Test the output
|
||||||
if fo := string(out); strings.Contains(fo, "ELF") && strings.Contains(fo, "executable") {
|
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") {
|
} 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") {
|
} 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") {
|
} 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") {
|
} else if strings.Contains(fo, "current ar archive") {
|
||||||
fileType = ft_ARCHIVE
|
fileType = ftARCHIVE
|
||||||
} else if strings.Contains(fo, "ELF") && strings.Contains(fo, "relocatable") {
|
} 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") {
|
} else if strings.Contains(fo, "Mach-O") && strings.Contains(fo, "object") {
|
||||||
fileType = ft_MACH_OBJECT
|
fileType = ftMACH_OBJECT
|
||||||
} else {
|
} else {
|
||||||
fileType = ft_UNDEFINED
|
fileType = ftUNDEFINED
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user