From bce21265af1403d78adbb53cf16bfc7378b4afb0 Mon Sep 17 00:00:00 2001 From: "Ian A. Mason" Date: Wed, 23 Oct 2019 16:27:24 +0000 Subject: [PATCH] Allow for customization under the hood. --- README.md | 5 +++++ shared/compiler.go | 12 ++++++++++-- shared/environment.go | 13 ++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 115fc15..f16dc3e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/shared/compiler.go b/shared/compiler.go index 732abfa..183b182 100644 --- a/shared/compiler.go +++ b/shared/compiler.go @@ -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} } diff --git a/shared/environment.go b/shared/environment.go index cabbe72..62171f1 100644 --- a/shared/environment.go +++ b/shared/environment.go @@ -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 {