From 29423eb17e625294ef870e27df826432cd4d0e6e Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Tue, 28 May 2024 12:26:58 +0800 Subject: [PATCH] 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 --- scripts/build/gen_symtab.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/build/gen_symtab.py b/scripts/build/gen_symtab.py index ef08456950a..b5abf8e4ea9 100644 --- a/scripts/build/gen_symtab.py +++ b/scripts/build/gen_symtab.py @@ -61,6 +61,9 @@ class symtab_entry: self.offset = offset self.name = name + def __eq__(self, other): + return self.addr == other.addr + start_addr = 0 symtab_list = [] @@ -95,22 +98,30 @@ def main(): if symbol_type == 'FUNC' and symbol_addr != 0: symbol_name = sanitize_func_name(symbol.name) - symtab_list.append(symtab_entry( - symbol_addr, symbol_addr, symbol_size, symbol_name)) - log.debug('%6d: %s %.25s' % ( - i, - hex(symbol_addr), - symbol_name)) - i = i + 1 + dummy_offset = 0 # offsets will be calculated later after we know the first address + entry = symtab_entry( + symbol_addr, symbol_size, dummy_offset, symbol_name) + # Prevent entries with duplicated addresses + if entry not in symtab_list: + symtab_list.append(entry) + # Sort the address in ascending order symtab_list.sort(key=lambda x: x.addr, reverse=False) # Get the address of the first symbol 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): + # Offset is calculated here 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: print("/* AUTO-GENERATED by gen_symtab.py, do not edit! */", file=wf) print("", file=wf)