Skip to content

Commit 2bdd2d5

Browse files
authored
Merge pull request travitch#59 from SRI-CSL/master
To everything (churn, churn, churn)
2 parents b5de01c + 25a6416 commit 2bdd2d5

File tree

7 files changed

+100
-18
lines changed

7 files changed

+100
-18
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ install:
1515
- sudo apt-get update
1616
# apache prerequisites
1717
- sudo apt-get install -y libapr1-dev libaprutil1-dev
18-
# for the clang build
18+
# for the clang build
1919
- sudo apt-get install -y llvm-3.5 clang-3.5
2020
# dragonegg prereqs. dragonegg and llvm-gcc use llvm 3.3
2121
- sudo apt-get install -y llvm-3.3 llvm-gcc-4.7
@@ -29,13 +29,14 @@ install:
2929

3030
# command to run tests
3131
script:
32-
# Run unittests
32+
# # Run unittests
3333
- python -m unittest discover test/ || exit 1
3434
- export WLLVM_HOME=`pwd`
35+
- ${WLLVM_HOME}/.travis/store.sh
3536
- export APACHE_VER=2.4.18
3637
# build apache with clang
3738
- ${WLLVM_HOME}/.travis/apache_clang.sh
3839
# build apache with gcc and dragonegg
3940
- ${WLLVM_HOME}/.travis/apache_dragonegg.sh
40-
41-
41+
# build musllvm with clang
42+
- ${WLLVM_HOME}/.travis/musllvm.sh

.travis/musllvm.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash -x
2+
# Make sure we exit if there is a failure
3+
set -e
4+
5+
6+
export PATH=/usr/lib/llvm-3.5/bin:${PATH}
7+
export LLVM_COMPILER=clang
8+
export WLLVM_OUTPUT=WARNING
9+
10+
wllvm-sanity-checker
11+
12+
#setup the store so we test that feature as well
13+
export WLLVM_BC_STORE=/tmp/bc
14+
mkdir -p /tmp/bc
15+
16+
git clone https://github.com/SRI-CSL/musllvm.git musllvm
17+
cd musllvm
18+
WLLVM_CONFIGURE_ONLY=1 CC=wllvm ./configure --target=LLVM --build=LLVM
19+
make
20+
extract-bc --bitcode ./lib/libc.a
21+
22+
if [ -s "./lib/libc.a.bc" ]
23+
then
24+
echo "libc.a.bc exists."
25+
else
26+
exit 1
27+
fi
28+
29+
#now lets makes sure the store has the bitcode too.
30+
mv ./lib/libc.a .
31+
make clean
32+
extract-bc --bitcode ./libc.a
33+
34+
if [ -s "./libc.a.bc" ]
35+
then
36+
echo "libc.a.bc exists."
37+
else
38+
exit 1
39+
fi

.travis/store.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash -x
2+
# Make sure we exit if there is a failure
3+
set -e
4+
5+
6+
export PATH=/usr/lib/llvm-3.5/bin:${PATH}
7+
export LLVM_COMPILER=clang
8+
export WLLVM_OUTPUT=WARNING
9+
10+
wllvm-sanity-checker
11+
12+
#setup the store so we test that feature as well
13+
export WLLVM_BC_STORE=/tmp/bc
14+
mkdir /tmp/bc
15+
16+
cd ./test/test_files
17+
make clean
18+
CC=wllvm make one
19+
mv main ../..
20+
make clean
21+
cd ../..
22+
extract-bc main
23+
24+
if [ -s "main.bc" ]
25+
then
26+
echo "main.bc exists."
27+
else
28+
exit 1
29+
fi

wllvm/arglistfilter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ def getOutputFilename(self):
399399
return '{0}.o'.format(root)
400400
return 'a.out'
401401

402+
def getBitcodeFileName(self):
403+
(dirs, baseFile) = os.path.split(self.getOutputFilename())
404+
bcfilename = os.path.join(dirs, '.{0}.bc'.format(baseFile))
405+
return bcfilename
406+
402407
# iam: returns a pair [objectFilename, bitcodeFilename] i.e .o and .bc.
403408
# the hidden flag determines whether the objectFile is hidden like the
404409
# bitcodeFile is (starts with a '.'), use the logging level & DUMPING flag to get a sense
@@ -411,10 +416,7 @@ def getArtifactNames(self, srcFile, hidden=False):
411416
else:
412417
objbase = '{0}.o'.format(srcroot)
413418
bcbase = '.{0}.o.bc'.format(srcroot)
414-
path = ''
415-
if self.outputFilename is not None:
416-
path = os.path.dirname(self.outputFilename)
417-
return [os.path.join(path, objbase), os.path.join(path, bcbase)]
419+
return [objbase, bcbase]
418420

