From 35f7c5e6e8519ca16363c799fb1b112edf1eb12b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 10 Mar 2021 08:57:42 +0000 Subject: build system: add support for 'make bloatcheck' Plus a few other make targets that make measurements on the binary. --- .gitignore | 1 + Makefile.custom | 22 +++++++++++----------- scripts/bloat-o-meter | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index cc485189e..764cc058a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ Config.in /busybox /busybox.exe /busybox_old +/busybox_old.exe /busybox_unstripped* win32/resources/busybox-w32.manifest diff --git a/Makefile.custom b/Makefile.custom index 6f679c4e1..e2f6d1c2f 100644 --- a/Makefile.custom +++ b/Makefile.custom @@ -104,29 +104,29 @@ checkhelp: $(patsubst %,$(srctree)/%,$(wildcard $(patsubst %,%/Config.in,$(busybox-dirs) ./))) .PHONY: sizes -sizes: busybox_unstripped +sizes: busybox_unstripped$(EXEEXT) $(NM) --size-sort $(<) .PHONY: bloatcheck -bloatcheck: busybox_old busybox_unstripped - @$(srctree)/scripts/bloat-o-meter busybox_old busybox_unstripped - @$(CROSS_COMPILE)size busybox_old busybox_unstripped +bloatcheck: busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) + @$(srctree)/scripts/bloat-o-meter busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) + @$(CROSS_COMPILE)size busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) .PHONY: baseline -baseline: busybox_unstripped - @mv busybox_unstripped busybox_old +baseline: busybox_unstripped$(EXEEXT) + @mv busybox_unstripped$(EXEEXT) busybox_old$(EXEEXT) .PHONY: objsizes -objsizes: busybox_unstripped +objsizes: busybox_unstripped$(EXEEXT) $(srctree)/scripts/objsizes .PHONY: stksizes -stksizes: busybox_unstripped - $(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq +stksizes: busybox_unstripped$(EXEEXT) + $(CROSS_COMPILE)objdump -d busybox_unstripped$(EXEEXT) | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq .PHONY: bigdata -bigdata: busybox_unstripped - $(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] ' +bigdata: busybox_unstripped$(EXEEXT) + $(CROSS_COMPILE)nm --size-sort busybox_unstripped$(EXEEXT) | grep -vi ' [trw] ' # Documentation Targets .PHONY: doc diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index b4a1d2811..26474595f 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -43,6 +43,8 @@ if f1 is None or f2 is None: sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) def getsizes(file): + if file.endswith(".exe"): + return getsizes_pe(file) sym, alias, lut, section = {}, {}, {}, {} for l in os.popen("readelf -W -S " + file).readlines(): x = l.replace("[ ", "[", 1).split() @@ -80,6 +82,29 @@ def getsizes(file): sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} return sym +def getsizes_pe(file): + sym, sections = {}, {} + prefix = os.getenv("CROSS_COMPILE", "") + for l in os.popen(prefix + "objdump -h " + file).readlines(): + x = l.split() + if len(x) != 7: continue + sections[x[1]] = 1 + if x[1] not in [".rdata"]: continue + sym[x[1]] = {"addr" : int(x[3], 16), "size" : int(x[2], 16)} + for l in os.popen(prefix + "nm -S --size-sort %s %s" % (sym_args, file)).readlines(): + if len(l.split()) != 4: continue + value, size, typ, name = l.split() + if typ in ["N"]: continue # skip debug symbols + if name in sections: continue # bare reference to section + value = int(value, 16) + size = int(size, 16) + if "$" in name: + section, name = name.split("$") + if section in sym: + sym[section]["size"] -= size + sym[name] = {"addr" : value, "size": size} + return sym + if flag_timing: start_t1 = int(time.time() * 1e9) old = getsizes(f1) -- cgit v1.2.3-55-g6feb