Skip to content

Commit bce2126

Browse files
committed
Allow for customization under the hood.
1 parent 0be1e56 commit bce2126

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ uses `objdump` on `*nix`, and `otool` on OS X.
138138
Both tools then use `llvm-link` or `llvm-ar` to combine the bitcode
139139
files into the desired form.
140140

141+
## Customization under the hood.
142+
143+
You can specify the exact version of `objcopy` and `ld` that `gllvm` uses
144+
to manipulate tha artifacts by setting the `GLLVM_OBJCOPY` and `GLLVM_LD`
145+
environment variables.
141146

142147
## License
143148

shared/compiler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,18 @@ func attachBitcodePathToObject(bcFile, objFile string) {
172172
var attachCmd string
173173
var attachCmdArgs []string
174174
if runtime.GOOS == osDARWIN {
175-
attachCmd = "ld"
175+
if len(LLVMLd) > 0 {
176+
attachCmd = LLVMLd
177+
} else {
178+
attachCmd = "ld"
179+
}
176180
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", DarwinSegmentName, DarwinSectionName, tmpFile.Name(), "-o", objFile}
177181
} else {
178-
attachCmd = "objcopy"
182+
if len(LLVMObjcopy) > 0 {
183+
attachCmd = LLVMObjcopy
184+
} else {
185+
attachCmd = "objcopy"
186+
}
179187
attachCmdArgs = []string{"--add-section", ELFSectionName + "=" + tmpFile.Name(), objFile}
180188
}
181189

shared/environment.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ var LLVMLoggingLevel string
7676
//LLVMLoggingFile is the path to the optional logfile (useful when configuring)
7777
var LLVMLoggingFile string
7878

79+
//LLVMObjcopy is the path to the objcopy executable used to attach the bitcode on *nix.
80+
var LLVMObjcopy string
81+
82+
//LLVMLd is the path to the ld executable used to attach the bitcode on OSX.
83+
var LLVMLd string
84+
7985
const (
8086
envpath = "LLVM_COMPILER_PATH"
8187
envcc = "LLVM_CC_NAME"
@@ -86,6 +92,9 @@ const (
8692
envbc = "WLLVM_BC_STORE"
8793
envlvl = "WLLVM_OUTPUT_LEVEL"
8894
envfile = "WLLVM_OUTPUT_FILE"
95+
envld = "GLLVM_LD" //iam: we are deviating from wllvm here.
96+
envobjcopy = "GLLVM_OBJCOPY" //iam: we are deviating from wllvm here.
97+
//wllvm uses a BINUTILS_TARGET_PREFIX, which seems less general.
8998
)
9099

91100
func init() {
@@ -102,10 +111,12 @@ func init() {
102111
LLVMLoggingLevel = os.Getenv(envlvl)
103112
LLVMLoggingFile = os.Getenv(envfile)
104113

114+
LLVMObjcopy = os.Getenv(envobjcopy)
115+
LLVMLd = os.Getenv(envld)
105116
}
106117

107118
func printEnvironment() {
108-
vars := []string{envpath, envcc, envcxx, envar, envlnk, envcfg, envbc, envlvl, envfile}
119+
vars := []string{envpath, envcc, envcxx, envar, envlnk, envcfg, envbc, envlvl, envfile, envobjcopy, envld}
109120

110121
informUser("\nLiving in this environment:\n\n")
111122
for _, v := range vars {

0 commit comments

Comments
 (0)