419421
#iam: for printing our partitioning of the args
420422
def dump(self):

wllvm/compilers.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def outputFileCallback(self, flag, filename):
7373
self.outputFilename = filename
7474

7575

76+
def getHashedPathName(path):
77+
return hashlib.sha256(path.encode('utf-8')).hexdigest() if path else None
78+
7679

7780
def attachBitcodePathToObject(bcPath, outFileName):
7881
# Don't try to attach a bitcode path to a binary. Unfortunately
@@ -106,6 +109,13 @@ def attachBitcodePathToObject(bcPath, outFileName):
106109
objcopyCmd = ['objcopy', '--add-section', '{0}={1}'.format(elfSectionName, f.name), outFileName]
107110
orc = 0
108111

112+
# loicg: If the environment variable WLLVM_BC_STORE is set, copy the bitcode
113+
# file to that location, using a hash of the original bitcode path as a name
114+
storeEnv = os.getenv('WLLVM_BC_STORE')
115+
if storeEnv:
116+
hashName = getHashedPathName(absBcPath)
117+
copyfile(absBcPath, os.path.join(storeEnv, hashName))
118+
109119
try:
110120
if os.path.getsize(outFileName) > 0:
111121
objProc = Popen(objcopyCmd)
@@ -122,13 +132,6 @@ def attachBitcodePathToObject(bcPath, outFileName):
122132
_logger.error('objcopy failed with %s', orc)
123133
sys.exit(-1)
124134

125-
# loicg: If the environment variable WLLVM_BC_STORE is set, copy the bitcode
126-
# file to that location, using a hash of the original bitcode path as a name
127-
storeEnv = os.getenv('WLLVM_BC_STORE')
128-
if storeEnv:
129-
hashName = hashlib.sha256(absBcPath).hexdigest()
130-
copyfile(absBcPath, os.path.join(storeEnv, hashName))
131-
132135
class BuilderBase(object):
133136
def __init__(self, cmd, isCxx, prefixPath=None):
134137
self.cmd = cmd
@@ -246,6 +249,9 @@ def buildAndAttachBitcode(builder):
246249
# maybe python-magic is in our future ...
247250
srcFile = af.inputFiles[0]
248251
(objFile, bcFile) = af.getArtifactNames(srcFile, hidden)
252+
if af.outputFilename is not None:
253+
objFile = af.outputFilename
254+
bcFile = af.getBitcodeFileName()
249255
buildBitcodeFile(builder, srcFile, bcFile)
250256
attachBitcodePathToObject(bcFile, objFile)
251257

wllvm/extraction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .compilers import elfSectionName
1717
from .compilers import darwinSegmentName
1818
from .compilers import darwinSectionName
19+
from .compilers import getHashedPathName
1920

2021
from .filetype import FileType
2122

@@ -153,7 +154,7 @@ def extract_section_linux(inputFile):
153154
def getStorePath(bcPath):
154155
storeEnv = os.getenv('WLLVM_BC_STORE')
155156
if storeEnv:
156-
hashName = hashlib.sha256(bcPath).hexdigest()
157+
hashName = getHashedPathName(bcPath)
157158
hashPath = os.path.join(storeEnv, hashName)
158159
if os.path.isfile(hashPath):
159160
return hashPath
@@ -163,7 +164,7 @@ def getStorePath(bcPath):
163164
def getBitcodePath(bcPath):
164165
"""Tries to resolve the whereabouts of the bitcode.
165166
166-
First, ihecks if the given path points to an existing bitcode file.
167+
First, checks if the given path points to an existing bitcode file.
167168
If it does not, it tries to look for the bitcode file in the store directory given
168169
by the environment variable WLLVM_BC_STORE.
169170
"""
@@ -298,6 +299,7 @@ def handleArchive(pArgs):
298299

299300
for bcFile in contents:
300301
if bcFile != '':
302+
bcFile = getBitcodePath(bcFile)
301303
if not os.path.exists(bcFile):
302304
_logger.warning('%s lists bitcode library "%s" but it could not be found', f, bcFile)
303305
else:

wllvm/version.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
5151
1.1.0 - 4/21/2017 no new features on the horizon, no new bugs?
5252
53+
1.1.1 - 4/25/2017 bugs introduced by the new fetures have hopefully been eradicated.
54+
55+
1.1.2 - 4/26/2017 encoding issues with hashlib in the python 3 swarm.
5356
5457
"""
5558

56-
wllvm_version = '1.1.0'
59+
wllvm_version = '1.1.2'

0 commit comments

Comments
 (0)