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>
diff --git a/scripts/build/gen_symtab.py b/scripts/build/gen_symtab.py
index ef08456..b5abf8e 100644
--- a/scripts/build/gen_symtab.py
+++ b/scripts/build/gen_symtab.py
@@ -61,6 +61,9 @@
self.offset = offset
self.name = name
+ def __eq__(self, other):
+ return self.addr == other.addr
+
start_addr = 0
symtab_list = []
@@ -95,22 +98,30 @@
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)