[libcxx] r232858 - Improve automatic detection of filetype for sym_check
Eric Fiselier
eric at efcs.ca
Fri Mar 20 16:07:38 PDT 2015
Author: ericwf
Date: Fri Mar 20 18:07:38 2015
New Revision: 232858
URL: http://llvm.org/viewvc/llvm-project?rev=232858&view=rev
Log:
Improve automatic detection of filetype for sym_check
Modified:
libcxx/trunk/utils/sym_check/sym_check/util.py
Modified: libcxx/trunk/utils/sym_check/sym_check/util.py
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/sym_check/sym_check/util.py?rev=232858&r1=232857&r2=232858&view=diff
==============================================================================
--- libcxx/trunk/utils/sym_check/sym_check/util.py (original)
+++ libcxx/trunk/utils/sym_check/sym_check/util.py Fri Mar 20 18:07:38 2015
@@ -95,8 +95,34 @@ def demangle_symbol(symbol):
return out
+def is_elf(filename):
+ with open(filename, 'r') as f:
+ magic_bytes = f.read(4)
+ return magic_bytes == '\x7fELF'
+
+
+def is_mach_o(filename):
+ with open(filename, 'r') as f:
+ magic_bytes = f.read(4)
+ return magic_bytes in [
+ '\xfe\xed\xfa\xce', # MH_MAGIC
+ '\xce\xfa\xed\xfe', # MH_CIGAM
+ '\xfe\xed\xfa\xcf', # MH_MAGIC_64
+ '\xcf\xfa\xed\xfe', # MH_CIGAM_64
+ '\xca\xfe\xba\xbe', # FAT_MAGIC
+ '\xbe\xba\xfe\xca' # FAT_CIGAM
+ ]
+
+
+def is_library_file(filename):
+ if sys.platform == 'darwin':
+ return is_mach_o(filename)
+ else:
+ return is_elf(filename)
+
+
def extract_or_load(filename):
import sym_check.extract
- if filename.endswith('.so') or filename.endswith('.dylib'):
+ if is_library_file(filename):
return sym_check.extract.extract_symbols(filename)
return read_syms_from_file(filename)
More information about the cfe-commits
mailing list