gen_symtab.py 841 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. '''
  3. Embedded symbol table generator.
  4. '''
  5. import sys
  6. symtab = []
  7. for line in sys.stdin:
  8. line = line.strip()
  9. parts = line.split(' ')
  10. if len(parts) != 4 or parts[3].startswith("__func__."):
  11. continue
  12. del parts[2]
  13. sym = {'addr': parts[0], 'size': parts[1], 'name': parts[2]}
  14. symtab.append(sym)
  15. print("#include <kern/symbol.h>")
  16. for index, sym in enumerate(symtab):
  17. print("static const char symbol_name_%u[] __symbol_table = \"%s\";" % (index, sym['name']))
  18. print("const struct symbol symbol_table[] __symbol_table = {")
  19. for index, sym in enumerate(symtab):
  20. print(" { 0x%s, 0x%s, symbol_name_%u }," % (sym['addr'], sym['size'], index))
  21. print("};")
  22. print("const size_t symbol_table_size = %d;" % len(symtab))
  23. print("const struct symbol *symbol_table_ptr = symbol_table;")