summaryrefslogtreecommitdiff
path: root/archival/libarchive
diff options
context:
space:
mode:
authorJames Byrne2019-07-02 11:35:03 +0200
committerDenys Vlasenko2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /archival/libarchive
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-6937487be73cd4563b876413277a295a5fe2f32c.zip
busybox-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
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>
Diffstat (limited to 'archival/libarchive')
-rw-r--r--archival/libarchive/data_extract_all.c4
-rw-r--r--archival/libarchive/decompress_bunzip2.c2
-rw-r--r--archival/libarchive/decompress_gunzip.c14
-rw-r--r--archival/libarchive/decompress_uncompress.c10
-rw-r--r--archival/libarchive/decompress_unlzma.c6
-rw-r--r--archival/libarchive/decompress_unxz.c4
-rw-r--r--archival/libarchive/get_header_ar.c8
-rw-r--r--archival/libarchive/get_header_cpio.c6
-rw-r--r--archival/libarchive/get_header_tar.c14
-rw-r--r--archival/libarchive/open_transformer.c6
-rw-r--r--archival/libarchive/seek_by_jump.c2
-rw-r--r--archival/libarchive/unpack_ar_archive.c2
12 files changed, 39 insertions, 39 deletions
diff --git a/archival/libarchive/data_extract_all.c b/archival/libarchive/data_extract_all.c
index 4c95db4..3142405 100644
--- a/archival/libarchive/data_extract_all.c
+++ b/archival/libarchive/data_extract_all.c
@@ -103,7 +103,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
struct stat existing_sb;
if (lstat(dst_name, &existing_sb) == -1) {
if (errno != ENOENT) {
- bb_perror_msg_and_die("can't stat old file");
+ bb_simple_perror_msg_and_die("can't stat old file");
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
@@ -207,7 +207,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
break;
default:
- bb_error_msg_and_die("unrecognized file type");
+ bb_simple_error_msg_and_die("unrecognized file type");
}
if (!S_ISLNK(file_header->mode)) {
diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c
index 1f535b3..42e2b4f 100644
--- a/archival/libarchive/decompress_bunzip2.c
+++ b/archival/libarchive/decompress_bunzip2.c
@@ -817,7 +817,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
break;
}
if (bd->headerCRC != bd->totalCRC) {
- bb_error_msg("CRC error");
+ bb_simple_error_msg("CRC error");
break;
}
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 7f9046b..1ddce61 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -1012,7 +1012,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
- bb_error_msg(error_msg);
+ bb_simple_error_msg(error_msg);
n = -1;
goto ret;
}
@@ -1085,7 +1085,7 @@ static int top_up(STATE_PARAM unsigned n)
bytebuffer_offset = 0;
bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
if ((int)bytebuffer_size < 0) {
- bb_error_msg(bb_msg_read_error);
+ bb_simple_error_msg(bb_msg_read_error);
return 0;
}
bytebuffer_size += count;
@@ -1211,7 +1211,7 @@ unpack_gz_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
bad_magic:
- bb_error_msg("invalid magic");
+ bb_simple_error_msg("invalid magic");
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
@@ -1233,7 +1233,7 @@ unpack_gz_stream(transformer_state_t *xstate)
again:
if (!check_header_gzip(PASS_STATE xstate)) {
- bb_error_msg("corrupted data");
+ bb_simple_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1246,7 +1246,7 @@ unpack_gz_stream(transformer_state_t *xstate)
total += n;
if (!top_up(PASS_STATE 8)) {
- bb_error_msg("corrupted data");
+ bb_simple_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1254,7 +1254,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - crc */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((~gunzip_crc) != v32) {
- bb_error_msg("crc error");
+ bb_simple_error_msg("crc error");
total = -1;
goto ret;
}
@@ -1262,7 +1262,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - size */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((uint32_t)gunzip_bytes_out != v32) {
- bb_error_msg("incorrect length");
+ bb_simple_error_msg("incorrect length");
total = -1;
}
diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c
index 1517559..2725a7f 100644
--- a/archival/libarchive/decompress_uncompress.c
+++ b/archival/libarchive/decompress_uncompress.c
@@ -113,7 +113,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
- bb_error_msg("short read");
+ bb_simple_error_msg("short read");
goto err;
}
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
if (rsize < 0)
- bb_error_msg_and_die(bb_msg_read_error);
+ bb_simple_error_msg_and_die(bb_msg_read_error);
insize += rsize;
}
@@ -200,7 +200,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (oldcode == -1) {
if (code >= 256)
- bb_error_msg_and_die("corrupted data"); /* %ld", code); */
+ bb_simple_error_msg_and_die("corrupted data"); /* %ld", code); */
oldcode = code;
finchar = (int) oldcode;
outbuf[outpos++] = (unsigned char) finchar;
@@ -236,7 +236,7 @@ unpack_Z_stream(transformer_state_t *xstate)
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
(posbits & 07));
*/
- bb_error_msg("corrupted data");
+ bb_simple_error_msg("corrupted data");
goto err;
}
@@ -247,7 +247,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* Generate output characters in reverse order */
while (code >= 256) {
if (stackp <= &htabof(0))
- bb_error_msg_and_die("corrupted data");
+ bb_simple_error_msg_and_die("corrupted data");
*--stackp = tab_suffixof(code);
code = tab_prefixof(code);
}
diff --git a/archival/libarchive/decompress_unlzma.c b/archival/libarchive/decompress_unlzma.c
index 668b016..0744f23 100644
--- a/archival/libarchive/decompress_unlzma.c
+++ b/archival/libarchive/decompress_unlzma.c
@@ -59,7 +59,7 @@ static void rc_read(rc_t *rc)
//TODO: return -1 instead
//This will make unlzma delete broken unpacked file on unpack errors
if (buffer_size <= 0)
- bb_error_msg_and_die("unexpected EOF");
+ bb_simple_error_msg_and_die("unexpected EOF");
rc->buffer_end = RC_BUFFER + buffer_size;
rc->ptr = RC_BUFFER;
}
@@ -234,7 +234,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
- bb_error_msg("bad lzma header");
+ bb_simple_error_msg("bad lzma header");
return -1;
}
@@ -513,7 +513,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
* potentially more detailed information).
* Do not fail silently.
*/
- bb_error_msg("corrupted data");
+ bb_simple_error_msg("corrupted data");
total_written = -1; /* failure */
}
rc_free(rc);
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c
index 8ae7a27..f033413 100644
--- a/archival/libarchive/decompress_unxz.c
+++ b/archival/libarchive/decompress_unxz.c
@@ -74,7 +74,7 @@ unpack_xz_stream(transformer_state_t *xstate)
if (iobuf.in_pos == iobuf.in_size) {
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
if (rd < 0) {
- bb_error_msg(bb_msg_read_error);
+ bb_simple_error_msg(bb_msg_read_error);
total = -1;
break;
}
@@ -123,7 +123,7 @@ unpack_xz_stream(transformer_state_t *xstate)
continue;
}
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
- bb_error_msg("corrupted data");
+ bb_simple_error_msg("corrupted data");
total = -1;
break;
}
diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c
index 7ce9c61..b6ecd59 100644
--- a/archival/libarchive/get_header_ar.c
+++ b/archival/libarchive/get_header_ar.c
@@ -22,7 +22,7 @@ static unsigned read_num(char *str, int base, int len)
* on misformatted numbers bb_strtou returns all-ones */
err = bb_strtou(str, NULL, base);
if (err == -1)
- bb_error_msg_and_die("invalid ar header");
+ bb_simple_error_msg_and_die("invalid ar header");
return err;
}
@@ -53,7 +53,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->offset += 60;
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
- bb_error_msg_and_die("invalid ar header");
+ bb_simple_error_msg_and_die("invalid ar header");
/*
* Note that the fields MUST be read in reverse order as
@@ -86,7 +86,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
return get_header_ar(archive_handle);
}
#else
- bb_error_msg_and_die("long filenames not supported");
+ bb_simple_error_msg_and_die("long filenames not supported");
#endif
}
/* Only size is always present, the rest may be missing in
@@ -107,7 +107,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
long_offset = read_num(&ar.formatted.name[1], 10,
sizeof(ar.formatted.name) - 1);
if (long_offset >= archive_handle->ar__long_name_size) {
- bb_error_msg_and_die("can't resolve long filename");
+ bb_simple_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
} else
diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c
index 75fc6a4..4ad1747 100644
--- a/archival/libarchive/get_header_cpio.c
+++ b/archival/libarchive/get_header_cpio.c
@@ -33,14 +33,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
goto create_hardlinks;
}
if (size != 110) {
- bb_error_msg_and_die("short read");
+ bb_simple_error_msg_and_die("short read");
}
archive_handle->offset += 110;
if (!is_prefixed_with(&cpio_header[0], "07070")
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
) {
- bb_error_msg_and_die("unsupported cpio format, use newc or crc");
+ bb_simple_error_msg_and_die("unsupported cpio format, use newc or crc");
}
if (sscanf(cpio_header + 6,
@@ -50,7 +50,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
&inode, &mode, &uid, &gid,
&nlink, &mtime, &size,
&major, &minor, &namesize) != 10)
- bb_error_msg_and_die("damaged cpio file");
+ bb_simple_error_msg_and_die("damaged cpio file");
file_header->mode = mode;
/* "cpio -R USER:GRP" support: */
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 52fa455..b3131ff 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -32,7 +32,7 @@ static unsigned long long getOctal(char *str, int len)
if (*end != '\0' && *end != ' ') {
int8_t first = str[0];
if (!(first & 0x80))
- bb_error_msg_and_die("corrupted octal value in tar header");
+ bb_simple_error_msg_and_die("corrupted octal value in tar header");
/*
* GNU tar uses "base-256 encoding" for very large numbers.
* Encoding is binary, with highest bit always set as a marker
@@ -100,7 +100,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|| errno != EINVAL
|| *end != ' '
) {
- bb_error_msg("malformed extended header, skipped");
+ bb_simple_error_msg("malformed extended header, skipped");
// More verbose version:
//bb_error_msg("malformed extended header at %"OFF_FMT"d, skipped",
// archive_handle->offset - (sz + len));
@@ -194,13 +194,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* the very first read fails. Grrr.
*/
if (archive_handle->offset == 0)
- bb_error_msg("short read");
+ bb_simple_error_msg("short read");
/* this merely signals end of archive, not exit(1): */
return EXIT_FAILURE;
}
if (i != 512) {
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
- bb_error_msg_and_die("short read");
+ bb_simple_error_msg_and_die("short read");
}
#else
@@ -243,11 +243,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto err;
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
err:
- bb_error_msg_and_die("invalid tar magic");
+ bb_simple_error_msg_and_die("invalid tar magic");
archive_handle->offset = 0;
goto again_after_align;
#endif
- bb_error_msg_and_die("invalid tar magic");
+ bb_simple_error_msg_and_die("invalid tar magic");
}
/* Do checksum on headers.
@@ -282,7 +282,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
- bb_error_msg_and_die("invalid tar header checksum");
+ bb_simple_error_msg_and_die("invalid tar header checksum");
}
/* GET_OCTAL trashes subsequent field, therefore we call it
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index a90f42a..44715ef 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -15,7 +15,7 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
- bb_error_msg("invalid magic");
+ bb_simple_error_msg("invalid magic");
return -1;
}
xstate->signature_skipped = 2;
@@ -46,7 +46,7 @@ ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf
} else {
nwrote = full_write(xstate->dst_fd, buf, bufsize);
if (nwrote != (ssize_t)bufsize) {
- bb_perror_msg("write");
+ bb_simple_perror_msg("write");
nwrote = -1;
goto ret;
}
@@ -205,7 +205,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
/* No known magic seen */
if (fail_if_not_compressed)
- bb_error_msg_and_die("no gzip"
+ bb_simple_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
" magic");
diff --git a/archival/libarchive/seek_by_jump.c b/archival/libarchive/seek_by_jump.c
index 232d97e..dddaa37 100644
--- a/archival/libarchive/seek_by_jump.c
+++ b/archival/libarchive/seek_by_jump.c
@@ -13,6 +13,6 @@ void FAST_FUNC seek_by_jump(int fd, off_t amount)
if (errno == ESPIPE)
seek_by_read(fd, amount);
else
- bb_perror_msg_and_die("seek failure");
+ bb_simple_perror_msg_and_die("seek failure");
}
}
diff --git a/archival/libarchive/unpack_ar_archive.c b/archival/libarchive/unpack_ar_archive.c
index 4f9f898..584c18c 100644
--- a/archival/libarchive/unpack_ar_archive.c
+++ b/archival/libarchive/unpack_ar_archive.c
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
if (!is_prefixed_with(magic, AR_MAGIC)) {
- bb_error_msg_and_die("invalid ar magic");
+ bb_simple_error_msg_and_die("invalid ar magic");
}
ar_archive->offset += AR_MAGIC_LEN;