import sys, os, re
-if len(sys.argv) != 3:
+def usage():
sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
sys.exit(-1)
-for f in sys.argv[1], sys.argv[2]:
+if len(sys.argv) < 3:
+ usage()
+
+for f in sys.argv[1:3]:
if not os.path.exists(f):
sys.stderr.write("Error: file '%s' does not exist\n" % f)
- sys.exit(-1)
+ usage()
+nm_args = " ".join(sys.argv[3:])
def getsizes(file):
sym = {}
- for l in os.popen("nm --size-sort " + file).readlines():
- size, type, name = l[:-1].split()
+ for l in os.popen("nm --size-sort %s %s" % (nm_args, file)).readlines():
+ l = l.strip()
+ # Skip empty lines
+ if not len(l): continue
+ # Skip archive members
+ if len(l.split()) == 1 and l.endswith(':'):
+ continue
+ size, type, name = l.split()
if type in "tTdDbBrR":
if "." in name: name = "static." + name.split(".")[0]
sym[name] = sym.get(name, 0) + int(size, 16)