aboutsummaryrefslogtreecommitdiff
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
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.
-rwxr-xr-xemar4
-rwxr-xr-xemcc7
-rw-r--r--tools/shared.py25
3 files changed, 29 insertions, 7 deletions
diff --git a/emar b/emar
index 49d995bd..e64cd8b9 100755
--- a/emar
+++ b/emar
@@ -12,11 +12,11 @@ from tools import shared
DEBUG = os.environ.get('EMCC_DEBUG')
-newargs = [shared.LLVM_LINK] + sys.argv[3:] + ['-o='+sys.argv[2]]
+newargs = [shared.LLVM_AR] + sys.argv[1:]
if DEBUG:
print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs
if len(newargs) > 2:
- os.execvp(shared.LLVM_LINK, newargs)
+ os.execvp(shared.LLVM_AR, newargs)
diff --git a/emcc b/emcc
index b8e2489c..fa18968a 100755
--- a/emcc
+++ b/emcc
@@ -239,7 +239,7 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ')
# ---------------- Utilities ---------------
SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc')
-BITCODE_SUFFIXES = ('.bc', '.o', '.a', '.dylib', '.so', '.dll')
+BITCODE_SUFFIXES = ('.bc', '.o', '.dylib', '.so', '.dll')
ASSEMBLY_SUFFIXES = ('.ll',)
def unsuffixed(name):
@@ -377,7 +377,7 @@ try:
for i in range(len(newargs)): # find input files XXX this a simple heuristic. we should really analyze based on a full understanding of gcc params,
# right now we just assume that what is left contains no more |-x OPT| things
arg = newargs[i]
- if arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + ASSEMBLY_SUFFIXES): # we already removed -o <target>, so all these should be inputs
+ if arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs
newargs[i] = ''
if os.path.exists(arg):
if arg.endswith(SOURCE_SUFFIXES):
@@ -440,6 +440,9 @@ try:
if input_file.endswith(BITCODE_SUFFIXES):
if DEBUG: print >> sys.stderr, 'emcc: copying bitcode file: ', input_file
shutil.copyfile(input_file, in_temp(unsuffixed_basename(input_file) + '.o'))
+ elif shared.Building.is_ar(input_file):
+ if DEBUG: print >> sys.stderr, 'emcc: copying ar file: ', input_file
+ shutil.copyfile(input_file, in_temp(os.path.basename(input_file)))
else: #.ll
if not LEAVE_INPUTS_RAW:
# Note that by assembling the .ll file, then disassembling it later, we will
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)