aboutsummaryrefslogtreecommitdiff
path: root/tools/shared.py
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2012-02-07 17:05:22 -0500
committerEhsan Akhgari <ehsan.akhgari@gmail.com>2012-02-08 18:45:37 -0500
commitf0fe97c44891b20962d4c3f7122d205cdfc479aa (patch)
tree6b3c65085271ae698af196f941978c16897de079 /tools/shared.py
parentb782221bf8a5d1271c3277e27360adc1d5e7bb75 (diff)
Use llvm-ar instead of llvm-link in emar
This makes the semantics of emar to be the same as the semantics of system ar.
Diffstat (limited to 'tools/shared.py')
-rw-r--r--tools/shared.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/shared.py b/tools/shared.py
index 45400581..615f86e8 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -90,6 +90,7 @@ CLANG_CPP=os.path.expanduser(os.path.join(LLVM_ROOT, 'clang++'))
CLANG=CLANG_CPP
LLVM_LINK=os.path.join(LLVM_ROOT, 'llvm-link')
LLVM_LD=os.path.join(LLVM_ROOT, 'llvm-ld')
+LLVM_AR=os.path.join(LLVM_ROOT, 'llvm-ar')
LLVM_OPT=os.path.expanduser(os.path.join(LLVM_ROOT, 'opt'))
LLVM_AS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-as'))
LLVM_DIS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-dis'))
@@ -726,6 +727,17 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)'''.replace('$EMSCRIPTEN_ROOT', path_
return filename + '.cc.js'
@staticmethod
+ def is_ar(filename):
+ try:
+ b = open(filename, 'r').read(8)
+ return b[0] == '!' and b[1] == '<' and \
+ b[2] == 'a' and b[3] == 'r' and \
+ b[4] == 'c' and b[5] == 'h' and \
+ b[6] == '>' and ord(b[7]) == 10
+ except:
+ return False
+
+ @staticmethod
def is_bitcode(filename):
# checks if a file contains LLVM bitcode
# if the file doesn't exist or doesn't have valid symbols, it isn't bitcode
@@ -733,9 +745,13 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)'''.replace('$EMSCRIPTEN_ROOT', path_
defs = Building.llvm_nm(filename, stderr=PIPE)
# If no symbols found, it might just be an empty bitcode file, try to dis it
if len(defs.defs) + len(defs.undefs) + len(defs.commons) == 0:
- test_ll = os.path.join(EMSCRIPTEN_TEMP_DIR, 'test.ll')
- Building.llvm_dis(filename, test_ll)
- assert os.path.exists(test_ll)
+ # llvm-nm 3.0 has a bug when reading symbols from ar files
+ # so try to see if we're dealing with an ar file, in which
+ # case we should try to dis it.
+ if not Building.is_ar(filename):
+ test_ll = os.path.join(EMSCRIPTEN_TEMP_DIR, 'test.ll')
+ Building.llvm_dis(filename, test_ll)
+ assert os.path.exists(test_ll)
except:
return False
@@ -743,6 +759,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)'''.replace('$EMSCRIPTEN_ROOT', path_
b = open(filename, 'r').read(4)
if b[0] == 'B' and b[1] == 'C':
return True
+ # look for ar signature
+ elif Building.is_ar(filename):
+ return True
# on OS X, there is a 20-byte prefix
elif ord(b[0]) == 222 and ord(b[1]) == 192 and ord(b[2]) == 23 and ord(b[3]) == 11:
b = open(filename, 'r').read(24)