summaryrefslogtreecommitdiffstats
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
parentelfutils.spec: Add procps as a %check BuildRequires:. (diff)
downloadelfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.gz
elfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.bz2
elfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.xz
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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * aarch64_symbol.c (aarch64_data_marker_symbol): Use startswith.
4 * arm_symbol.c (arm_data_marker_symbol): Likewise.
5
12021-02-01 Érico Nogueira <ericonr@disroot.org> 62021-02-01 Érico Nogueira <ericonr@disroot.org>
2 7
3 * ppc_initreg.c: Also include <asm/ptrace.h>. 8 * 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include <elf.h> 35#include <elf.h>
34#include <stddef.h> 36#include <stddef.h>
35#include <string.h> 37#include <string.h>
@@ -104,7 +106,7 @@ aarch64_data_marker_symbol (const GElf_Sym *sym, const char *sname)
104 return (sym != NULL && sname != NULL 106 return (sym != NULL && sname != NULL
105 && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL 107 && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
106 && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE 108 && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
107 && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0)); 109 && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
108} 110}
109 111
110const char * 112const 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include <elf.h> 35#include <elf.h>
34#include <stddef.h> 36#include <stddef.h>
35#include <string.h> 37#include <string.h>
@@ -154,5 +156,5 @@ arm_data_marker_symbol (const GElf_Sym *sym, const char *sname)
154 return (sym != NULL && sname != NULL 156 return (sym != NULL && sname != NULL
155 && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL 157 && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
156 && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE 158 && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
157 && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0)); 159 && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
158} 160}
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 97f598f6..249385b6 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,9 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * debuginfod-client.c (debuginfod_query_server): Use startswith.
4 (debuginfod_add_http_header): Likewise.
5 * debuginfod.cxx: Likewise.
6
12021-05-04 Alice Zhang <alizhang@redhat.com> 72021-05-04 Alice Zhang <alizhang@redhat.com>
2 8
3 * debuginfod-client.c (cache_miss_default_s): New static time_t, 9 * 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,
1054 &scheme); 1054 &scheme);
1055 if(ok3 == CURLE_OK && scheme) 1055 if(ok3 == CURLE_OK && scheme)
1056 { 1056 {
1057 if (strncmp (scheme, "HTTP", 4) == 0) 1057 if (startswith (scheme, "HTTP"))
1058 if (resp_code == 200) 1058 if (resp_code == 200)
1059 { 1059 {
1060 verified_handle = msg->easy_handle; 1060 verified_handle = msg->easy_handle;
@@ -1318,7 +1318,7 @@ int debuginfod_add_http_header (debuginfod_client *client, const char* header)
1318 1318
1319 /* Track if User-Agent: is being set. If so, signal not to add the 1319 /* Track if User-Agent: is being set. If so, signal not to add the
1320 default one. */ 1320 default one. */
1321 if (strncmp (header, "User-Agent:", 11) == 0) 1321 if (startswith (header, "User-Agent:"))
1322 client->user_agent_set_p = 1; 1322 client->user_agent_set_p = 1;
1323 1323
1324 client->headers = temp; 1324 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" {
37 37
38#include "debuginfod.h" 38#include "debuginfod.h"
39#include <dwarf.h> 39#include <dwarf.h>
40#include <system.h>
40 41
41#include <argp.h> 42#include <argp.h>
42#ifdef __GNUC__ 43#ifdef __GNUC__
@@ -2323,15 +2324,15 @@ elf_classify (int fd, bool &executable_p, bool &debuginfo_p, string &buildid, se
2323 const char *section_name = elf_strptr (elf, shstrndx, shdr->sh_name); 2324 const char *section_name = elf_strptr (elf, shstrndx, shdr->sh_name);
2324 if (section_name == NULL) 2325 if (section_name == NULL)
2325 break; 2326 break;
2326 if (strncmp(section_name, ".debug_line", 11) == 0 || 2327 if (startswith (section_name, ".debug_line") ||
2327 strncmp(section_name, ".zdebug_line", 12) == 0) 2328 startswith (section_name, ".zdebug_line"))
2328 { 2329 {
2329 debuginfo_p = true; 2330 debuginfo_p = true;
2330 dwarf_extract_source_paths (elf, debug_sourcefiles); 2331 dwarf_extract_source_paths (elf, debug_sourcefiles);
2331 break; // expecting only one .*debug_line, so no need to look for others 2332 break; // expecting only one .*debug_line, so no need to look for others
2332 } 2333 }
2333 else if (strncmp(section_name, ".debug_", 7) == 0 || 2334 else if (startswith (section_name, ".debug_") ||
2334 strncmp(section_name, ".zdebug_", 8) == 0) 2335 startswith (section_name, ".zdebug_"))
2335 { 2336 {
2336 debuginfo_p = true; 2337 debuginfo_p = true;
2337 // NB: don't break; need to parse .debug_line for sources 2338 // 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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * system.h (startswith): New function.
4 (pwrite_retry): Cast to char *.
5 (write_retry): Likewise.
6 (pread_retry): Likewise.
7
12021-02-05 Mark Wielaard <mark@klomp.org> 82021-02-05 Mark Wielaard <mark@klomp.org>
2 9
3 * printversion.c (print_version): Update copyright year. 10 * 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 @@
37#include <endian.h> 37#include <endian.h>
38#include <byteswap.h> 38#include <byteswap.h>
39#include <unistd.h> 39#include <unistd.h>
40#include <string.h>
40 41
41#if __BYTE_ORDER == __LITTLE_ENDIAN 42#if __BYTE_ORDER == __LITTLE_ENDIAN
42# define LE32(n) (n) 43# define LE32(n) (n)
@@ -69,6 +70,14 @@
69 ((void *) ((char *) memcpy (dest, src, n) + (size_t) n)) 70 ((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
70#endif 71#endif
71 72
73/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */
74
75static inline int
76startswith (const char *str, const char *prefix)
77{
78 return strncmp (str, prefix, strlen (prefix)) == 0;
79}
80
72/* A special gettext function we use if the strings are too short. */ 81/* A special gettext function we use if the strings are too short. */
73#define sgettext(Str) \ 82#define sgettext(Str) \
74 ({ const char *__res = strrchr (_(Str), '|'); \ 83 ({ const char *__res = strrchr (_(Str), '|'); \
@@ -104,7 +113,7 @@ pwrite_retry (int fd, const void *buf, size_t len, off_t off)
104 113
105 do 114 do
106 { 115 {
107 ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd, 116 ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
108 off + recvd)); 117 off + recvd));
109 if (ret <= 0) 118 if (ret <= 0)
110 return ret < 0 ? ret : recvd; 119 return ret < 0 ? ret : recvd;
@@ -123,7 +132,7 @@ write_retry (int fd, const void *buf, size_t len)
123 132
124 do 133 do
125 { 134 {
126 ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd)); 135 ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
127 if (ret <= 0) 136 if (ret <= 0)
128 return ret < 0 ? ret : recvd; 137 return ret < 0 ? ret : recvd;
129 138
@@ -141,7 +150,7 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
141 150
142 do 151 do
143 { 152 {
144 ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd, 153 ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
145 off + recvd)); 154 off + recvd));
146 if (ret <= 0) 155 if (ret <= 0)
147 return ret < 0 ? ret : recvd; 156 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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * libasmP.h (asm_emit_symbol_p): Use startswith.
4
12020-12-16 Dmitry V. Levin <ldv@altlinux.org> 52020-12-16 Dmitry V. Levin <ldv@altlinux.org>
2 6
3 * libasmP.h (_): Remove. 7 * 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,
302// XXX The second part should probably be controlled by an option which 302// XXX The second part should probably be controlled by an option which
303// isn't implemented yet 303// isn't implemented yet
304// XXX Also, the format will change with the backend. 304// XXX Also, the format will change with the backend.
305#define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0) 305#define asm_emit_symbol_p(name) (!startswith (name, ".L"))
306 306
307#endif /* libasmP.h */ 307#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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * dwarf_begin_elf.c (check_section): Use startswith.
4
12021-05-01 Mark Wielaard <mark@klomp.org> 52021-05-01 Mark Wielaard <mark@klomp.org>
2 6
3 * libdw_form.c (__libdw_form_val_compute_len): Check indirect 7 * 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include <assert.h> 35#include <assert.h>
34#include <stdbool.h> 36#include <stdbool.h>
35#include <stddef.h> 37#include <stddef.h>
@@ -138,7 +140,7 @@ check_section (Dwarf *result, size_t shstrndx, Elf_Scn *scn, bool inscngrp)
138 break; 140 break;
139 } 141 }
140 else if (scnlen > 14 /* .gnu.debuglto_ prefix. */ 142 else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
141 && strncmp (scnname, ".gnu.debuglto_", 14) == 0 143 && startswith (scnname, ".gnu.debuglto_")
142 && strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0) 144 && strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
143 break; 145 break;
144 } 146 }
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d107e78f..fedf65a4 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,13 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * dwfl_frame.c (dwfl_attach_state): Use startswith.
4 * dwfl_module_getdwarf.c (find_symtab): Likewise.
5 * linux-kernel-modules.c: Likewise.
6 * linux-pid-attach.c (linux_proc_pid_is_stopped): Likewise.
7 (dwfl_linux_proc_attach): Likewise.
8 * relocate.c (resolve_symbol): Likewise.
9 (relocate_section): Likewise.
10
12021-02-01 Érico Nogueira <ericonr@disroot.org> 112021-02-01 Érico Nogueira <ericonr@disroot.org>
2 12
3 * dwfl_error.c (strerror_r): Only use the GNU version when available. 13 * 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include "libdwflP.h" 35#include "libdwflP.h"
34#include <unistd.h> 36#include <unistd.h>
35 37
@@ -172,7 +174,7 @@ dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid,
172 is called from dwfl_linux_proc_attach with elf == NULL. 174 is called from dwfl_linux_proc_attach with elf == NULL.
173 __libdwfl_module_getebl will call __libdwfl_getelf which 175 __libdwfl_module_getebl will call __libdwfl_getelf which
174 will call the find_elf callback. */ 176 will call the find_elf callback. */
175 if (strncmp (mod->name, "[vdso: ", 7) == 0 177 if (startswith (mod->name, "[vdso: ")
176 || strcmp (strrchr (mod->name, ' ') ?: "", 178 || strcmp (strrchr (mod->name, ' ') ?: "",
177 " (deleted)") == 0) 179 " (deleted)") == 0)
178 continue; 180 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)
1162 if (sname == NULL) 1162 if (sname == NULL)
1163 goto elferr; 1163 goto elferr;
1164 1164
1165 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 1165 if (startswith (sname, ".zdebug"))
1166 /* Try to uncompress, but it might already have been, an error 1166 /* Try to uncompress, but it might already have been, an error
1167 might just indicate, already uncompressed. */ 1167 might just indicate, already uncompressed. */
1168 elf_compress_gnu (symstrscn, 0, 0); 1168 elf_compress_gnu (symstrscn, 0, 0);
@@ -1245,7 +1245,7 @@ find_symtab (Dwfl_Module *mod)
1245 if (sname == NULL) 1245 if (sname == NULL)
1246 goto elferr; 1246 goto elferr;
1247 1247
1248 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 1248 if (startswith (sname, ".zdebug"))
1249 /* Try to uncompress, but it might already have been, an error 1249 /* Try to uncompress, but it might already have been, an error
1250 might just indicate, already uncompressed. */ 1250 might just indicate, already uncompressed. */
1251 elf_compress_gnu (aux_strscn, 0, 0); 1251 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
924 924
925 if (!strcmp (secname, ".modinfo") 925 if (!strcmp (secname, ".modinfo")
926 || !strcmp (secname, ".data.percpu") 926 || !strcmp (secname, ".data.percpu")
927 || !strncmp (secname, ".exit", 5)) 927 || startswith (secname, ".exit"))
928 { 928 {
929 *addr = (Dwarf_Addr) -1l; 929 *addr = (Dwarf_Addr) -1l;
930 return DWARF_CB_OK; 930 return DWARF_CB_OK;
@@ -935,7 +935,7 @@ dwfl_linux_kernel_module_section_address
935 behavior, and this cruft leaks out into the /sys information. 935 behavior, and this cruft leaks out into the /sys information.
936 The file name for ".init*" may actually look like "_init*". */ 936 The file name for ".init*" may actually look like "_init*". */
937 937
938 const bool is_init = !strncmp (secname, ".init", 5); 938 const bool is_init = startswith (secname, ".init");
939 if (is_init) 939 if (is_init)
940 { 940 {
941 if (asprintf (&sysfile, SECADDRDIRFMT "_%s", 941 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include "libelfP.h" 35#include "libelfP.h"
34#include "libdwflP.h" 36#include "libdwflP.h"
35#include <sys/types.h> 37#include <sys/types.h>
@@ -59,7 +61,7 @@ linux_proc_pid_is_stopped (pid_t pid)
59 61
60 have_state = false; 62 have_state = false;
61 while (fgets (buffer, sizeof (buffer), procfile) != NULL) 63 while (fgets (buffer, sizeof (buffer), procfile) != NULL)
62 if (strncmp (buffer, "State:", 6) == 0) 64 if (startswith (buffer, "State:"))
63 { 65 {
64 have_state = true; 66 have_state = true;
65 break; 67 break;
@@ -407,7 +409,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped)
407 char *line = NULL; 409 char *line = NULL;
408 size_t linelen = 0; 410 size_t linelen = 0;
409 while (getline (&line, &linelen, procfile) >= 0) 411 while (getline (&line, &linelen, procfile) >= 0)
410 if (strncmp (line, "Tgid:", 5) == 0) 412 if (startswith (line, "Tgid:"))
411 { 413 {
412 errno = 0; 414 errno = 0;
413 char *endptr; 415 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 @@
30# include <config.h> 30# include <config.h>
31#endif 31#endif
32 32
33#include <system.h>
34
33#include "libelfP.h" 35#include "libelfP.h"
34#include "libdwflP.h" 36#include "libdwflP.h"
35 37
@@ -237,7 +239,7 @@ resolve_symbol (Dwfl_Module *referer, struct reloc_symtab_cache *symtab,
237 return DWFL_E_LIBELF; 239 return DWFL_E_LIBELF;
238 240
239 /* If the section is already decompressed, that isn't an error. */ 241 /* If the section is already decompressed, that isn't an error. */
240 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 242 if (startswith (sname, ".zdebug"))
241 elf_compress_gnu (scn, 0, 0); 243 elf_compress_gnu (scn, 0, 0);
242 244
243 if ((shdr->sh_flags & SHF_COMPRESSED) != 0) 245 if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -518,7 +520,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
518 Nothing to do here. */ 520 Nothing to do here. */
519 return DWFL_E_NOERROR; 521 return DWFL_E_NOERROR;
520 522
521 if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0) 523 if (startswith (tname, ".zdebug"))
522 elf_compress_gnu (tscn, 0, 0); 524 elf_compress_gnu (tscn, 0, 0);
523 525
524 if ((tshdr->sh_flags & SHF_COMPRESSED) != 0) 526 if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -539,7 +541,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
539 if (sname == NULL) 541 if (sname == NULL)
540 return DWFL_E_LIBELF; 542 return DWFL_E_LIBELF;
541 543
542 if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0) 544 if (startswith (sname, ".zdebug"))
543 elf_compress_gnu (scn, 0, 0); 545 elf_compress_gnu (scn, 0, 0);
544 546
545 if ((shdr->sh_flags & SHF_COMPRESSED) != 0) 547 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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * eblobjnotetypename.c (ebl_object_note_type_name): Use startswith.
4 * eblopenbackend.c (default_debugscn_p): Likewise.
5
12020-12-16 Dmitry V. Levin <ldv@altlinux.org> 62020-12-16 Dmitry V. Levin <ldv@altlinux.org>
2 7
3 * libeblP.h (_): Remove. 8 * 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 @@
31# include <config.h> 31# include <config.h>
32#endif 32#endif
33 33
34#include <system.h>
35
34#include <inttypes.h> 36#include <inttypes.h>
35#include <stdio.h> 37#include <stdio.h>
36#include <string.h> 38#include <string.h>
@@ -79,8 +81,7 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
79 } 81 }
80 } 82 }
81 83
82 if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX, 84 if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
83 strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
84 { 85 {
85 /* GNU Build Attribute notes (ab)use the owner name to store 86 /* GNU Build Attribute notes (ab)use the owner name to store
86 most of their data. Don't decode everything here. Just 87 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)
616 / sizeof (dwarf_scn_names[0])); 616 / sizeof (dwarf_scn_names[0]));
617 for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt) 617 for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
618 if (strcmp (name, dwarf_scn_names[cnt]) == 0 618 if (strcmp (name, dwarf_scn_names[cnt]) == 0
619 || (strncmp (name, ".zdebug", strlen (".zdebug")) == 0 619 || (startswith (name, ".zdebug")
620 && strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0) 620 && strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0)
621 || (strncmp (name, ".gnu.debuglto_", strlen (".gnu.debuglto_")) == 0 621 || (startswith (name, ".gnu.debuglto_")
622 && strcmp (&name[14], dwarf_scn_names[cnt]) == 0)) 622 && strcmp (&name[14], dwarf_scn_names[cnt]) == 0))
623 return true; 623 return true;
624 624
diff --git a/src/ChangeLog b/src/ChangeLog
index 0cea28e2..c5ecc05b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * elfclassify.c (run_classify): Use startswith.
4 * elfcompress.c (process_file): Likewise.
5 * nm.c (show_symbols_sysv): Likewise.
6 * readelf.c (print_debug): Likewise.
7 (handle_notes_data): Likewise.
8 (dump_data_section): Likewise.
9 (print_string_section): Likewise.
10 * strip.c (remove_debug_relocations): Likewise.
11
12021-04-03 Mark Wielaard <mark@klomp.org> 122021-04-03 Mark Wielaard <mark@klomp.org>
2 13
3 * nm.c (show_symbols): close dwfl_fd if dwfl_begin fails. 14 * 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 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19#include <system.h>
19 20
20#include <argp.h> 21#include <argp.h>
21#include <error.h> 22#include <error.h>
@@ -335,11 +336,8 @@ run_classify (void)
335 stderr); 336 stderr);
336 has_bits_alloc = true; 337 has_bits_alloc = true;
337 } 338 }
338 const char *debug_prefix = ".debug_"; 339 if (startswith (section_name, ".debug_")
339 const char *zdebug_prefix = ".zdebug_"; 340 || startswith (section_name, ".zdebug_"))
340 if (strncmp (section_name, debug_prefix, strlen (debug_prefix)) == 0
341 || strncmp (section_name, zdebug_prefix,
342 strlen (zdebug_prefix)) == 0)
343 { 341 {
344 if (verbose > 1 && !has_debug_sections) 342 if (verbose > 1 && !has_debug_sections)
345 fputs ("debug: .debug_* section found\n", stderr); 343 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)
448 { 448 {
449 if (!force && type == T_DECOMPRESS 449 if (!force && type == T_DECOMPRESS
450 && (shdr->sh_flags & SHF_COMPRESSED) == 0 450 && (shdr->sh_flags & SHF_COMPRESSED) == 0
451 && strncmp (sname, ".zdebug", strlen (".zdebug")) != 0) 451 && !startswith (sname, ".zdebug"))
452 { 452 {
453 if (verbose > 0) 453 if (verbose > 0)
454 printf ("[%zd] %s already decompressed\n", ndx, sname); 454 printf ("[%zd] %s already decompressed\n", ndx, sname);
@@ -460,7 +460,7 @@ process_file (const char *fname)
460 printf ("[%zd] %s already compressed\n", ndx, sname); 460 printf ("[%zd] %s already compressed\n", ndx, sname);
461 } 461 }
462 else if (!force && type == T_COMPRESS_GNU 462 else if (!force && type == T_COMPRESS_GNU
463 && strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 463 && startswith (sname, ".zdebug"))
464 { 464 {
465 if (verbose > 0) 465 if (verbose > 0)
466 printf ("[%zd] %s already GNU compressed\n", ndx, sname); 466 printf ("[%zd] %s already GNU compressed\n", ndx, sname);
@@ -472,11 +472,9 @@ process_file (const char *fname)
472 /* Check if we might want to change this section name. */ 472 /* Check if we might want to change this section name. */
473 if (! adjust_names 473 if (! adjust_names
474 && ((type != T_COMPRESS_GNU 474 && ((type != T_COMPRESS_GNU
475 && strncmp (sname, ".zdebug", 475 && startswith (sname, ".zdebug"))
476 strlen (".zdebug")) == 0)
477 || (type == T_COMPRESS_GNU 476 || (type == T_COMPRESS_GNU
478 && strncmp (sname, ".debug", 477 && startswith (sname, ".debug"))))
479 strlen (".debug")) == 0)))
480 adjust_names = true; 478 adjust_names = true;
481 479
482 /* We need a buffer this large if we change the names. */ 480 /* We need a buffer this large if we change the names. */
@@ -696,7 +694,7 @@ process_file (const char *fname)
696 false, false, verbose > 0) < 0) 694 false, false, verbose > 0) < 0)
697 goto cleanup; 695 goto cleanup;
698 } 696 }
699 else if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 697 else if (startswith (sname, ".zdebug"))
700 { 698 {
701 snamebuf[0] = '.'; 699 snamebuf[0] = '.';
702 strcpy (&snamebuf[1], &sname[2]); 700 strcpy (&snamebuf[1], &sname[2]);
@@ -710,7 +708,7 @@ process_file (const char *fname)
710 break; 708 break;
711 709
712 case T_COMPRESS_GNU: 710 case T_COMPRESS_GNU:
713 if (strncmp (sname, ".debug", strlen (".debug")) == 0) 711 if (startswith (sname, ".debug"))
714 { 712 {
715 if ((shdr->sh_flags & SHF_COMPRESSED) != 0) 713 if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
716 { 714 {
@@ -757,7 +755,7 @@ process_file (const char *fname)
757 } 755 }
758 else if (verbose >= 0) 756 else if (verbose >= 0)
759 { 757 {
760 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 758 if (startswith (sname, ".zdebug"))
761 printf ("[%zd] %s unchanged, already GNU compressed", 759 printf ("[%zd] %s unchanged, already GNU compressed",
762 ndx, sname); 760 ndx, sname);
763 else 761 else
@@ -769,7 +767,7 @@ process_file (const char *fname)
769 case T_COMPRESS_ZLIB: 767 case T_COMPRESS_ZLIB:
770 if ((shdr->sh_flags & SHF_COMPRESSED) == 0) 768 if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
771 { 769 {
772 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) 770 if (startswith (sname, ".zdebug"))
773 { 771 {
774 /* First decompress to recompress zlib style. 772 /* First decompress to recompress zlib style.
775 Don't report even when verbose. */ 773 Don't report even when verbose. */
@@ -900,7 +898,7 @@ process_file (const char *fname)
900 symtab_size = size; 898 symtab_size = size;
901 symtab_compressed = T_COMPRESS_ZLIB; 899 symtab_compressed = T_COMPRESS_ZLIB;
902 } 900 }
903 else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0) 901 else if (startswith (name, ".zdebug"))
904 { 902 {
905 /* Don't report the (internal) uncompression. */ 903 /* Don't report the (internal) uncompression. */
906 if (compress_section (newscn, size, sname, NULL, ndx, 904 if (compress_section (newscn, size, sname, NULL, ndx,
@@ -1046,7 +1044,7 @@ process_file (const char *fname)
1046 shstrtab_size = shdr->sh_size; 1044 shstrtab_size = shdr->sh_size;
1047 if ((shdr->sh_flags & SHF_COMPRESSED) != 0) 1045 if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
1048 shstrtab_compressed = T_COMPRESS_ZLIB; 1046 shstrtab_compressed = T_COMPRESS_ZLIB;
1049 else if (strncmp (shstrtab_name, ".zdebug", strlen (".zdebug")) == 0) 1047 else if (startswith (shstrtab_name, ".zdebug"))
1050 shstrtab_compressed = T_COMPRESS_GNU; 1048 shstrtab_compressed = T_COMPRESS_GNU;
1051 } 1049 }
1052 1050
@@ -1187,8 +1185,7 @@ process_file (const char *fname)
1187 symtab_size = shdr->sh_size; 1185 symtab_size = shdr->sh_size;
1188 if ((shdr->sh_flags & SHF_COMPRESSED) != 0) 1186 if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
1189 symtab_compressed = T_COMPRESS_ZLIB; 1187 symtab_compressed = T_COMPRESS_ZLIB;
1190 else if (strncmp (symtab_name, ".zdebug", 1188 else if (startswith (symtab_name, ".zdebug"))
1191 strlen (".zdebug")) == 0)
1192 symtab_compressed = T_COMPRESS_GNU; 1189 symtab_compressed = T_COMPRESS_GNU;
1193 } 1190 }
1194 1191
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,
858 bind = ebl_symbol_binding_name (ebl, 858 bind = ebl_symbol_binding_name (ebl,
859 GELF_ST_BIND (syms[cnt].sym.st_info), 859 GELF_ST_BIND (syms[cnt].sym.st_info),
860 symbindbuf, sizeof (symbindbuf)); 860 symbindbuf, sizeof (symbindbuf));
861 if (bind != NULL && strncmp (bind, "GNU_", strlen ("GNU_")) == 0) 861 if (bind != NULL && startswith (bind, "GNU_"))
862 bind += strlen ("GNU_"); 862 bind += strlen ("GNU_");
863 printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n", 863 printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n",
864 longest_name, symstr, addressbuf, bind, 864 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\
1335 _("bad compression header for section %zd: %s"), 1335 _("bad compression header for section %zd: %s"),
1336 elf_ndxscn (scn), elf_errmsg (-1)); 1336 elf_ndxscn (scn), elf_errmsg (-1));
1337 } 1337 }
1338 else if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0) 1338 else if (startswith (sname, ".zdebug"))
1339 { 1339 {
1340 ssize_t size; 1340 ssize_t size;
1341 if ((size = dwelf_scn_gnu_compressed_size (scn)) >= 0) 1341 if ((size = dwelf_scn_gnu_compressed_size (scn)) >= 0)
@@ -11451,7 +11451,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
11451 || (scnlen == dbglen + 5 11451 || (scnlen == dbglen + 5
11452 && strstr (name, ".dwo") == name + dbglen + 1))) 11452 && strstr (name, ".dwo") == name + dbglen + 1)))
11453 || (scnlen > 14 /* .gnu.debuglto_ prefix. */ 11453 || (scnlen > 14 /* .gnu.debuglto_ prefix. */
11454 && strncmp (name, ".gnu.debuglto_", 14) == 0 11454 && startswith (name, ".gnu.debuglto_")
11455 && strcmp (&name[14], debug_sections[n].name) == 0) 11455 && strcmp (&name[14], debug_sections[n].name) == 0)
11456) 11456)
11457 { 11457 {
@@ -12455,8 +12455,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
12455 into the owner name field. Extract just the owner name 12455 into the owner name field. Extract just the owner name
12456 prefix here, then use the rest later as data. */ 12456 prefix here, then use the rest later as data. */
12457 bool is_gnu_build_attr 12457 bool is_gnu_build_attr
12458 = strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX, 12458 = startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX);
12459 strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0;
12460 const char *print_name = (is_gnu_build_attr 12459 const char *print_name = (is_gnu_build_attr
12461 ? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name); 12460 ? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name);
12462 size_t print_namesz = (is_gnu_build_attr 12461 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)
12636 _("Couldn't uncompress section"), 12635 _("Couldn't uncompress section"),
12637 elf_ndxscn (scn)); 12636 elf_ndxscn (scn));
12638 } 12637 }
12639 else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0) 12638 else if (startswith (name, ".zdebug"))
12640 { 12639 {
12641 if (elf_compress_gnu (scn, 0, 0) < 0) 12640 if (elf_compress_gnu (scn, 0, 0) < 0)
12642 printf ("WARNING: %s [%zd]\n", 12641 printf ("WARNING: %s [%zd]\n",
@@ -12687,7 +12686,7 @@ print_string_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
12687 _("Couldn't uncompress section"), 12686 _("Couldn't uncompress section"),
12688 elf_ndxscn (scn)); 12687 elf_ndxscn (scn));
12689 } 12688 }
12690 else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0) 12689 else if (startswith (name, ".zdebug"))
12691 { 12690 {
12692 if (elf_compress_gnu (scn, 0, 0) < 0) 12691 if (elf_compress_gnu (scn, 0, 0) < 0)
12693 printf ("WARNING: %s [%zd]\n", 12692 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,
607 GElf_Chdr tchdr; 607 GElf_Chdr tchdr;
608 int tcompress_type = 0; 608 int tcompress_type = 0;
609 bool is_gnu_compressed = false; 609 bool is_gnu_compressed = false;
610 if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0) 610 if (startswith (tname, ".zdebug"))
611 { 611 {
612 is_gnu_compressed = true; 612 is_gnu_compressed = true;
613 if (elf_compress_gnu (tscn, 0, 0) != 1) 613 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 @@
12021-04-19 Martin Liska <mliska@suse.cz>
2
3 * dwelf_elf_e_machine_string.c (main): Use startswith.
4 * dwelfgnucompressed.c (main): Likewise.
5 * elfgetchdr.c (main): Likewise.
6 * elfputzdata.c (main): Likewise.
7 * vdsosyms.c (module_callback): Likewise.
8
12021-05-04 Alice Zhang <alizhang@redhat.com> 92021-05-04 Alice Zhang <alizhang@redhat.com>
2 10
3 * run-debuginfod-find.sh: Added tests for negative cache files. 11 * 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 @@
19# include <config.h> 19# include <config.h>
20#endif 20#endif
21 21
22#include <system.h>
23
22#include <assert.h> 24#include <assert.h>
23#include <errno.h> 25#include <errno.h>
24#include <inttypes.h> 26#include <inttypes.h>
@@ -41,7 +43,7 @@ main (int argc, char **argv)
41 const char *machine; 43 const char *machine;
42 44
43 errno = 0; 45 errno = 0;
44 if (strncmp ("0x", argv[i], 2) == 0) 46 if (startswith (argv[i], "0x"))
45 val = strtol (&argv[i][2], NULL, 16); 47 val = strtol (&argv[i][2], NULL, 16);
46 else 48 else
47 val = strtol (argv[i], NULL, 10); 49 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 @@
18# include <config.h> 18# include <config.h>
19#endif 19#endif
20 20
21#include <system.h>
22
21#include <assert.h> 23#include <assert.h>
22#include <sys/types.h> 24#include <sys/types.h>
23#include <sys/stat.h> 25#include <sys/stat.h>
@@ -82,7 +84,7 @@ main (int argc, char *argv[])
82 break; 84 break;
83 } 85 }
84 86
85 if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0) 87 if (startswith (sname, ".zdebug"))
86 { 88 {
87 ssize_t size; 89 ssize_t size;
88 if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1) 90 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 @@
18# include <config.h> 18# include <config.h>
19#endif 19#endif
20 20
21#include <system.h>
22
21#include <assert.h> 23#include <assert.h>
22#include <sys/types.h> 24#include <sys/types.h>
23#include <sys/stat.h> 25#include <sys/stat.h>
@@ -99,7 +101,7 @@ main (int argc, char *argv[])
99 } 101 }
100 102
101 /* This duplicates what the dwelfgnucompressed testcase does. */ 103 /* This duplicates what the dwelfgnucompressed testcase does. */
102 if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0) 104 if (startswith (sname, ".zdebug"))
103 { 105 {
104 ssize_t size; 106 ssize_t size;
105 if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1) 107 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 @@
18# include <config.h> 18# include <config.h>
19#endif 19#endif
20 20
21#include <system.h>
22
21#include <sys/types.h> 23#include <sys/types.h>
22#include <sys/stat.h> 24#include <sys/stat.h>
23#include <fcntl.h> 25#include <fcntl.h>
@@ -83,7 +85,7 @@ main (int argc, char *argv[])
83 printf ("Cannot compress %zd %s\n", idx, name); 85 printf ("Cannot compress %zd %s\n", idx, name);
84 } 86 }
85 else if ((shdr->sh_flags & SHF_COMPRESSED) != 0 87 else if ((shdr->sh_flags & SHF_COMPRESSED) != 0
86 || strncmp (name, ".zdebug", strlen (".zdebug")) == 0) 88 || startswith (name, ".zdebug"))
87 { 89 {
88 printf ("Already compressed %zd %s\n", idx, name); 90 printf ("Already compressed %zd %s\n", idx, name);
89 } 91 }
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)),
43{ 43{
44 /* We can only recognize the vdso by inspecting the "magic name". */ 44 /* We can only recognize the vdso by inspecting the "magic name". */
45 printf ("module name: %s\n", name); 45 printf ("module name: %s\n", name);
46 if (strncmp ("[vdso: ", name, 7) == 0) 46 if (startswith (name, "[vdso: "))
47 { 47 {
48 vdso_syms = dwfl_module_getsymtab (mod); 48 vdso_syms = dwfl_module_getsymtab (mod);
49 printf ("vdso syms: %d\n", vdso_syms); 49 printf ("vdso syms: %d\n", vdso_syms);