pack including static symbols using 'nm' (#646)

Co-authored-by: someone2639 <someone2639@gmail.com>
This commit is contained in:
someone2639
2023-06-25 23:56:43 -04:00
committed by GitHub
parent 823101164d
commit 13b8339560
2 changed files with 15 additions and 7 deletions

View File

@@ -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

View File

@@ -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))