- sym = {}
- 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)
- for l in os.popen("readelf -S " + file).readlines():
+ sym, alias, lut = {}, {}, {}
+ for l in os.popen("readelf -W -s %s %s" % (sym_args, file)).readlines():
+ l = l.strip()
+ if not (len(l) and l[0].isdigit() and len(l.split()) == 8):
+ continue
+ num, value, size, typ, bind, vis, ndx, name = l.split()
+ if ndx == "UND": continue # skip undefined
+ if typ in ["SECTION", "FILES"]: continue # skip sections and files
+ if "." in name: name = "static." + name.split(".")[0]
+ value = int(value, 16)
+ size = int(size, 16) if size.startswith('0x') else int(size)
+ if vis != "DEFAULT" and bind != "GLOBAL": # see if it is an alias
+ alias[(value, size)] = {"name" : name}
+ else:
+ sym[name] = {"addr" : value, "size": size}
+ lut[(value, size)] = 0
+ for addr, sz in iter(alias.keys()):
+ # If the non-GLOBAL sym has an implementation elsewhere then
+ # it's an alias, disregard it.
+ if not (addr, sz) in lut:
+ # If this non-GLOBAL sym does not have an implementation at
+ # another address, then treat it as a normal symbol.
+ sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz}
+ for l in os.popen("readelf -W -S " + file).readlines():