Allow for customization under the hood.

This commit is contained in:
Ian A. Mason 2019-10-23 16:27:24 +00:00
parent 0be1e568c2
commit bce21265af
3 changed files with 27 additions and 3 deletions

View File

@ -138,6 +138,11 @@ uses `objdump` on `*nix`, and `otool` on OS X.
Both tools then use `llvm-link` or `llvm-ar` to combine the bitcode
files into the desired form.
## Customization under the hood.
You can specify the exact version of `objcopy` and `ld` that `gllvm` uses
to manipulate tha artifacts by setting the `GLLVM_OBJCOPY` and `GLLVM_LD`
environment variables.
## License

View File

@ -172,10 +172,18 @@ func attachBitcodePathToObject(bcFile, objFile string) {
var attachCmd string
var attachCmdArgs []string
if runtime.GOOS == osDARWIN {
attachCmd = "ld"
if len(LLVMLd) > 0 {
attachCmd = LLVMLd
} else {
attachCmd = "ld"
}
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", DarwinSegmentName, DarwinSectionName, tmpFile.Name(), "-o", objFile}
} else {
attachCmd = "objcopy"
if len(LLVMObjcopy) > 0 {
attachCmd = LLVMObjcopy
} else {
attachCmd = "objcopy"
}
attachCmdArgs = []string{"--add-section", ELFSectionName + "=" + tmpFile.Name(), objFile}
}

View File

@ -76,6 +76,12 @@ var LLVMLoggingLevel string
//LLVMLoggingFile is the path to the optional logfile (useful when configuring)
var LLVMLoggingFile string
//LLVMObjcopy is the path to the objcopy executable used to attach the bitcode on *nix.
var LLVMObjcopy string
//LLVMLd is the path to the ld executable used to attach the bitcode on OSX.
var LLVMLd string
const (
envpath = "LLVM_COMPILER_PATH"
envcc = "LLVM_CC_NAME"
@ -86,6 +92,9 @@ const (
envbc = "WLLVM_BC_STORE"
envlvl = "WLLVM_OUTPUT_LEVEL"
envfile = "WLLVM_OUTPUT_FILE"
envld = "GLLVM_LD" //iam: we are deviating from wllvm here.
envobjcopy = "GLLVM_OBJCOPY" //iam: we are deviating from wllvm here.
//wllvm uses a BINUTILS_TARGET_PREFIX, which seems less general.
)
func init() {
@ -102,10 +111,12 @@ func init() {
LLVMLoggingLevel = os.Getenv(envlvl)
LLVMLoggingFile = os.Getenv(envfile)
LLVMObjcopy = os.Getenv(envobjcopy)
LLVMLd = os.Getenv(envld)
}
func printEnvironment() {
vars := []string{envpath, envcc, envcxx, envar, envlnk, envcfg, envbc, envlvl, envfile}
vars := []string{envpath, envcc, envcxx, envar, envlnk, envcfg, envbc, envlvl, envfile, envobjcopy, envld}
informUser("\nLiving in this environment:\n\n")
for _, v := range vars {