From patchwork Wed Sep 18 12:44:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 34568 Received: (qmail 99832 invoked by alias); 18 Sep 2019 12:44:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 99817 invoked by uid 89); 18 Sep 2019 12:44:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=som, HX-Gm-Message-State:APjAAAU, HX-Google-DKIM-Signature:UdFA X-HELO: mail-pf1-f180.google.com Received: from mail-pf1-f180.google.com (HELO mail-pf1-f180.google.com) (209.85.210.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Sep 2019 12:44:49 +0000 Received: by mail-pf1-f180.google.com with SMTP id q10so4407525pfl.0; Wed, 18 Sep 2019 05:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=0wyNRlsGumTVyTqpBJTi9lF7vKJJJhIdmxUW8QSGgnw=; b=JUHnKJa/TfAQiGZA9FNtScZz54tBqplds7TtqbGlqZTYPuuSt1fIlUnpJRLbWtm86T Q4dRxoJZ06dxm5duIPpxdtrIbQvl6WHdFOUWiRe2qeNYsk7Nvx+s+3mI27kcSfRxFlhF aNjCXF2s0aHfMy87TZuPeOfgBzm4v+eOYmGHYMe8B1aTRtfF8IiVb0kXTJl3coM/f57P AgNeZtm+1Oi3/u3HQ4JszhmDqtZ/N3e7nxVq2k/SYZH+2bhhG6H3Y7e78Zmb0KvJprc2 YHLrqk9dA9Gv9TORg6REcPEooIu+Jf5Ozuvfp+CJpBJbAUD5zANnvQVdeYFXqvfvfNPN QOSg== Return-Path: Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id i74sm8667143pfe.28.2019.09.18.05.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2019 05:44:46 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 54C5A80801; Wed, 18 Sep 2019 22:14:43 +0930 (ACST) Date: Wed, 18 Sep 2019 22:14:43 +0930 From: Alan Modra To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Constify target name, reloc name, and carsym name Message-ID: <20190918124443.GD3685@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Just a few of the many cases where we could make char*'s const. Again committing the gdb part as obvious. bfd/ * bfd-in.h (carsym.name): Make const. * reloc.c (struct reloc_howto_struct.name): Likewise. * targets.c (bfd_target.name): Likewise.! * bfd.c (bfd_get_sign_extend_vma): Make variable const. * som.c (som_bfd_fill_in_ar_symbols): Use an intermediary variable when setting carsym.name. * bfd-in2.h: Regenerate. gdb/ * amd64-dicos-tdep.c (amd64_dicos_osabi_sniffer): Constify target. * i386-cygwin-tdep.c (i386_cygwin_init_abi): Likewise. * i386-dicos-tdep.c (i386_dicos_osabi_sniffer): Likewise. ld/ * ldlang.c (stricpy, strcut, name_compare): Constify params. (get_first_input_target): Make return and "target" const. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 6544838a57..6c72acb705 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -257,7 +257,7 @@ typedef unsigned long symindex; /* This is a type pun with struct ranlib on purpose! */ typedef struct carsym { - char *name; + const char *name; file_ptr file_offset; /* Look here to find the file. */ } carsym; /* To make these you call a carsymogen. */ diff --git a/bfd/bfd.c b/bfd/bfd.c index f14ec253fb..91403508a9 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1507,7 +1507,7 @@ RETURNS int bfd_get_sign_extend_vma (bfd *abfd) { - char *name; + const char *name; if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) return get_elf_backend_data (abfd)->sign_extend_vma; diff --git a/bfd/reloc.c b/bfd/reloc.c index 9ca68ca61d..8eac73ddfe 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -361,7 +361,7 @@ CODE_FRAGMENT . bfd *, char **); . . {* The textual name of the relocation type. *} -. char *name; +. const char *name; .}; . */ diff --git a/bfd/som.c b/bfd/som.c index 02a99a3360..cf78843452 100644 --- a/bfd/som.c +++ b/bfd/som.c @@ -5995,6 +5995,7 @@ som_bfd_fill_in_ar_symbols (bfd *abfd, unsigned int hash_val; unsigned int len; unsigned char ext_len[4]; + char *name; /* An empty chain has zero as it's file offset. */ hash_val = bfd_getb32 (hash_table + 4 * i); @@ -6025,13 +6026,14 @@ som_bfd_fill_in_ar_symbols (bfd *abfd, len = bfd_getb32 (ext_len); /* Allocate space for the name and null terminate it too. */ - set->name = bfd_zalloc (abfd, (bfd_size_type) len + 1); - if (!set->name) + name = bfd_zalloc (abfd, (bfd_size_type) len + 1); + if (!name) goto error_return; - if (bfd_bread (set->name, (bfd_size_type) len, abfd) != len) + if (bfd_bread (name, (bfd_size_type) len, abfd) != len) goto error_return; - set->name[len] = 0; + name[len] = 0; + set->name = name; /* Fill in the file offset. Note that the "location" field points to the SOM itself, not the ar_hdr in front of it. */ @@ -6068,13 +6070,14 @@ som_bfd_fill_in_ar_symbols (bfd *abfd, len = bfd_getb32 (ext_len); /* Allocate space for the name and null terminate it too. */ - set->name = bfd_zalloc (abfd, (bfd_size_type) len + 1); - if (!set->name) + name = bfd_zalloc (abfd, (bfd_size_type) len + 1); + if (!name) goto error_return; - if (bfd_bread (set->name, (bfd_size_type) len, abfd) != len) + if (bfd_bread (name, (bfd_size_type) len, abfd) != len) goto error_return; - set->name[len] = 0; + name[len] = 0; + set->name = name; /* Fill in the file offset. Note that the "location" field points to the SOM itself, not the ar_hdr in front of it. */ diff --git a/bfd/targets.c b/bfd/targets.c index 09956994ec..b02dfc5484 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -179,7 +179,7 @@ DESCRIPTION .typedef struct bfd_target .{ . {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc. *} -. char *name; +. const char *name; . . {* The "flavour" of a back end is a general indication about . the contents of a file. *} diff --git a/gdb/amd64-dicos-tdep.c b/gdb/amd64-dicos-tdep.c index e797843bc9..ee91888491 100644 --- a/gdb/amd64-dicos-tdep.c +++ b/gdb/amd64-dicos-tdep.c @@ -35,7 +35,7 @@ amd64_dicos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) static enum gdb_osabi amd64_dicos_osabi_sniffer (bfd *abfd) { - char *target_name = bfd_get_target (abfd); + const char *target_name = bfd_get_target (abfd); /* On amd64-DICOS, the Load Module's "header" section is 72 bytes. */ diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c index 1acd37975e..0e3ba82b76 100644 --- a/gdb/i386-cygwin-tdep.c +++ b/gdb/i386-cygwin-tdep.c @@ -229,7 +229,7 @@ i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) static enum gdb_osabi i386_cygwin_osabi_sniffer (bfd *abfd) { - char *target_name = bfd_get_target (abfd); + const char *target_name = bfd_get_target (abfd); if (strcmp (target_name, "pei-i386") == 0) return GDB_OSABI_CYGWIN; diff --git a/gdb/i386-dicos-tdep.c b/gdb/i386-dicos-tdep.c index 02af91aefd..a8c7c04d1f 100644 --- a/gdb/i386-dicos-tdep.c +++ b/gdb/i386-dicos-tdep.c @@ -31,7 +31,7 @@ i386_dicos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) static enum gdb_osabi i386_dicos_osabi_sniffer (bfd *abfd) { - char *target_name = bfd_get_target (abfd); + const char *target_name = bfd_get_target (abfd); /* On x86-DICOS, the Load Module's "header" section is 36 bytes. */ if (strcmp (target_name, "elf32-i386") == 0 diff --git a/ld/ldlang.c b/ld/ldlang.c index 8beccd3736..76e862a640 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -3149,7 +3149,7 @@ get_target (const bfd_target *target, void *data) /* Like strcpy() but convert to lower case as well. */ static void -stricpy (char *dest, char *src) +stricpy (char *dest, const char *src) { char c; @@ -3163,7 +3163,7 @@ stricpy (char *dest, char *src) from haystack. */ static void -strcut (char *haystack, char *needle) +strcut (char *haystack, const char *needle) { haystack = strstr (haystack, needle); @@ -3182,7 +3182,7 @@ strcut (char *haystack, char *needle) Return a value indicating how "similar" they are. */ static int -name_compare (char *first, char *second) +name_compare (const char *first, const char *second) { char *copy1; char *copy2; @@ -3267,10 +3267,10 @@ closest_target_match (const bfd_target *target, void *data) /* Return the BFD target format of the first input file. */ -static char * +static const char * get_first_input_target (void) { - char *target = NULL; + const char *target = NULL; LANG_FOR_EACH_INPUT_STATEMENT (s) {