libbb: reduce the overhead of single parameter bb_error_msg() calls
authorJames Byrne <james.byrne@origamienergy.com>
Tue, 2 Jul 2019 09:35:03 +0000 (11:35 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 2 Jul 2019 09:35:03 +0000 (11:35 +0200)
commit6937487be73cd4563b876413277a295a5fe2f32c
treef16cc9999a7c827891e6ec8d99c699fc791008ee
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2
libbb: reduce the overhead of single parameter bb_error_msg() calls

Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().

This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.

Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.

This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.

The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):

Arm:     -92 bytes
MIPS:    -52 bytes
PPC:   -1836 bytes
x86_64: -938 bytes

Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.

Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
225 files changed:
Config.in
archival/bbunzip.c
archival/bzip2.c
archival/dpkg.c
archival/gzip.c
archival/libarchive/data_extract_all.c
archival/libarchive/decompress_bunzip2.c
archival/libarchive/decompress_gunzip.c
archival/libarchive/decompress_uncompress.c
archival/libarchive/decompress_unlzma.c
archival/libarchive/decompress_unxz.c
archival/libarchive/get_header_ar.c
archival/libarchive/get_header_cpio.c
archival/libarchive/get_header_tar.c
archival/libarchive/open_transformer.c
archival/libarchive/seek_by_jump.c
archival/libarchive/unpack_ar_archive.c
archival/lzop.c
archival/rpm.c
archival/tar.c
archival/unzip.c
console-tools/loadfont.c
console-tools/loadkmap.c
console-tools/openvt.c
console-tools/showkey.c
coreutils/cp.c
coreutils/cut.c
coreutils/date.c
coreutils/df.c
coreutils/echo.c
coreutils/env.c
coreutils/expand.c
coreutils/expr.c
coreutils/id.c
coreutils/install.c
coreutils/ln.c
coreutils/logname.c
coreutils/md5_sha1_sum.c
coreutils/od_bloaty.c
coreutils/paste.c
coreutils/printf.c
coreutils/rm.c
coreutils/sort.c
coreutils/split.c
coreutils/stty.c
coreutils/tail.c
coreutils/test.c
coreutils/tr.c
coreutils/uudecode.c
coreutils/uuencode.c
debianutils/start_stop_daemon.c
e2fsprogs/chattr.c
e2fsprogs/fsck.c
editors/awk.c
editors/diff.c
editors/ed.c
editors/patch_bbox.c
editors/patch_toybox.c
editors/sed.c
editors/vi.c
findutils/find.c
findutils/xargs.c
include/libbb.h
init/bootchartd.c
init/init.c
libbb/appletlib.c
libbb/bb_getgroups.c
libbb/bbunit.c
libbb/capability.c
libbb/change_identity.c
libbb/copy_file.c
libbb/copyfd.c
libbb/die_if_bad_username.c
libbb/dump.c
libbb/fflush_stdout_and_exit.c
libbb/get_console.c
libbb/get_volsize.c
libbb/getpty.c
libbb/herror_msg.c
libbb/mtab.c
libbb/perror_nomsg.c
libbb/perror_nomsg_and_die.c
libbb/read_printf.c
libbb/safe_poll.c
libbb/selinux_common.c
libbb/time.c
libbb/update_passwd.c
libbb/uuencode.c
libbb/verror_msg.c
libbb/warn_ignoring_args.c
libbb/xconnect.c
libbb/xfuncs.c
libbb/xfuncs_printf.c
libbb/xgetcwd.c
libbb/xgethostbyname.c
loginutils/addgroup.c
loginutils/adduser.c
loginutils/chpasswd.c
loginutils/deluser.c
loginutils/getty.c
loginutils/login.c
loginutils/su.c
loginutils/sulogin.c
mailutils/mail.c
mailutils/popmaildir.c
mailutils/sendmail.c
miscutils/bc.c
miscutils/chat.c
miscutils/crond.c
miscutils/crontab.c
miscutils/dc.c
miscutils/devfsd.c
miscutils/devmem.c
miscutils/fbsplash.c
miscutils/flash_eraseall.c
miscutils/hdparm.c
miscutils/hexedit.c
miscutils/i2c_tools.c
miscutils/inotifyd.c
miscutils/nandwrite.c
miscutils/rfkill.c
miscutils/rx.c
miscutils/time.c
miscutils/ubi_tools.c
miscutils/ubirename.c
modutils/modutils-24.c
modutils/rmmod.c
networking/arp.c
networking/arping.c
networking/dnsd.c
networking/ether-wake.c
networking/ftpgetput.c
networking/hostname.c
networking/httpd.c
networking/ifconfig.c
networking/ifplugd.c
networking/ifupdown.c
networking/inetd.c
networking/ipcalc.c
networking/isrv.c
networking/libiproute/ipaddress.c
networking/libiproute/ipneigh.c
networking/libiproute/iproute.c
networking/libiproute/iptunnel.c
networking/libiproute/libnetlink.c
networking/libiproute/utils.c
networking/nbd-client.c
networking/nc.c
networking/nc_bloaty.c
networking/netstat.c
networking/nslookup.c
networking/ntpd.c
networking/ping.c
networking/route.c
networking/slattach.c
networking/tcpudp.c
networking/telnetd.c
networking/tftp.c
networking/tls.c
networking/tls.h
networking/traceroute.c
networking/udhcp/arpping.c
networking/udhcp/common.c
networking/udhcp/common.h
networking/udhcp/d6_dhcpc.c
networking/udhcp/d6_packet.c
networking/udhcp/d6_socket.c
networking/udhcp/dhcpc.c
networking/udhcp/dhcpd.c
networking/udhcp/dhcprelay.c
networking/udhcp/packet.c
networking/udhcp/signalpipe.c
networking/udhcp/socket.c
networking/wget.c
networking/zcip.c
printutils/lpr.c
procps/kill.c
procps/mpstat.c
procps/powertop.c
procps/pstree.c
procps/top.c
runit/chpst.c
runit/svlogd.c
selinux/chcon.c
selinux/getenforce.c
selinux/getsebool.c
selinux/load_policy.c
selinux/runcon.c
selinux/sestatus.c
selinux/setenforce.c
selinux/setfiles.c
selinux/setsebool.c
shell/hush.c
shell/shell_common.c
sysklogd/klogd.c
sysklogd/logread.c
sysklogd/syslogd.c
util-linux/acpid.c
util-linux/dmesg.c
util-linux/eject.c
util-linux/fdformat.c
util-linux/fdisk.c
util-linux/flock.c
util-linux/fsck_minix.c
util-linux/getopt.c
util-linux/hwclock.c
util-linux/ipcs.c
util-linux/last.c
util-linux/losetup.c
util-linux/mdev.c
util-linux/mesg.c
util-linux/mkfs_ext2.c
util-linux/mkfs_minix.c
util-linux/mkfs_reiser.c
util-linux/mkfs_vfat.c
util-linux/mkswap.c
util-linux/mount.c
util-linux/nsenter.c
util-linux/rdate.c
util-linux/readprofile.c
util-linux/rtcwake.c
util-linux/setpriv.c
util-linux/switch_root.c
util-linux/uevent.c
util-linux/unshare.c