diff options
author | Ron Yorston <rmy@pobox.com> | 2021-03-10 08:57:42 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-03-10 09:00:58 +0000 |
commit | 35f7c5e6e8519ca16363c799fb1b112edf1eb12b (patch) | |
tree | 48d6d8f7e31b568033c5da64c28613c3492997a8 | |
parent | 9da193543f73e3e3c97a40221959e5ea2aea2054 (diff) | |
download | busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.tar.gz busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.tar.bz2 busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.zip |
build system: add support for 'make bloatcheck'
Plus a few other make targets that make measurements on the binary.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.custom | 22 | ||||
-rwxr-xr-x | 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 | |||
20 | /busybox | 20 | /busybox |
21 | /busybox.exe | 21 | /busybox.exe |
22 | /busybox_old | 22 | /busybox_old |
23 | /busybox_old.exe | ||
23 | /busybox_unstripped* | 24 | /busybox_unstripped* |
24 | win32/resources/busybox-w32.manifest | 25 | win32/resources/busybox-w32.manifest |
25 | 26 | ||
diff --git a/Makefile.custom b/Makefile.custom index 6f679c4e1..e2f6d1c2f 100644 --- a/Makefile.custom +++ b/Makefile.custom | |||
@@ -104,29 +104,29 @@ checkhelp: | |||
104 | $(patsubst %,$(srctree)/%,$(wildcard $(patsubst %,%/Config.in,$(busybox-dirs) ./))) | 104 | $(patsubst %,$(srctree)/%,$(wildcard $(patsubst %,%/Config.in,$(busybox-dirs) ./))) |
105 | 105 | ||
106 | .PHONY: sizes | 106 | .PHONY: sizes |
107 | sizes: busybox_unstripped | 107 | sizes: busybox_unstripped$(EXEEXT) |
108 | $(NM) --size-sort $(<) | 108 | $(NM) --size-sort $(<) |
109 | 109 | ||
110 | .PHONY: bloatcheck | 110 | .PHONY: bloatcheck |
111 | bloatcheck: busybox_old busybox_unstripped | 111 | bloatcheck: busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) |
112 | @$(srctree)/scripts/bloat-o-meter busybox_old busybox_unstripped | 112 | @$(srctree)/scripts/bloat-o-meter busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) |
113 | @$(CROSS_COMPILE)size busybox_old busybox_unstripped | 113 | @$(CROSS_COMPILE)size busybox_old$(EXEEXT) busybox_unstripped$(EXEEXT) |
114 | 114 | ||
115 | .PHONY: baseline | 115 | .PHONY: baseline |
116 | baseline: busybox_unstripped | 116 | baseline: busybox_unstripped$(EXEEXT) |
117 | @mv busybox_unstripped busybox_old | 117 | @mv busybox_unstripped$(EXEEXT) busybox_old$(EXEEXT) |
118 | 118 | ||
119 | .PHONY: objsizes | 119 | .PHONY: objsizes |
120 | objsizes: busybox_unstripped | 120 | objsizes: busybox_unstripped$(EXEEXT) |
121 | $(srctree)/scripts/objsizes | 121 | $(srctree)/scripts/objsizes |
122 | 122 | ||
123 | .PHONY: stksizes | 123 | .PHONY: stksizes |
124 | stksizes: busybox_unstripped | 124 | stksizes: busybox_unstripped$(EXEEXT) |
125 | $(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq | 125 | $(CROSS_COMPILE)objdump -d busybox_unstripped$(EXEEXT) | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq |
126 | 126 | ||
127 | .PHONY: bigdata | 127 | .PHONY: bigdata |
128 | bigdata: busybox_unstripped | 128 | bigdata: busybox_unstripped$(EXEEXT) |
129 | $(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] ' | 129 | $(CROSS_COMPILE)nm --size-sort busybox_unstripped$(EXEEXT) | grep -vi ' [trw] ' |
130 | 130 | ||
131 | # Documentation Targets | 131 | # Documentation Targets |
132 | .PHONY: doc | 132 | .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: | |||
43 | 43 | ||
44 | sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) | 44 | sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) |
45 | def getsizes(file): | 45 | def getsizes(file): |
46 | if file.endswith(".exe"): | ||
47 | return getsizes_pe(file) | ||
46 | sym, alias, lut, section = {}, {}, {}, {} | 48 | sym, alias, lut, section = {}, {}, {}, {} |
47 | for l in os.popen("readelf -W -S " + file).readlines(): | 49 | for l in os.popen("readelf -W -S " + file).readlines(): |
48 | x = l.replace("[ ", "[", 1).split() | 50 | x = l.replace("[ ", "[", 1).split() |
@@ -80,6 +82,29 @@ def getsizes(file): | |||
80 | sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} | 82 | sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} |
81 | return sym | 83 | return sym |
82 | 84 | ||
85 | def getsizes_pe(file): | ||
86 | sym, sections = {}, {} | ||
87 | prefix = os.getenv("CROSS_COMPILE", "") | ||
88 | for l in os.popen(prefix + "objdump -h " + file).readlines(): | ||
89 | x = l.split() | ||
90 | if len(x) != 7: continue | ||
91 | sections[x[1]] = 1 | ||
92 | if x[1] not in [".rdata"]: continue | ||
93 | sym[x[1]] = {"addr" : int(x[3], 16), "size" : int(x[2], 16)} | ||
94 | for l in os.popen(prefix + "nm -S --size-sort %s %s" % (sym_args, file)).readlines(): | ||
95 | if len(l.split()) != 4: continue | ||
96 | value, size, typ, name = l.split() | ||
97 | if typ in ["N"]: continue # skip debug symbols | ||
98 | if name in sections: continue # bare reference to section | ||
99 | value = int(value, 16) | ||
100 | size = int(size, 16) | ||
101 | if "$" in name: | ||
102 | section, name = name.split("$") | ||
103 | if section in sym: | ||
104 | sym[section]["size"] -= size | ||
105 | sym[name] = {"addr" : value, "size": size} | ||
106 | return sym | ||
107 | |||
83 | if flag_timing: | 108 | if flag_timing: |
84 | start_t1 = int(time.time() * 1e9) | 109 | start_t1 = int(time.time() * 1e9) |
85 | old = getsizes(f1) | 110 | old = getsizes(f1) |