summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-04-19 14:33:36 +0200
committerMark Wielaard <mark@klomp.org>2021-05-12 11:56:57 +0200
commitadc201f81902f3015a841869756ed4b9b811fe33 (patch)
tree735ab647b6e749f7bbbd1cd88256f89c2de266a9
parent857546d176a36d2b5dc18b81dcafa3fb8ec0123d (diff)
downloadelfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.gz
Come up with startswith function.
New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <mliska@suse.cz>
-rw-r--r--backends/ChangeLog5
-rw-r--r--backends/aarch64_symbol.c4
-rw-r--r--backends/arm_symbol.c4
-rw-r--r--debuginfod/ChangeLog6
-rw-r--r--debuginfod/debuginfod-client.c4
-rw-r--r--debuginfod/debuginfod.cxx9
-rw-r--r--lib/ChangeLog7
-rw-r--r--lib/system.h15
-rw-r--r--libasm/ChangeLog4
-rw-r--r--libasm/libasmP.h2
-rw-r--r--libdw/ChangeLog4
-rw-r--r--libdw/dwarf_begin_elf.c4
-rw-r--r--libdwfl/ChangeLog10
-rw-r--r--libdwfl/dwfl_frame.c4
-rw-r--r--libdwfl/dwfl_module_getdwarf.c4
-rw-r--r--libdwfl/linux-kernel-modules.c4
-rw-r--r--libdwfl/linux-pid-attach.c6
-rw-r--r--libdwfl/relocate.c8
-rw-r--r--libebl/ChangeLog5
-rw-r--r--libebl/eblobjnotetypename.c5
-rw-r--r--libebl/eblopenbackend.c4
-rw-r--r--src/ChangeLog11
-rw-r--r--src/elfclassify.c8
-rw-r--r--src/elfcompress.c25
-rw-r--r--src/nm.c2
-rw-r--r--src/readelf.c11
-rw-r--r--src/strip.c2
-rw-r--r--tests/ChangeLog8
-rw-r--r--tests/dwelf_elf_e_machine_string.c4
-rw-r--r--tests/dwelfgnucompressed.c4
-rw-r--r--tests/elfgetchdr.c4
-rw-r--r--tests/elfputzdata.c4
-rw-r--r--tests/vdsosyms.c2
33 files changed, 144 insertions, 59 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog
index eb15c81d..ac0e3187 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * aarch64_symbol.c (aarch64_data_marker_symbol): Use startswith.
+ * arm_symbol.c (arm_data_marker_symbol): Likewise.
+
2021-02-01 Érico Nogueira <ericonr@disroot.org>
* ppc_initreg.c: Also include <asm/ptrace.h>.
diff --git a/backends/aarch64_symbol.c b/backends/aarch64_symbol.c
index 464a5695..15e0805b 100644
--- a/backends/aarch64_symbol.c
+++ b/backends/aarch64_symbol.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <elf.h>
#include <stddef.h>
#include <string.h>
@@ -104,7 +106,7 @@ aarch64_data_marker_symbol (const GElf_Sym *sym, const char *sname)
return (sym != NULL && sname != NULL
&& sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
&& GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
- && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+ && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
}
const char *
diff --git a/backends/arm_symbol.c b/backends/arm_symbol.c
index c8e1d7f9..a733cfff 100644
--- a/backends/arm_symbol.c
+++ b/backends/arm_symbol.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <elf.h>
#include <stddef.h>
#include <string.h>
@@ -154,5 +156,5 @@ arm_data_marker_symbol (const GElf_Sym *sym, const char *sname)
return (sym != NULL && sname != NULL
&& sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
&& GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
- && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+ && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
}
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 97f598f6..249385b6 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * debuginfod-client.c (debuginfod_query_server): Use startswith.
+ (debuginfod_add_http_header): Likewise.
+ * debuginfod.cxx: Likewise.
+
2021-05-04 Alice Zhang <alizhang@redhat.com>
* debuginfod-client.c (cache_miss_default_s): New static time_t,
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 4fa047f5..cb51c261 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1054,7 +1054,7 @@ debuginfod_query_server (debuginfod_client *c,
&scheme);
if(ok3 == CURLE_OK && scheme)
{
- if (strncmp (scheme, "HTTP", 4) == 0)
+ if (startswith (scheme, "HTTP"))
if (resp_code == 200)
{
verified_handle = msg->easy_handle;
@@ -1318,7 +1318,7 @@ int debuginfod_add_http_header (debuginfod_client *client, const char* header)
/* Track if User-Agent: is being set. If so, signal not to add the
default one. */
- if (strncmp (header, "User-Agent:", 11) == 0)
+ if (startswith (header, "User-Agent:"))
client->user_agent_set_p = 1;
client->headers = temp;
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 0e6fd13f..e0948eab 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -37,6 +37,7 @@ extern "C" {
#include "debuginfod.h"
#include <dwarf.h>
+#include <system.h>
#include <argp.h>
#ifdef __GNUC__
@@ -2323,15 +2324,15 @@ elf_classify (int fd, bool &executable_p, bool &debuginfo_p, string &buildid, se
const char *section_name = elf_strptr (elf, shstrndx, shdr->sh_name);
if (section_name == NULL)
break;
- if (strncmp(section_name, ".debug_line", 11) == 0 ||
- strncmp(section_name, ".zdebug_line", 12) == 0)
+ if (startswith (section_name, ".debug_line") ||
+ startswith (section_name, ".zdebug_line"))
{
debuginfo_p = true;
dwarf_extract_source_paths (elf, debug_sourcefiles);
break; // expecting only one .*debug_line, so no need to look for others
}
- else if (strncmp(section_name, ".debug_", 7) == 0 ||
- strncmp(section_name, ".zdebug_", 8) == 0)
+ else if (startswith (section_name, ".debug_") ||
+ startswith (section_name, ".zdebug_"))
{
debuginfo_p = true;
// NB: don't break; need to parse .debug_line for sources
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 371e2133..dd3ebcab 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * system.h (startswith): New function.
+ (pwrite_retry): Cast to char *.
+ (write_retry): Likewise.
+ (pread_retry): Likewise.
+
2021-02-05 Mark Wielaard <mark@klomp.org>
* printversion.c (print_version): Update copyright year.
diff --git a/lib/system.h b/lib/system.h
index 1c478e1c..cdf18ed7 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -37,6 +37,7 @@
#include <endian.h>
#include <byteswap.h>
#include <unistd.h>
+#include <string.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define LE32(n) (n)
@@ -69,6 +70,14 @@
((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
#endif
+/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
({ const char *__res = strrchr (_(Str), '|'); \
@@ -104,7 +113,7 @@ pwrite_retry (int fd, const void *buf, size_t len, off_t off)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -123,7 +132,7 @@ write_retry (int fd, const void *buf, size_t len)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));
+ ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -141,7 +150,7 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 98ac3315..85e723e6 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * libasmP.h (asm_emit_symbol_p): Use startswith.
+
2020-12-16 Dmitry V. Levin <ldv@altlinux.org>
* libasmP.h (_): Remove.
diff --git a/libasm/libasmP.h b/libasm/libasmP.h
index 8b72f32b..5b5fb776 100644
--- a/libasm/libasmP.h
+++ b/libasm/libasmP.h
@@ -302,6 +302,6 @@ extern int __disasm_cb_internal (DisasmCtx_t *ctx, const uint8_t **startp,
// XXX The second part should probably be controlled by an option which
// isn't implemented yet
// XXX Also, the format will change with the backend.
-#define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0)
+#define asm_emit_symbol_p(name) (!startswith (name, ".L"))
#endif /* libasmP.h */
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index aa3e5ee2..b5462ef4 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwarf_begin_elf.c (check_section): Use startswith.
+
2021-05-01 Mark Wielaard <mark@klomp.org>
* libdw_form.c (__libdw_form_val_compute_len): Check indirect
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 757ac4fa..9e944b86 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
@@ -138,7 +140,7 @@ check_section (Dwarf *result, size_t shstrndx, Elf_Scn *scn, bool inscngrp)
break;
}
else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
- && strncmp (scnname, ".gnu.debuglto_", 14) == 0
+ && startswith (scnname, ".gnu.debuglto_")
&& strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
break;
}
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d107e78f..fedf65a4 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,13 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwfl_frame.c (dwfl_attach_state): Use startswith.
+ * dwfl_module_getdwarf.c (find_symtab): Likewise.
+ * linux-kernel-modules.c: Likewise.
+ * linux-pid-attach.c (linux_proc_pid_is_stopped): Likewise.
+ (dwfl_linux_proc_attach): Likewise.
+ * relocate.c (resolve_symbol): Likewise.
+ (relocate_section): Likewise.
+
2021-02-01 Érico Nogueira <ericonr@disroot.org>
* dwfl_error.c (strerror_r): Only use the GNU version when available.
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index 5bbf850e..77e0c5cb 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libdwflP.h"
#include <unistd.h>
@@ -172,7 +174,7 @@ dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid,
is called from dwfl_linux_proc_attach with elf == NULL.
__libdwfl_module_getebl will call __libdwfl_getelf which
will call the find_elf callback. */
- if (strncmp (mod->name, "[vdso: ", 7) == 0
+ if (startswith (mod->name, "[vdso: ")
|| strcmp (strrchr (mod->name, ' ') ?: "",
" (deleted)") == 0)
continue;
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 2f3dd0dd..6f076057 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -1162,7 +1162,7 @@ find_symtab (Dwfl_Module *mod)
if (sname == NULL)
goto elferr;
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
/* Try to uncompress, but it might already have been, an error
might just indicate, already uncompressed. */
elf_compress_gnu (symstrscn, 0, 0);
@@ -1245,7 +1245,7 @@ find_symtab (Dwfl_Module *mod)
if (sname == NULL)
goto elferr;
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
/* Try to uncompress, but it might already have been, an error
might just indicate, already uncompressed. */
elf_compress_gnu (aux_strscn, 0, 0);
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 6edb27f2..c0f8dfa4 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -924,7 +924,7 @@ dwfl_linux_kernel_module_section_address
if (!strcmp (secname, ".modinfo")
|| !strcmp (secname, ".data.percpu")
- || !strncmp (secname, ".exit", 5))
+ || startswith (secname, ".exit"))
{
*addr = (Dwarf_Addr) -1l;
return DWARF_CB_OK;
@@ -935,7 +935,7 @@ dwfl_linux_kernel_module_section_address
behavior, and this cruft leaks out into the /sys information.
The file name for ".init*" may actually look like "_init*". */
- const bool is_init = !strncmp (secname, ".init", 5);
+ const bool is_init = startswith (secname, ".init");
if (is_init)
{
if (asprintf (&sysfile, SECADDRDIRFMT "_%s",
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index fdf5c9b1..cd534825 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libelfP.h"
#include "libdwflP.h"
#include <sys/types.h>
@@ -59,7 +61,7 @@ linux_proc_pid_is_stopped (pid_t pid)
have_state = false;
while (fgets (buffer, sizeof (buffer), procfile) != NULL)
- if (strncmp (buffer, "State:", 6) == 0)
+ if (startswith (buffer, "State:"))
{
have_state = true;
break;
@@ -407,7 +409,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped)
char *line = NULL;
size_t linelen = 0;
while (getline (&line, &linelen, procfile) >= 0)
- if (strncmp (line, "Tgid:", 5) == 0)
+ if (startswith (line, "Tgid:"))
{
errno = 0;
char *endptr;
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 88b5211d..0497bd4f 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libelfP.h"
#include "libdwflP.h"
@@ -237,7 +239,7 @@ resolve_symbol (Dwfl_Module *referer, struct reloc_symtab_cache *symtab,
return DWFL_E_LIBELF;
/* If the section is already decompressed, that isn't an error. */
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
elf_compress_gnu (scn, 0, 0);
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -518,7 +520,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
Nothing to do here. */
return DWFL_E_NOERROR;
- if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (tname, ".zdebug"))
elf_compress_gnu (tscn, 0, 0);
if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -539,7 +541,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
if (sname == NULL)
return DWFL_E_LIBELF;
- if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
elf_compress_gnu (scn, 0, 0);
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 33208f0d..fff66b3e 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * eblobjnotetypename.c (ebl_object_note_type_name): Use startswith.
+ * eblopenbackend.c (default_debugscn_p): Likewise.
+
2020-12-16 Dmitry V. Levin <ldv@altlinux.org>
* libeblP.h (_): Remove.
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 9daddcda..4662906d 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -31,6 +31,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
@@ -79,8 +81,7 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
}
}
- if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
- strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
+ if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
{
/* GNU Build Attribute notes (ab)use the owner name to store
most of their data. Don't decode everything here. Just
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index a8af1658..71fafed7 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -616,9 +616,9 @@ default_debugscn_p (const char *name)
/ sizeof (dwarf_scn_names[0]));
for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
if (strcmp (name, dwarf_scn_names[cnt]) == 0
- || (strncmp (name, ".zdebug", strlen (".zdebug")) == 0
+ || (startswith (name, ".zdebug")
&& strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0)
- || (strncmp (name, ".gnu.debuglto_", strlen (".gnu.debuglto_")) == 0
+ || (startswith (name, ".gnu.debuglto_")
&& strcmp (&name[14], dwarf_scn_names[cnt]) == 0))
return true;
diff --git a/src/ChangeLog b/src/ChangeLog
index 0cea28e2..c5ecc05b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * elfclassify.c (run_classify): Use startswith.
+ * elfcompress.c (process_file): Likewise.
+ * nm.c (show_symbols_sysv): Likewise.
+ * readelf.c (print_debug): Likewise.
+ (handle_notes_data): Likewise.
+ (dump_data_section): Likewise.
+ (print_string_section): Likewise.
+ * strip.c (remove_debug_relocations): Likewise.
+
2021-04-03 Mark Wielaard <mark@klomp.org>
* nm.c (show_symbols): close dwfl_fd if dwfl_begin fails.
diff --git a/src/elfclassify.c b/src/elfclassify.c
index ae626bb1..fe7eeeed 100644
--- a/src/elfclassify.c
+++ b/src/elfclassify.c
@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
+#include <system.h>
#include <argp.h>
#include <error.h>
@@ -335,11 +336,8 @@ run_classify (void)
stderr);
has_bits_alloc = true;
}
- const char *debug_prefix = ".debug_";
- const char *zdebug_prefix = ".zdebug_";
- if (strncmp (section_name, debug_prefix, strlen (debug_prefix)) == 0
- || strncmp (section_name, zdebug_prefix,
- strlen (zdebug_prefix)) == 0)
+ if (startswith (section_name, ".debug_")
+ || startswith (section_name, ".zdebug_"))
{
if (verbose > 1 && !has_debug_sections)
fputs ("debug: .debug_* section found\n", stderr);
diff --git a/src/elfcompress.c b/src/elfcompress.c
index c5ba6c34..d5bc3300 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -448,7 +448,7 @@ process_file (const char *fname)
{
if (!force && type == T_DECOMPRESS
&& (shdr->sh_flags & SHF_COMPRESSED) == 0
- && strncmp (sname, ".zdebug", strlen (".zdebug")) != 0)
+ && !startswith (sname, ".zdebug"))
{
if (verbose > 0)
printf ("[%zd] %s already decompressed\n", ndx, sname);
@@ -460,7 +460,7 @@ process_file (const char *fname)
printf ("[%zd] %s already compressed\n", ndx, sname);
}
else if (!force && type == T_COMPRESS_GNU
- && strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ && startswith (sname, ".zdebug"))
{
if (verbose > 0)
printf ("[%zd] %s already GNU compressed\n", ndx, sname);
@@ -472,11 +472,9 @@ process_file (const char *fname)
/* Check if we might want to change this section name. */
if (! adjust_names
&& ((type != T_COMPRESS_GNU
- && strncmp (sname, ".zdebug",
- strlen (".zdebug")) == 0)
+ && startswith (sname, ".zdebug"))
|| (type == T_COMPRESS_GNU
- && strncmp (sname, ".debug",
- strlen (".debug")) == 0)))
+ && startswith (sname, ".debug"))))
adjust_names = true;
/* We need a buffer this large if we change the names. */
@@ -696,7 +694,7 @@ process_file (const char *fname)
false, false, verbose > 0) < 0)
goto cleanup;
}
- else if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (sname, ".zdebug"))
{
snamebuf[0] = '.';
strcpy (&snamebuf[1], &sname[2]);
@@ -710,7 +708,7 @@ process_file (const char *fname)
break;
case T_COMPRESS_GNU:
- if (strncmp (sname, ".debug", strlen (".debug")) == 0)
+ if (startswith (sname, ".debug"))
{
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
{
@@ -757,7 +755,7 @@ process_file (const char *fname)
}
else if (verbose >= 0)
{
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
printf ("[%zd] %s unchanged, already GNU compressed",
ndx, sname);
else
@@ -769,7 +767,7 @@ process_file (const char *fname)
case T_COMPRESS_ZLIB:
if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
{
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
/* First decompress to recompress zlib style.
Don't report even when verbose. */
@@ -900,7 +898,7 @@ process_file (const char *fname)
symtab_size = size;
symtab_compressed = T_COMPRESS_ZLIB;
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
/* Don't report the (internal) uncompression. */
if (compress_section (newscn, size, sname, NULL, ndx,
@@ -1046,7 +1044,7 @@ process_file (const char *fname)
shstrtab_size = shdr->sh_size;
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
shstrtab_compressed = T_COMPRESS_ZLIB;
- else if (strncmp (shstrtab_name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (shstrtab_name, ".zdebug"))
shstrtab_compressed = T_COMPRESS_GNU;
}
@@ -1187,8 +1185,7 @@ process_file (const char *fname)
symtab_size = shdr->sh_size;
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
symtab_compressed = T_COMPRESS_ZLIB;
- else if (strncmp (symtab_name, ".zdebug",
- strlen (".zdebug")) == 0)
+ else if (startswith (symtab_name, ".zdebug"))
symtab_compressed = T_COMPRESS_GNU;
}
diff --git a/src/nm.c b/src/nm.c
index dc2186db..b99805e8 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -858,7 +858,7 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname,
bind = ebl_symbol_binding_name (ebl,
GELF_ST_BIND (syms[cnt].sym.st_info),
symbindbuf, sizeof (symbindbuf));
- if (bind != NULL && strncmp (bind, "GNU_", strlen ("GNU_")) == 0)
+ if (bind != NULL && startswith (bind, "GNU_"))
bind += strlen ("GNU_");
printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n",
longest_name, symstr, addressbuf, bind,
diff --git a/src/readelf.c b/src/readelf.c
index b9740455..9b472622 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1335,7 +1335,7 @@ There are %zd section headers, starting at offset %#" PRIx64 ":\n\
_("bad compression header for section %zd: %s"),
elf_ndxscn (scn), elf_errmsg (-1));
}
- else if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ else if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) >= 0)
@@ -11451,7 +11451,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
|| (scnlen == dbglen + 5
&& strstr (name, ".dwo") == name + dbglen + 1)))
|| (scnlen > 14 /* .gnu.debuglto_ prefix. */
- && strncmp (name, ".gnu.debuglto_", 14) == 0
+ && startswith (name, ".gnu.debuglto_")
&& strcmp (&name[14], debug_sections[n].name) == 0)
)
{
@@ -12455,8 +12455,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
into the owner name field. Extract just the owner name
prefix here, then use the rest later as data. */
bool is_gnu_build_attr
- = strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
- strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0;
+ = startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX);
const char *print_name = (is_gnu_build_attr
? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name);
size_t print_namesz = (is_gnu_build_attr
@@ -12636,7 +12635,7 @@ dump_data_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
_("Couldn't uncompress section"),
elf_ndxscn (scn));
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
if (elf_compress_gnu (scn, 0, 0) < 0)
printf ("WARNING: %s [%zd]\n",
@@ -12687,7 +12686,7 @@ print_string_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
_("Couldn't uncompress section"),
elf_ndxscn (scn));
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
if (elf_compress_gnu (scn, 0, 0) < 0)
printf ("WARNING: %s [%zd]\n",
diff --git a/src/strip.c b/src/strip.c
index 7a5d4e4c..70fc8c03 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -607,7 +607,7 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
GElf_Chdr tchdr;
int tcompress_type = 0;
bool is_gnu_compressed = false;
- if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (tname, ".zdebug"))
{
is_gnu_compressed = true;
if (elf_compress_gnu (tscn, 0, 0) != 1)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 35fb2b2c..4951e14f 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwelf_elf_e_machine_string.c (main): Use startswith.
+ * dwelfgnucompressed.c (main): Likewise.
+ * elfgetchdr.c (main): Likewise.
+ * elfputzdata.c (main): Likewise.
+ * vdsosyms.c (module_callback): Likewise.
+
2021-05-04 Alice Zhang <alizhang@redhat.com>
* run-debuginfod-find.sh: Added tests for negative cache files.
diff --git a/tests/dwelf_elf_e_machine_string.c b/tests/dwelf_elf_e_machine_string.c
index afad1058..30599c36 100644
--- a/tests/dwelf_elf_e_machine_string.c
+++ b/tests/dwelf_elf_e_machine_string.c
@@ -19,6 +19,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
@@ -41,7 +43,7 @@ main (int argc, char **argv)
const char *machine;
errno = 0;
- if (strncmp ("0x", argv[i], 2) == 0)
+ if (startswith (argv[i], "0x"))
val = strtol (&argv[i][2], NULL, 16);
else
val = strtol (argv[i], NULL, 10);
diff --git a/tests/dwelfgnucompressed.c b/tests/dwelfgnucompressed.c
index 0132271c..447f3d59 100644
--- a/tests/dwelfgnucompressed.c
+++ b/tests/dwelfgnucompressed.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -82,7 +84,7 @@ main (int argc, char *argv[])
break;
}
- if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfgetchdr.c b/tests/elfgetchdr.c
index 44ba1789..171c4df8 100644
--- a/tests/elfgetchdr.c
+++ b/tests/elfgetchdr.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -99,7 +101,7 @@ main (int argc, char *argv[])
}
/* This duplicates what the dwelfgnucompressed testcase does. */
- if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfputzdata.c b/tests/elfputzdata.c
index 0d9c020e..0ff363f9 100644
--- a/tests/elfputzdata.c
+++ b/tests/elfputzdata.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -83,7 +85,7 @@ main (int argc, char *argv[])
printf ("Cannot compress %zd %s\n", idx, name);
}
else if ((shdr->sh_flags & SHF_COMPRESSED) != 0
- || strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ || startswith (name, ".zdebug"))
{
printf ("Already compressed %zd %s\n", idx, name);
}
diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c
index 83ab034f..ff1a18a8 100644
--- a/tests/vdsosyms.c
+++ b/tests/vdsosyms.c
@@ -43,7 +43,7 @@ module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)),
{
/* We can only recognize the vdso by inspecting the "magic name". */
printf ("module name: %s\n", name);
- if (strncmp ("[vdso: ", name, 7) == 0)
+ if (startswith (name, "[vdso: "))
{
vdso_syms = dwfl_module_getsymtab (mod);
printf ("vdso syms: %d\n", vdso_syms);