From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61929 invoked by alias); 18 Sep 2019 12:56:08 -0000 Mailing-List: contact gdb-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: gdb-cvs-owner@sourceware.org List-Subscribe: Sender: gdb-cvs-owner@sourceware.org Received: (qmail 61514 invoked by uid 9051); 18 Sep 2019 12:56:08 -0000 Date: Wed, 18 Sep 2019 12:56:00 -0000 Message-ID: <20190918125608.61508.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alan Modra To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] Constify target name, reloc name, and carsym name X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 90d92a632aaf75ce698335efeb383ddf785c12d8 X-Git-Newrev: 1d38e9d14cc793bca9124d5ed7dc2a6e3122f2e5 X-SW-Source: 2019-09/txt/msg00051.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1d38e9d14cc793bca9124d5ed7dc2a6e3122f2e5 commit 1d38e9d14cc793bca9124d5ed7dc2a6e3122f2e5 Author: Alan Modra Date: Wed Sep 18 15:04:27 2019 +0930 Constify target name, reloc name, and carsym name 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: --- bfd/ChangeLog | 10 ++++++++++ bfd/bfd-in.h | 2 +- bfd/bfd-in2.h | 6 +++--- bfd/bfd.c | 2 +- bfd/reloc.c | 2 +- bfd/som.c | 19 +++++++++++-------- bfd/targets.c | 2 +- gdb/ChangeLog | 6 ++++++ gdb/amd64-dicos-tdep.c | 2 +- gdb/i386-cygwin-tdep.c | 2 +- gdb/i386-dicos-tdep.c | 2 +- ld/ChangeLog | 5 +++++ ld/ldlang.c | 10 +++++----- 13 files changed, 47 insertions(+), 23 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 08605c3..8c5ce8b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,15 @@ 2019-09-18 Alan Modra + * 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. + +2019-09-18 Alan Modra + * mach-o.c (bfd_mach_o_fat_member_init): Likewise. Replace xstrdup and xmalloc with bfd_strdup and bfd_malloc. Return an error status. Adjust calls. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 6544838..6c72acb 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-in2.h b/bfd/bfd-in2.h index 13445a1..135c1e5 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -264,7 +264,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. */ @@ -2718,7 +2718,7 @@ struct reloc_howto_struct bfd *, char **); /* The textual name of the relocation type. */ - char *name; + const char *name; }; #define HOWTO(type, right, size, bits, pcrel, left, ovf, func, name, \ @@ -7634,7 +7634,7 @@ typedef struct flag_info flag_info; 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/bfd/bfd.c b/bfd/bfd.c index f14ec25..9140350 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 9ca68ca..8eac73d 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 02a99a3..cf78843 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 0995699..b02dfc5 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/ChangeLog b/gdb/ChangeLog index 9ad5000..5e0e37b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2019-09-18 Alan Modra + * 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. + +2019-09-18 Alan Modra + * solib-spu.c (spu_bfd_open): Use bfd_set_filename. * spu-linux-nat.c (spu_bfd_open): Likewise. diff --git a/gdb/amd64-dicos-tdep.c b/gdb/amd64-dicos-tdep.c index e797843..ee91888 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 1acd379..0e3ba82 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 02af91a..a8c7c04 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/ChangeLog b/ld/ChangeLog index 81935a4..b863676 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,10 @@ 2019-09-18 Alan Modra + * ldlang.c (stricpy, strcut, name_compare): Constify params. + (get_first_input_target): Make return and "target" const. + +2019-09-18 Alan Modra + * emultempl/pe.em (after_open): Use bfd_set_filename. * emultempl/pep.em (after_open): Use bfd_set_filename. diff --git a/ld/ldlang.c b/ld/ldlang.c index 8beccd3..76e862a 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) {