Skip to content

Commit 11466e4

Browse files
committed
Pulling in the upstream changes.
Merge branch 'master' of https://github.com/travitch/whole-program-llvm
2 parents f2ade2d + 37ec6ab commit 11466e4

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ original bitcode file. For convenience, when using both the manifest
237237
feature of `extract-bc` and the store, the manifest will contain both
238238
the original path, and the store path.
239239

240+
Cross-Compilation
241+
-----------------
242+
243+
To support cross-compilation WLLVM supports the `-target` triple used by clang.
244+
More information can be found
245+
[here.](https://clang.llvm.org/docs/CrossCompilation.html#target-triple).
246+
247+
Additionall, WLLVM leverages `objcopy` for some of its heavy lifting. When
248+
cross-compiling you must ensure to use the appropriate `objcopy` for the target
249+
architecture. The `BINUTILS_TARGET_PREFIX` environment variable can be used to
250+
set the objcopy of choice, for example, `arm-linux-gnueabihf`.
240251

241252
Debugging
242253
---------

wllvm/arglistfilter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
129129
'-iquote' : (1, ArgumentListFilter.compileBinaryCallback),
130130
'-imultilib' : (1, ArgumentListFilter.compileBinaryCallback),
131131

132+
# Architecture
133+
'-target' : (1, ArgumentListFilter.compileBinaryCallback),
134+
'-marm' : (0, ArgumentListFilter.compileUnaryCallback),
135+
132136
# Language
133137
'-ansi' : (0, ArgumentListFilter.compileUnaryCallback),
134138
'-pedantic' : (0, ArgumentListFilter.compileUnaryCallback),
@@ -272,6 +276,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
272276
r'-mmacosx-version-min=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
273277

274278
r'^--sysroot=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
279+
r'^--gcc-toolchain=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
275280
r'^-print-prog-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
276281
r'^-print-file-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
277282
#iam: -xc from yices. why BD?

wllvm/compilers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def wcompile(mode):
7171
# Environmental variable for path to compiler tools (clang/llvm-link etc..)
7272
llvmCompilerPathEnv = 'LLVM_COMPILER_PATH'
7373

74+
# Environmental variable for cross-compilation target.
75+
binutilsTargetPrefixEnv = 'BINUTILS_TARGET_PREFIX'
76+
7477
# This is the ELF section name inserted into binaries
7578
elfSectionName = '.llvm_bc'
7679

@@ -131,12 +134,15 @@ def attachBitcodePathToObject(bcPath, outFileName):
131134
os.fsync(f.fileno())
132135
f.close()
133136

137+
binUtilsTargetPrefix = os.getenv(binutilsTargetPrefixEnv)
134138

135139
# Now write our bitcode section
136140
if sys.platform.startswith('darwin'):
137-
objcopyCmd = ['ld', '-r', '-keep_private_externs', outFileName, '-sectcreate', darwinSegmentName, darwinSectionName, f.name, '-o', outFileName]
141+
objcopyBin = '{}-{}'.format(binUtilsTargetPrefix, 'ld') if binUtilsTargetPrefix else 'ld'
142+
objcopyCmd = [objcopyBin, '-r', '-keep_private_externs', outFileName, '-sectcreate', darwinSegmentName, darwinSectionName, f.name, '-o', outFileName]
138143
else:
139-
objcopyCmd = ['objcopy', '--add-section', '{0}={1}'.format(elfSectionName, f.name), outFileName]
144+
objcopyBin = '{}-{}'.format(binUtilsTargetPrefix, 'objcopy') if binUtilsTargetPrefix else 'objcopy'
145+
objcopyCmd = [objcopyBin, '--add-section', '{0}={1}'.format(elfSectionName, f.name), outFileName]
140146
orc = 0
141147

142148
# loicg: If the environment variable WLLVM_BC_STORE is set, copy the bitcode
@@ -249,6 +255,7 @@ def getBuilder(cmd, mode):
249255
compilerEnv = 'LLVM_COMPILER'
250256
cstring = os.getenv(compilerEnv)
251257
pathPrefix = os.getenv(llvmCompilerPathEnv) # Optional
258+
252259
_logger.debug('WLLVM compiler using %s', cstring)
253260
if pathPrefix:
254261
_logger.debug('WLLVM compiler path prefix "%s"', pathPrefix)

wllvm/extraction.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ def extraction():
5151
bitCodeArchiveExtension = 'bca'
5252
moduleExtension = 'bc'
5353

54+
# Environmental variable for cross-compilation target.
55+
binutilsTargetPrefixEnv = 'BINUTILS_TARGET_PREFIX'
56+
5457
def getSectionSizeAndOffset(sectionName, filename):
5558
"""Returns the size and offset of the section, both in bytes.
5659
5760
Use objdump on the provided binary; parse out the fields
5861
to find the given section. Parses the output,and
5962
extracts thesize and offset of that section (in bytes).
6063
"""
61-
objdumpCmd = ['objdump', '-h', '-w', filename]
64+
65+
binUtilsTargetPrefix = os.getenv(binutilsTargetPrefixEnv)
66+
objdumpBin = '{}-{}'.format(binUtilsTargetPrefix, 'objdump') if binUtilsTargetPrefix else 'objdump'
67+
objdumpCmd = [objdumpBin, '-h', '-w', filename]
6268
objdumpProc = Popen(objdumpCmd, stdout=sp.PIPE)
6369

6470
objdumpOutput = objdumpProc.communicate()[0]

0 commit comments

Comments
 (0)