diff options
author | Martin Liska <mliska@suse.cz> | 2021-03-18 15:16:54 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2021-04-01 14:59:04 +0200 |
commit | 3f3328b816ee3486ac0621cfd6d808faa2c0a689 (patch) | |
tree | 5323d7ff39635e28d62c26a7e13e705ccfafe757 | |
parent | 24d127aa9f26445709dbd53e14e2ab636a449888 (diff) | |
download | gdb-3f3328b816ee3486ac0621cfd6d808faa2c0a689.zip gdb-3f3328b816ee3486ac0621cfd6d808faa2c0a689.tar.gz gdb-3f3328b816ee3486ac0621cfd6d808faa2c0a689.tar.bz2 |
Use startswith more for strncmp function calls.
bfd/ChangeLog:
* elf-bfd.h (bfd_section_is_ctf): Use startswith function.
* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
(elf_get_reloc_section): Likewise.
* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
* elf32-m32r.c (m32r_elf_section_flags): Likewise.
* elf32-microblaze.c (microblaze_elf_size_dynamic_sections): Likewise.
* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
(nds32_elf_relocate_section): Likewise.
(nds32_elf_action_discarded): Likewise.
(nds32_elf_check_relocs): Likewise.
(nds32_elf_section_flags): Likewise.
* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
* elf32-ppc.c (ppc_elf_section_from_shdr): Likewise.
* elf32-rx.c (rx_table_find): Likewise.
(rx_table_map): Likewise.
* elf32-spu.c (spu_elf_backend_symbol_processing): Likewise.
(spu_elf_find_overlays): Likewise.
(needs_ovl_stub): Likewise.
(allocate_spuear_stubs): Likewise.
(build_spuear_stubs): Likewise.
(mark_overlay_section): Likewise.
(spu_elf_auto_overlay): Likewise.
(spu_elf_output_symbol_hook): Likewise.
* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
* elf32-xtensa.c (xtensa_property_section_name): Likewise.
* elf64-ppc.c (ppc64_elf_section_flags): Likewise.
(ppc64_elf_relocate_section): Likewise.
* elflink.c (resolve_section): Likewise.
(UNARY_OP): Likewise.
(BINARY_OP_HEAD): Likewise.
(elf_link_input_bfd): Likewise.
* elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
* elfxx-riscv.c (riscv_parse_subset): Likewise.
* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
* opncls.c (get_build_id): Likewise.
binutils/ChangeLog:
* dllwrap.c: Use startswith function.
* objcopy.c (is_dwo_section): Likewise.
(handle_remove_section_option): Likewise.
(copy_main): Likewise.
* objdump.c (is_significant_symbol_name): Likewise.
-rw-r--r-- | bfd/ChangeLog | 38 | ||||
-rw-r--r-- | bfd/elf-bfd.h | 2 | ||||
-rw-r--r-- | bfd/elf.c | 21 | ||||
-rw-r--r-- | bfd/elf32-arc.c | 2 | ||||
-rw-r--r-- | bfd/elf32-m32r.c | 4 | ||||
-rw-r--r-- | bfd/elf32-microblaze.c | 2 | ||||
-rw-r--r-- | bfd/elf32-nds32.c | 13 | ||||
-rw-r--r-- | bfd/elf32-or1k.c | 2 | ||||
-rw-r--r-- | bfd/elf32-ppc.c | 6 | ||||
-rw-r--r-- | bfd/elf32-rx.c | 6 | ||||
-rw-r--r-- | bfd/elf32-spu.c | 26 | ||||
-rw-r--r-- | bfd/elf32-tilepro.c | 2 | ||||
-rw-r--r-- | bfd/elf32-xtensa.c | 2 | ||||
-rw-r--r-- | bfd/elf64-ppc.c | 6 | ||||
-rw-r--r-- | bfd/elflink.c | 10 | ||||
-rw-r--r-- | bfd/elfnn-riscv.c | 2 | ||||
-rw-r--r-- | bfd/elfxx-riscv.c | 4 | ||||
-rw-r--r-- | bfd/elfxx-tilegx.c | 2 | ||||
-rw-r--r-- | bfd/opncls.c | 2 | ||||
-rw-r--r-- | binutils/ChangeLog | 8 | ||||
-rw-r--r-- | binutils/dllwrap.c | 8 | ||||
-rw-r--r-- | binutils/objcopy.c | 20 | ||||
-rw-r--r-- | binutils/objdump.c | 2 |
23 files changed, 117 insertions, 73 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e12c559..aa62c92 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,41 @@ +2021-04-01 Martin Liska <mliska@suse.cz> + + * elf-bfd.h (bfd_section_is_ctf): Use startswith function. + * elf.c (_bfd_elf_make_section_from_shdr): Likewise. + (elf_get_reloc_section): Likewise. + * elf32-arc.c (elf_arc_size_dynamic_sections): Likewise. + * elf32-m32r.c (m32r_elf_section_flags): Likewise. + * elf32-microblaze.c (microblaze_elf_size_dynamic_sections): Likewise. + * elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise. + (nds32_elf_relocate_section): Likewise. + (nds32_elf_action_discarded): Likewise. + (nds32_elf_check_relocs): Likewise. + (nds32_elf_section_flags): Likewise. + * elf32-or1k.c (or1k_elf_check_relocs): Likewise. + * elf32-ppc.c (ppc_elf_section_from_shdr): Likewise. + * elf32-rx.c (rx_table_find): Likewise. + (rx_table_map): Likewise. + * elf32-spu.c (spu_elf_backend_symbol_processing): Likewise. + (spu_elf_find_overlays): Likewise. + (needs_ovl_stub): Likewise. + (allocate_spuear_stubs): Likewise. + (build_spuear_stubs): Likewise. + (mark_overlay_section): Likewise. + (spu_elf_auto_overlay): Likewise. + (spu_elf_output_symbol_hook): Likewise. + * elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise. + * elf32-xtensa.c (xtensa_property_section_name): Likewise. + * elf64-ppc.c (ppc64_elf_section_flags): Likewise. + (ppc64_elf_relocate_section): Likewise. + * elflink.c (resolve_section): Likewise. + (UNARY_OP): Likewise. + (BINARY_OP_HEAD): Likewise. + (elf_link_input_bfd): Likewise. + * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise. + * elfxx-riscv.c (riscv_parse_subset): Likewise. + * elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise. + * opncls.c (get_build_id): Likewise. + 2021-03-31 Alan Modra <amodra@gmail.com> PR 27671 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 101c2fd..296b80a 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -3093,7 +3093,7 @@ static inline bool bfd_section_is_ctf (const asection *sec) { const char *name = bfd_section_name (sec); - return strncmp (name, ".ctf", 4) == 0 && (name[4] == 0 || name[4] == '.'); + return startswith (name, ".ctf") && (name[4] == 0 || name[4] == '.'); } #ifdef __cplusplus @@ -1084,19 +1084,19 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, not any sort of flag. Their SEC_ALLOC bits are cleared. */ if (name [0] == '.') { - if (strncmp (name, ".debug", 6) == 0 - || strncmp (name, ".gnu.debuglto_.debug_", 21) == 0 - || strncmp (name, ".gnu.linkonce.wi.", 17) == 0 - || strncmp (name, ".zdebug", 7) == 0) + if (startswith (name, ".debug") + || startswith (name, ".gnu.debuglto_.debug_") + || startswith (name, ".gnu.linkonce.wi.") + || startswith (name, ".zdebug")) flags |= SEC_DEBUGGING | SEC_ELF_OCTETS; - else if (strncmp (name, GNU_BUILD_ATTRS_SECTION_NAME, 21) == 0 - || strncmp (name, ".note.gnu", 9) == 0) + else if (startswith (name, GNU_BUILD_ATTRS_SECTION_NAME) + || startswith (name, ".note.gnu")) { flags |= SEC_ELF_OCTETS; opb = 1; } - else if (strncmp (name, ".line", 5) == 0 - || strncmp (name, ".stab", 5) == 0 + else if (startswith (name, ".line") + || startswith (name, ".stab") || strcmp (name, ".gdb_index") == 0) flags |= SEC_DEBUGGING; } @@ -1277,8 +1277,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information section. */ - const char *lto_section_name = ".gnu.lto_.lto."; - if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0) + if (startswith (name, ".gnu.lto_.lto.")) { struct lto_section lsection; if (bfd_get_section_contents (abfd, newsect, &lsection, 0, @@ -3677,7 +3676,7 @@ elf_get_reloc_section (asection *reloc_sec) /* We look up the section the relocs apply to by name. */ name = reloc_sec->name; - if (strncmp (name, ".rel", 4) != 0) + if (!startswith (name, ".rel")) return NULL; name += 4; if (type == SHT_RELA && *name++ != 'a') diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c index d201d5a..11a1388 100644 --- a/bfd/elf32-arc.c +++ b/bfd/elf32-arc.c @@ -2759,7 +2759,7 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, { /* Strip this section if we don't need it. */ } - else if (strncmp (s->name, ".rela", 5) == 0) + else if (startswith (s->name, ".rela")) { if (s->size != 0 && s != htab->srelplt) relocs_exist = true; diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 783632b..6a73258 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -3615,8 +3615,8 @@ m32r_elf_section_flags (const Elf_Internal_Shdr *hdr) { const char *name = hdr->bfd_section->name; - if (strncmp (name, ".sbss", 5) == 0 - || strncmp (name, ".sdata", 6) == 0) + if (startswith (name, ".sbss") + || startswith (name, ".sdata")) hdr->bfd_section->flags |= SEC_SMALL_DATA; return true; diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c index b586858..d9c0d93 100644 --- a/bfd/elf32-microblaze.c +++ b/bfd/elf32-microblaze.c @@ -3050,7 +3050,7 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, of the dynobj section names depend upon the input files. */ name = bfd_section_name (s); - if (strncmp (name, ".rela", 5) == 0) + if (startswith (name, ".rela")) { if (s->size == 0) { diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 31a3ca0..5eb0295 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -4439,7 +4439,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, { got_size += s->size; } - else if (strncmp (bfd_section_name (s), ".rela", 5) == 0) + else if (startswith (bfd_section_name (s), ".rela")) { if (s->size != 0 && s != elf_hash_table (info)->srelplt) relocs = true; @@ -5426,7 +5426,7 @@ nds32_elf_relocate_section (bfd * output_bfd ATTRIBUTE_UNUSED, if (name == NULL) return false; - BFD_ASSERT (strncmp (name, ".rela", 5) == 0 + BFD_ASSERT (startswith (name, ".rela") && strcmp (bfd_section_name (input_section), name + 5) == 0); @@ -6870,8 +6870,7 @@ static unsigned int nds32_elf_action_discarded (asection *sec) { - if (strncmp - (".gcc_except_table", sec->name, sizeof (".gcc_except_table") - 1) == 0) + if (startswith (sec->name, ".gcc_except_table")) return 0; return _bfd_elf_default_action_discarded (sec); @@ -7239,7 +7238,7 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, if (name == NULL) return false; - BFD_ASSERT (strncmp (name, ".rela", 5) == 0 + BFD_ASSERT (startswith (name, ".rela") && strcmp (bfd_section_name (sec), name + 5) == 0); @@ -12450,8 +12449,8 @@ nds32_elf_section_flags (const Elf_Internal_Shdr *hdr) { const char *name = hdr->bfd_section->name; - if (strncmp (name, ".sbss", 5) == 0 - || strncmp (name, ".sdata", 6) == 0) + if (startswith (name, ".sbss") + || startswith (name, ".sdata")) hdr->bfd_section->flags |= SEC_SMALL_DATA; return true; diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c index cd4398d..013deb4 100644 --- a/bfd/elf32-or1k.c +++ b/bfd/elf32-or1k.c @@ -2110,7 +2110,7 @@ or1k_elf_check_relocs (bfd *abfd, if (name == NULL) return false; - if (strncmp (name, ".rela", 5) != 0 + if (!startswith (name, ".rela") || strcmp (bfd_section_name (sec), name + 5) != 0) { _bfd_error_handler diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 0ae7e0b..d6ed501 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -1338,10 +1338,10 @@ ppc_elf_section_from_shdr (bfd *abfd, if (hdr->sh_type == SHT_ORDERED) flags |= SEC_SORT_ENTRIES; - if (strncmp (name, ".PPC.EMB", 8) == 0) + if (startswith (name, ".PPC.EMB")) name += 8; - if (strncmp (name, ".sbss", 5) == 0 - || strncmp (name, ".sdata", 6) == 0) + if (startswith (name, ".sbss") + || startswith (name, ".sdata")) flags |= SEC_SMALL_DATA; return (flags == 0 diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c index 95684d4..7718635 100644 --- a/bfd/elf32-rx.c +++ b/bfd/elf32-rx.c @@ -557,7 +557,7 @@ rx_elf_relocate_section name = h->root.root.string; } - if (strncmp (name, "$tableentry$default$", 20) == 0) + if (startswith (name, "$tableentry$default$")) { bfd_vma entry_vma; int idx; @@ -3759,7 +3759,7 @@ rx_table_find (struct bfd_hash_entry *vent, void *vinfo) sec = ent->u.def.section; abfd = sec->owner; - if (strncmp (name, "$tablestart$", 12)) + if (!startswith (name, "$tablestart$")) return true; sec->flags |= SEC_KEEP; @@ -3895,7 +3895,7 @@ rx_table_map (struct bfd_hash_entry *vent, void *vinfo) name = ent->root.string; - if (strncmp (name, "$tablestart$", 12)) + if (!startswith (name, "$tablestart$")) return true; tname = name + 12; diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c index 5bffc1d..c3ce2c1 100644 --- a/bfd/elf32-spu.c +++ b/bfd/elf32-spu.c @@ -307,7 +307,7 @@ spu_elf_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym) { if (sym->name != NULL && sym->section != bfd_abs_section_ptr - && strncmp (sym->name, "_EAR_", 5) == 0) + && startswith (sym->name, "_EAR_")) sym->flags |= BSF_KEEP; } @@ -725,7 +725,7 @@ spu_elf_find_overlays (struct bfd_link_info *info) an overlay, in the sense that it might be loaded in by the overlay manager, but rather the initial section contents for the overlay buffer. */ - if (strncmp (s->name, ".ovl.init", 9) != 0) + if (!startswith (s->name, ".ovl.init")) { num_buf = ((s->vma - vma_start) >> htab->line_size_log2) + 1; set_id = (num_buf == prev_buf)? set_id + 1 : 0; @@ -785,7 +785,7 @@ spu_elf_find_overlays (struct bfd_link_info *info) if (spu_elf_section_data (s0)->u.o.ovl_index == 0) { ++num_buf; - if (strncmp (s0->name, ".ovl.init", 9) != 0) + if (!startswith (s0->name, ".ovl.init")) { alloc_sec[ovl_index] = s0; spu_elf_section_data (s0)->u.o.ovl_index = ++ovl_index; @@ -794,7 +794,7 @@ spu_elf_find_overlays (struct bfd_link_info *info) else ovl_end = s->vma + s->size; } - if (strncmp (s->name, ".ovl.init", 9) != 0) + if (!startswith (s->name, ".ovl.init")) { alloc_sec[ovl_index] = s; spu_elf_section_data (s)->u.o.ovl_index = ++ovl_index; @@ -970,7 +970,7 @@ needs_ovl_stub (struct elf_link_hash_entry *h, /* setjmp always goes via an overlay stub, because then the return and hence the longjmp goes via __ovly_return. That magically makes setjmp/longjmp between overlays work. */ - if (strncmp (h->root.root.string, "setjmp", 6) == 0 + if (startswith (h->root.root.string, "setjmp") && (h->root.root.string[6] == '\0' || h->root.root.string[6] == '@')) ret = call_ovl_stub; } @@ -1496,7 +1496,7 @@ allocate_spuear_stubs (struct elf_link_hash_entry *h, void *inf) if ((h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) && h->def_regular - && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0 + && startswith (h->root.root.string, "_SPUEAR_") && (sym_sec = h->root.u.def.section) != NULL && sym_sec->output_section != bfd_abs_section_ptr && spu_elf_section_data (sym_sec->output_section) != NULL @@ -1521,7 +1521,7 @@ build_spuear_stubs (struct elf_link_hash_entry *h, void *inf) if ((h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) && h->def_regular - && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0 + && startswith (h->root.root.string, "_SPUEAR_") && (sym_sec = h->root.u.def.section) != NULL && sym_sec->output_section != bfd_abs_section_ptr && spu_elf_section_data (sym_sec->output_section) != NULL @@ -3455,7 +3455,7 @@ mark_overlay_section (struct function_info *fun, if (!fun->sec->linker_mark && (htab->params->ovly_flavour != ovly_soft_icache || htab->params->non_ia_text - || strncmp (fun->sec->name, ".text.ia.", 9) == 0 + || startswith (fun->sec->name, ".text.ia.") || strcmp (fun->sec->name, ".init") == 0 || strcmp (fun->sec->name, ".fini") == 0)) { @@ -3483,7 +3483,7 @@ mark_overlay_section (struct function_info *fun, return false; memcpy (name, ".rodata", sizeof (".rodata")); } - else if (strncmp (fun->sec->name, ".text.", 6) == 0) + else if (startswith (fun->sec->name, ".text.")) { size_t len = strlen (fun->sec->name); name = bfd_malloc (len + 3); @@ -3492,7 +3492,7 @@ mark_overlay_section (struct function_info *fun, memcpy (name, ".rodata", sizeof (".rodata")); memcpy (name + 7, fun->sec->name + 5, len - 4); } - else if (strncmp (fun->sec->name, ".gnu.linkonce.t.", 16) == 0) + else if (startswith (fun->sec->name, ".gnu.linkonce.t.")) { size_t len = strlen (fun->sec->name) + 1; name = bfd_malloc (len); @@ -3583,7 +3583,7 @@ mark_overlay_section (struct function_info *fun, a stack! Also, don't mark .ovl.init as an overlay. */ if (fun->lo + fun->sec->output_offset + fun->sec->output_section->vma == info->output_bfd->start_address - || strncmp (fun->sec->output_section->name, ".ovl.init", 9) == 0) + || startswith (fun->sec->output_section->name, ".ovl.init")) { fun->sec->linker_mark = 0; if (fun->rodata != NULL) @@ -4317,7 +4317,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) } else if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD) && sec->output_section->owner == info->output_bfd - && strncmp (sec->output_section->name, ".ovl.init", 9) == 0) + && startswith (sec->output_section->name, ".ovl.init")) fixed_size -= sec->size; if (count != old_count) bfd_arr[bfd_count++] = ibfd; @@ -5156,7 +5156,7 @@ spu_elf_output_symbol_hook (struct bfd_link_info *info, && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) && h->def_regular - && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0) + && startswith (h->root.root.string, "_SPUEAR_")) { struct got_entry *g; diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c index cf288b3..b0ed706 100644 --- a/bfd/elf32-tilepro.c +++ b/bfd/elf32-tilepro.c @@ -2332,7 +2332,7 @@ tilepro_elf_size_dynamic_sections (bfd *output_bfd, /* Strip this section if we don't need it; see the comment below. */ } - else if (strncmp (s->name, ".rela", 5) == 0) + else if (startswith (s->name, ".rela")) { if (s->size != 0) { diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 21894d1..c1781c7 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -11260,7 +11260,7 @@ xtensa_property_section_name (asection *sec, const char *base_name, suffix = 0; prop_sec_name = xtensa_add_names (base_name, suffix); } - else if (strncmp (sec->name, ".gnu.linkonce.", linkonce_len) == 0) + else if (startswith (sec->name, ".gnu.linkonce.")) { char *linkonce_kind = 0; diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index bc8dc4d..c306954 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -2042,8 +2042,8 @@ ppc64_elf_section_flags (const Elf_Internal_Shdr *hdr) { const char *name = hdr->bfd_section->name; - if (strncmp (name, ".sbss", 5) == 0 - || strncmp (name, ".sdata", 6) == 0) + if (startswith (name, ".sbss") + || startswith (name, ".sdata")) hdr->bfd_section->flags |= SEC_SMALL_DATA; return true; @@ -15873,7 +15873,7 @@ ppc64_elf_relocate_section (bfd *output_bfd, if (*name == '.') ++name; - if (strncmp (name, "__libc_start_main", 17) == 0 + if (startswith (name, "__libc_start_main") && (name[17] == 0 || name[17] == '@')) { /* Allow crt1 branch to go via a toc adjusting diff --git a/bfd/elflink.c b/bfd/elflink.c index ce1407f..f8d6313 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8719,7 +8719,7 @@ resolve_section (const char *name, if (strncmp (curr->name, name, len) == 0) { - if (strncmp (".end", name + len, 4) == 0) + if (startswith (name + len, ".end")) { *result = (curr->vma + curr->size / bfd_octets_per_byte (abfd, curr)); @@ -8832,7 +8832,7 @@ eval_symbol (bfd_vma *result, /* All that remains are operators. */ #define UNARY_OP(op) \ - if (strncmp (sym, #op, strlen (#op)) == 0) \ + if (startswith (sym, #op)) \ { \ sym += strlen (#op); \ if (*sym == ':') \ @@ -8849,7 +8849,7 @@ eval_symbol (bfd_vma *result, } #define BINARY_OP_HEAD(op) \ - if (strncmp (sym, #op, strlen (#op)) == 0) \ + if (startswith (sym, #op)) \ { \ sym += strlen (#op); \ if (*sym == ':') \ @@ -11196,10 +11196,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) /* We need to reverse-copy input .ctors/.dtors sections if they are placed in .init_array/.finit_array for output. */ if (o->size > address_size - && ((strncmp (o->name, ".ctors", 6) == 0 + && ((startswith (o->name, ".ctors") && strcmp (o->output_section->name, ".init_array") == 0) - || (strncmp (o->name, ".dtors", 6) == 0 + || (startswith (o->name, ".dtors") && strcmp (o->output_section->name, ".fini_array") == 0)) && (o->name[6] == 0 || o->name[6] == '.')) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 51f9d75..b5be929 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -1515,7 +1515,7 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) /* Strip this section if we don't need it; see the comment below. */ } - else if (strncmp (s->name, ".rela", 5) == 0) + else if (startswith (s->name, ".rela")) { if (s->size != 0) { diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index a81ebd4..f6a2509 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1802,12 +1802,12 @@ riscv_parse_subset (riscv_parse_subset_t *rps, } p = arch; - if (strncmp (p, "rv32", 4) == 0) + if (startswith (p, "rv32")) { *rps->xlen = 32; p += 4; } - else if (strncmp (p, "rv64", 4) == 0) + else if (startswith (p, "rv64")) { *rps->xlen = 64; p += 4; diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c index 28a1a43..a517831 100644 --- a/bfd/elfxx-tilegx.c +++ b/bfd/elfxx-tilegx.c @@ -2578,7 +2578,7 @@ tilegx_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* Strip this section if we don't need it; see the comment below. */ } - else if (strncmp (s->name, ".rela", 5) == 0) + else if (startswith (s->name, ".rela")) { if (s->size != 0) { diff --git a/bfd/opncls.c b/bfd/opncls.c index 26faaa6..74df4c2 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1904,7 +1904,7 @@ get_build_id (bfd *abfd) if (inote.descsz <= 0 || inote.type != NT_GNU_BUILD_ID || inote.namesz != 4 /* sizeof "GNU" */ - || strncmp (inote.namedata, "GNU", 4) != 0 + || !startswith (inote.namedata, "GNU") || inote.descsz > 0x7ffffffe || size < (12 + BFD_ALIGN (inote.namesz, 4) + inote.descsz)) { diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 125ac81..1ffbdf8 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,5 +1,13 @@ 2021-04-01 Martin Liska <mliska@suse.cz> + * dllwrap.c: Use startswith function. + * objcopy.c (is_dwo_section): Likewise. + (handle_remove_section_option): Likewise. + (copy_main): Likewise. + * objdump.c (is_significant_symbol_name): Likewise. + +2021-04-01 Martin Liska <mliska@suse.cz> + * dwarf.c (display_debug_lines_raw): Replace const_strneq with startswith. (display_debug_lines_decoded): Likewise. diff --git a/binutils/dllwrap.c b/binutils/dllwrap.c index bd65b98..bc7104d 100644 --- a/binutils/dllwrap.c +++ b/binutils/dllwrap.c @@ -840,11 +840,11 @@ Creating one, but that may not be what you want")); else which_target = UNKNOWN_TARGET; - if (! strncmp (target, "arm", 3)) + if (startswith (target, "arm")) which_cpu = ARM_CPU; - else if (!strncmp (target, "x86_64", 6) - || !strncmp (target, "athlon64", 8) - || !strncmp (target, "amd64", 5)) + else if (startswith (target, "x86_64") + || startswith (target, "athlon64") + || startswith (target, "amd64")) which_cpu = X64_CPU; else if (target[0] == 'i' && (target[1] >= '3' && target[1] <= '6') && target[2] == '8' && target[3] == '6') diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 092bc9e..6622adc 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1285,7 +1285,7 @@ is_dwo_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) if (len < 5) return false; - return strncmp (name + len - 4, ".dwo", 4) == 0; + return startswith (name + len - 4, ".dwo"); } /* Return TRUE if section SEC is in the update list. */ @@ -4261,7 +4261,7 @@ static void handle_remove_section_option (const char *section_pattern) { find_section_list (section_pattern, true, SECTION_CONTEXT_REMOVE); - if (strncmp (section_pattern, ".rel", 4) == 0) + if (startswith (section_pattern, ".rel")) { section_pattern += 4; if (*section_pattern == 'a') @@ -5875,15 +5875,15 @@ copy_main (int argc, char *argv[]) /* Convert input EFI target to PEI target. */ if (input_target != NULL - && strncmp (input_target, "efi-", 4) == 0) + && startswith (input_target, "efi-")) { char *efi; efi = xstrdup (output_target + 4); - if (strncmp (efi, "bsdrv-", 6) == 0 - || strncmp (efi, "rtdrv-", 6) == 0) + if (startswith (efi, "bsdrv-") + || startswith (efi, "rtdrv-")) efi += 2; - else if (strncmp (efi, "app-", 4) != 0) + else if (!startswith (efi, "app-")) fatal (_("unknown input EFI target: %s"), input_target); input_target = efi; @@ -5892,23 +5892,23 @@ copy_main (int argc, char *argv[]) /* Convert output EFI target to PEI target. */ if (output_target != NULL - && strncmp (output_target, "efi-", 4) == 0) + && startswith (output_target, "efi-")) { char *efi; efi = xstrdup (output_target + 4); - if (strncmp (efi, "app-", 4) == 0) + if (startswith (efi, "app-")) { if (pe_subsystem == -1) pe_subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; } - else if (strncmp (efi, "bsdrv-", 6) == 0) + else if (startswith (efi, "bsdrv-")) { if (pe_subsystem == -1) pe_subsystem = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER; efi += 2; } - else if (strncmp (efi, "rtdrv-", 6) == 0) + else if (startswith (efi, "rtdrv-")) { if (pe_subsystem == -1) pe_subsystem = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER; diff --git a/binutils/objdump.c b/binutils/objdump.c index bffd744..cbbec81 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -821,7 +821,7 @@ slurp_dynamic_symtab (bfd *abfd) static bool is_significant_symbol_name (const char * name) { - return strncmp (name, ".plt", 4) == 0 || strcmp (name, ".got") == 0; + return startswith (name, ".plt") || startswith (name, ".got"); } /* Filter out (in place) symbols that are useless for disassembly. |