scripts: Replaced nm with objdump in code.py/data.py
There is an argument for prefering nm for code size measurements due to portability. But I'm not sure this really holds up these days with objdump being so prevalent. We already depend on objdump for ctx/structs/perf and other dwarf info, so using objdump -t to get symbol information means one less tool to depend on/pass around when cross-compiling. As a minor benefit this also gives us more control over which sections to include, instead of relying on nm's predefined t/r/d/b section types. --- Note code.py/data.py did _not_ require objdump before this. They did use objdump to map symbols to source files, but would just guess if objdump wasn't available.
This commit is contained in:
+13
-4
@@ -225,12 +225,13 @@ class SymInfo:
|
||||
def __iter__(self):
|
||||
return iter(self.syms)
|
||||
|
||||
def collect_syms(obj_path, global_only=False, *,
|
||||
def collect_syms(obj_path, sections=None, global_=False, *,
|
||||
objdump_path=OBJDUMP_PATH,
|
||||
**args):
|
||||
symbol_pattern = re.compile(
|
||||
'^(?P<addr>[0-9a-fA-F]+)'
|
||||
' (?P<scope>.).*'
|
||||
'\s+(?P<section>[^\s]+)'
|
||||
'\s+(?P<size>[0-9a-fA-F]+)'
|
||||
'\s+(?P<name>[^\s]+)\s*$')
|
||||
|
||||
@@ -249,6 +250,7 @@ def collect_syms(obj_path, global_only=False, *,
|
||||
if m:
|
||||
name = m.group('name')
|
||||
scope = m.group('scope')
|
||||
section = m.group('section')
|
||||
addr = int(m.group('addr'), 16)
|
||||
size = int(m.group('size'), 16)
|
||||
# skip non-globals?
|
||||
@@ -257,9 +259,14 @@ def collect_syms(obj_path, global_only=False, *,
|
||||
# u => unique global
|
||||
# => neither
|
||||
# ! => local + global
|
||||
if global_only and scope in 'l ':
|
||||
if global_ and scope in 'l ':
|
||||
continue
|
||||
# ignore zero-sized symbols
|
||||
# filter by section? note we accept prefixes
|
||||
if (sections is not None
|
||||
and not any(section.startswith(prefix)
|
||||
for prefix in sections)):
|
||||
continue
|
||||
# skip zero sized symbols
|
||||
if not size:
|
||||
continue
|
||||
# note multiple symbols can share a name
|
||||
@@ -673,7 +680,9 @@ def collect(obj_path, trace_paths, *,
|
||||
jobs = len(os.sched_getaffinity(0))
|
||||
|
||||
# find sym/line info to reverse ASLR
|
||||
syms = collect_syms(obj_path, **args)
|
||||
syms = collect_syms(obj_path,
|
||||
sections=['.text'],
|
||||
**args)
|
||||
lines = collect_dwarf_lines(obj_path, **args)
|
||||
|
||||
if jobs is not None:
|
||||
|
||||
Reference in New Issue
Block a user