From 13b833956024e8c48a14bac18972892c61318dc4 Mon Sep 17 00:00:00 2001 From: someone2639 Date: Sun, 25 Jun 2023 23:56:43 -0400 Subject: [PATCH] pack including static symbols using 'nm' (#646) Co-authored-by: someone2639 --- Makefile | 2 +- tools/mapPacker.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 0bce5954..e1391826 100644 --- a/Makefile +++ b/Makefile @@ -873,7 +873,7 @@ $(BUILD_DIR)/goddard.txt: $(BUILD_DIR)/sm64_prelim.elf $(BUILD_DIR)/asm/debug/map.o: asm/debug/map.s $(BUILD_DIR)/sm64_prelim.elf $(call print,Assembling:,$<,$@) - $(V)python3 tools/mapPacker.py $(BUILD_DIR)/sm64_prelim.map $(BUILD_DIR)/bin/addr.bin $(BUILD_DIR)/bin/name.bin + $(V)python3 tools/mapPacker.py $(BUILD_DIR)/sm64_prelim.elf $(BUILD_DIR)/bin/addr.bin $(BUILD_DIR)/bin/name.bin $(V)$(CROSS)gcc -c $(ASMFLAGS) $(foreach i,$(INCLUDE_DIRS),-Wa,-I$(i)) -x assembler-with-cpp -MMD -MF $(BUILD_DIR)/$*.d -o $@ $< # Link SM64 ELF file diff --git a/tools/mapPacker.py b/tools/mapPacker.py index d9954522..4ac4b669 100644 --- a/tools/mapPacker.py +++ b/tools/mapPacker.py @@ -1,4 +1,4 @@ -import sys, struct +import sys, struct, subprocess class MapEntry(): def __init__(self, nm, addr): @@ -15,11 +15,19 @@ structDef = ">LLLL" symNames = [] -with open(sys.argv[1]) as f: - for line in f: - if "0x000000008" in line and "=" not in line and "." not in line and "*" not in line and "load address" not in line: - tokens = line.split() - symNames.append(MapEntry(tokens[1], int(tokens[0], 16))) + +proc = subprocess.Popen(["nm", "-S", sys.argv[1]], stdout=subprocess.PIPE) + +symbols = proc.communicate()[0].decode('ascii').split("\n") +for line in symbols: + # format: + # 80153210 000000f8 T global_sym + # 80153210 t static_sym + tokens = line.split() + if len(tokens) >= 3 and len(tokens[-2]) == 1: + addr = int(tokens[0], 16) + if addr & 0x80000000 and tokens[-2].lower() == "t": + symNames.append(MapEntry(tokens[-1], addr))