build: symtab: prevent entries with the same address
Append new entry to the symtab list only if it has unique address. Added a bit more comments and move the debug print to after the list is sorted. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
f5934de8e5
commit
29423eb17e
1 changed files with 19 additions and 8 deletions
|
@ -61,6 +61,9 @@ class symtab_entry:
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.addr == other.addr
|
||||||
|
|
||||||
|
|
||||||
start_addr = 0
|
start_addr = 0
|
||||||
symtab_list = []
|
symtab_list = []
|
||||||
|
@ -95,22 +98,30 @@ def main():
|
||||||
|
|
||||||
if symbol_type == 'FUNC' and symbol_addr != 0:
|
if symbol_type == 'FUNC' and symbol_addr != 0:
|
||||||
symbol_name = sanitize_func_name(symbol.name)
|
symbol_name = sanitize_func_name(symbol.name)
|
||||||
symtab_list.append(symtab_entry(
|
dummy_offset = 0 # offsets will be calculated later after we know the first address
|
||||||
symbol_addr, symbol_addr, symbol_size, symbol_name))
|
entry = symtab_entry(
|
||||||
log.debug('%6d: %s %.25s' % (
|
symbol_addr, symbol_size, dummy_offset, symbol_name)
|
||||||
i,
|
# Prevent entries with duplicated addresses
|
||||||
hex(symbol_addr),
|
if entry not in symtab_list:
|
||||||
symbol_name))
|
symtab_list.append(entry)
|
||||||
i = i + 1
|
|
||||||
|
|
||||||
|
# Sort the address in ascending order
|
||||||
symtab_list.sort(key=lambda x: x.addr, reverse=False)
|
symtab_list.sort(key=lambda x: x.addr, reverse=False)
|
||||||
|
|
||||||
# Get the address of the first symbol
|
# Get the address of the first symbol
|
||||||
start_addr = symtab_list[0].addr
|
start_addr = symtab_list[0].addr
|
||||||
# Use that to calculate the offset of other symbols relative to the first one
|
|
||||||
for i, entry in enumerate(symtab_list):
|
for i, entry in enumerate(symtab_list):
|
||||||
|
# Offset is calculated here
|
||||||
entry.offset = entry.addr - start_addr
|
entry.offset = entry.addr - start_addr
|
||||||
|
|
||||||
|
# Debug print
|
||||||
|
log.debug('%6d: %s %s %.25s' % (
|
||||||
|
i,
|
||||||
|
hex(entry.addr),
|
||||||
|
hex(entry.size),
|
||||||
|
entry.name))
|
||||||
|
|
||||||
with open(args.output, 'w') as wf:
|
with open(args.output, 'w') as wf:
|
||||||
print("/* AUTO-GENERATED by gen_symtab.py, do not edit! */", file=wf)
|
print("/* AUTO-GENERATED by gen_symtab.py, do not edit! */", file=wf)
|
||||||
print("", file=wf)
|
print("", file=wf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue