|
func injectPath(extension, bcFile, objFile string) (success bool) { |
|
success = false |
|
// Store bitcode path to temp file |
|
var absBcPath, _ = filepath.Abs(bcFile) |
|
tmpContent := []byte(absBcPath + "\n") |
|
tmpFile, err := os.CreateTemp("", "gllvm") |
|
if err != nil { |
|
LogError("attachBitcodePathToObject: %v\n", err) |
|
return |
|
} |
|
defer CheckDefer(func() error { return os.Remove(tmpFile.Name()) }) |
|
if _, err := tmpFile.Write(tmpContent); err != nil { |
|
LogError("attachBitcodePathToObject: %v\n", err) |
|
return |
|
} |
|
if err := tmpFile.Close(); err != nil { |
|
LogError("attachBitcodePathToObject: %v\n", err) |
|
return |
|
} |
|
|
|
// Let's write the bitcode section |
|
var attachCmd string |
|
var attachCmdArgs []string |
|
if runtime.GOOS == osDARWIN { |
|
if len(LLVMLd) > 0 { |
|
attachCmd = LLVMLd |
|
} else { |
|
attachCmd = "ld" |
|
} |
|
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", DarwinSegmentName, DarwinSectionName, tmpFile.Name(), "-o", objFile} |
|
} else { |
|
if len(LLVMObjcopy) > 0 { |
|
attachCmd = LLVMObjcopy |
|
} else { |
|
attachCmd = "objcopy" |
|
} |
|
attachCmdArgs = []string{"--add-section", ELFSectionName + "=" + tmpFile.Name(), objFile} |
|
} |
|
|
|
// Run the attach command and ignore errors |
|
_, nerr := execCmd(attachCmd, attachCmdArgs, "") |
|
if nerr != nil { |
|
LogWarning("attachBitcodePathToObject: %v %v failed because %v\n", attachCmd, attachCmdArgs, nerr) |
|
return |
|
} |
|
|
|
// Copy bitcode file to store, if necessary |
|
if bcStorePath := LLVMBitcodeStorePath; bcStorePath != "" { |
|
destFilePath := path.Join(bcStorePath, getHashedPath(absBcPath)) |
|
in, _ := os.Open(absBcPath) |
|
defer CheckDefer(func() error { return in.Close() }) |
|
out, _ := os.Create(destFilePath) |
|
defer CheckDefer(func() error { return out.Close() }) |
|
_, err := io.Copy(out, in) |
|
if err != nil { |
|
LogWarning("Copying bc to bitcode archive %v failed because %v\n", destFilePath, err) |
|
return |
|
} |
|
err = out.Sync() |
|
if err != nil { |
|
LogWarning("Syncing bitcode archive %v failed because %v\n", destFilePath, err) |
|
return |
|
} |
|
|
|
} |
|
success = true |
|
return |
|
} |
Hi, I'm attempting to build ardupilot using gllvm, but it doesn't works well. Here are debug outputs first:
Here are some sample to raise this error
gllvm/shared/compiler.go
Lines 188 to 255 in 7bb6e19
In some quick debugging, I've found that
objFileargumentinjectPathcannot recognize correct path, so it raise error.Does the error appear only in this project? Is there a solution by specifying environmental variables?
Thank you!