From bb0082d686d9a84f29c7e6bb36736f68aa65169e Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 30 Jun 2001 03:15:46 +0000 Subject: [PATCH] * elf-bfd.h: Add prototypes for _bfd_elfcore_make_pseudosection and _bfd_elfcore_strndup. (struct elf_backend_data): Add elf_backend_grok_prstatus and elf_backend_grok_psinfo. * elf.c (_bfd_elfcore_make_pseudosection): New function. (elfcore_grok_prstatus): Use it. (elfcore_make_note_pseudosection): Likewise. (elfcore_strndup): Rename to... (_bfd_elfcore_strndup): Here, and make global. (elfcore_grok_psinfo): Use _bfd_elfcore_strndup. (elfcore_grok_note): Call elf_backend_grok_prstatus and elf_backend_grok_psinfo if available. * elf32-mips.c (_bfd_elf32_mips_grok_prstatus): New function. (_bfd_elf32_mips_grok_psinfo): New function. (elf_backend_grok_prstatus): Define. (elf_backend_grok_psinfo): Define. * elfxx-target.h (elf_backend_grok_prstatus): Default to NULL. (elf_backend_grok_psinfo): Likewise. (elfNN_bed): Include elf_backend_grok_prstatus and elf_backend_grok_psinfo. --- bfd/ChangeLog | 155 ++++++++++++++++++++++++++------------------- bfd/elf-bfd.h | 11 ++++ bfd/elf.c | 131 +++++++++++++++++++------------------- bfd/elf32-mips.c | 69 ++++++++++++++++++++ bfd/elfxx-target.h | 8 +++ 5 files changed, 244 insertions(+), 130 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b49316abf24..51a470b6867 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,26 @@ +2001-06-29 Daniel Jacobowitz + + * elf-bfd.h: Add prototypes for _bfd_elfcore_make_pseudosection + and _bfd_elfcore_strndup. + (struct elf_backend_data): Add elf_backend_grok_prstatus + and elf_backend_grok_psinfo. + * elf.c (_bfd_elfcore_make_pseudosection): New function. + (elfcore_grok_prstatus): Use it. + (elfcore_make_note_pseudosection): Likewise. + (elfcore_strndup): Rename to... + (_bfd_elfcore_strndup): Here, and make global. + (elfcore_grok_psinfo): Use _bfd_elfcore_strndup. + (elfcore_grok_note): Call elf_backend_grok_prstatus + and elf_backend_grok_psinfo if available. + * elf32-mips.c (_bfd_elf32_mips_grok_prstatus): New function. + (_bfd_elf32_mips_grok_psinfo): New function. + (elf_backend_grok_prstatus): Define. + (elf_backend_grok_psinfo): Define. + * elfxx-target.h (elf_backend_grok_prstatus): Default to NULL. + (elf_backend_grok_psinfo): Likewise. + (elfNN_bed): Include elf_backend_grok_prstatus and + elf_backend_grok_psinfo. + 2001-06-29 H.J. Lu * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Check if @@ -132,30 +155,30 @@ 2001-06-20 Catherine Moore - * elf-bfd.h (struct elf_backend_data): - elf_backend_emit_relocs: New field: Function for emitting - relocs. - elf_backend_count_relocs: New field: Function for determining - the number of relocs to be emitted. - * elfxx-target.h: Provide default (NULL) values for - elf_backend_emit_relocs and elf_backend_count_relocs. - * elflink.h (elf_link_size_reloc_section): Make the hash table - big enough to hold the relocs counted by either reloc_count or - o->reloc_count. - (elf_bfd_final_link) emit_relocs: New boolean, set if relocs - should be emitted, either because of a command line option - stored in the info structure or because the target provides a - special reloc emitting function. - If the target provides a reloc counting function use it, - unless performing a relocatable link or emitting all relocs. - Also set the SEC_RELOC flag on any output section which will - contain relocs. - (elf_link_input_bfd): emit_relocs: New boolean, set if relocs - should be emitted, either because of a command line option - stored in the info structure or because the target provides a - special reloc emitting function. - If the target provides a reloc emitting function, use it, - unless performing a relocatable link or emitting all relocs. + * elf-bfd.h (struct elf_backend_data): + elf_backend_emit_relocs: New field: Function for emitting + relocs. + elf_backend_count_relocs: New field: Function for determining + the number of relocs to be emitted. + * elfxx-target.h: Provide default (NULL) values for + elf_backend_emit_relocs and elf_backend_count_relocs. + * elflink.h (elf_link_size_reloc_section): Make the hash table + big enough to hold the relocs counted by either reloc_count or + o->reloc_count. + (elf_bfd_final_link) emit_relocs: New boolean, set if relocs + should be emitted, either because of a command line option + stored in the info structure or because the target provides a + special reloc emitting function. + If the target provides a reloc counting function use it, + unless performing a relocatable link or emitting all relocs. + Also set the SEC_RELOC flag on any output section which will + contain relocs. + (elf_link_input_bfd): emit_relocs: New boolean, set if relocs + should be emitted, either because of a command line option + stored in the info structure or because the target provides a + special reloc emitting function. + If the target provides a reloc emitting function, use it, + unless performing a relocatable link or emitting all relocs. 2001-06-20 H.J. Lu @@ -209,13 +232,13 @@ function. Move flagword result into parameter list. Remove comment about setting bfd_error_handler to intercept failure results. - * coffgen.c (make_a_section_from_file): Examine result of + * coffgen.c (make_a_section_from_file): Examine result of calling bfd_coff_styp_to_sec_flags and pass a failure back to caller. - * ecoff.h (styp_flags_to_sec_flags): Change to a boolean + * ecoff.h (styp_flags_to_sec_flags): Change to a boolean function. Move flagword result into parameter list. - * libcoff.h: Regenerate. - * libecoff.h: Regenerate. + * libcoff.h: Regenerate. + * libecoff.h: Regenerate. 2001-06-13 Nick Clifton @@ -224,10 +247,10 @@ 2001-06-12 Catherine Moore - * elflink.h (elf_gc_propagate_vtable_entries): Replace FILE_ALIGN - with the file_align entry from elf_backend_data. - (elf_gc_smash_unused_vtentry_relocs): Likewise. - (elf_gc_record_vtentry): Likewise. + * elflink.h (elf_gc_propagate_vtable_entries): Replace FILE_ALIGN + with the file_align entry from elf_backend_data. + (elf_gc_smash_unused_vtentry_relocs): Likewise. + (elf_gc_record_vtentry): Likewise. 2001-06-10 Alan Modra @@ -275,7 +298,7 @@ 2001-06-06 Christian Groessler - * coff-z8k.c: Fix formatting. + * coff-z8k.c: Fix formatting. Fix howtos: howto->size was always 1. 2001-06-05 Thiemo Seufer @@ -468,7 +491,7 @@ 2001-05-24 Tom Rix - * Makefile.am coff-pmac bfd now defined in coff-rs6000.c + * Makefile.am coff-pmac bfd now defined in coff-rs6000.c xcoff-target.h not used to define rs6000 or ppc bfd. * Makefile.in same @@ -546,13 +569,13 @@ * elf-bfd.h (NUM_SHDR_ENTRIES): New macro: compute the number of entries in a structured section. - * elf.c: Use new macro. - * elf32-i386.c: Use new macro. - * elf32-mips.c: Use new macro. - * elf64-alpha.c: Use new macro. - * elf64-sparc.c: Use new macro. - * elfcode.h: Use new macro. - * elflink.h: Use new macro. + * elf.c: Use new macro. + * elf32-i386.c: Use new macro. + * elf32-mips.c: Use new macro. + * elf64-alpha.c: Use new macro. + * elf64-sparc.c: Use new macro. + * elfcode.h: Use new macro. + * elflink.h: Use new macro. 2001-05-23 Nick Clifton @@ -709,7 +732,7 @@ 2001-05-04 Nick Clifton * elf32-arm.h (elf32_arm_final_link_relocate): Set - EF_ARM_HASENTRY if the start address is set. + EF_ARM_HASENTRY if the start address is set. 2001-05-03 Nick Clifton @@ -750,7 +773,7 @@ 2001-05-02 Johan Rydberg - * elf32-openrisc.c (openrisc_elf_howto_table): Do not complain + * elf32-openrisc.c (openrisc_elf_howto_table): Do not complain about overflow in R_OPENRISC_LO_16_IN_INSN and R_OPENRISC_HI_16_IN_INSN.Index: bfd/elf32-openrisc.c @@ -992,31 +1015,31 @@ 2001-03-23 Nick Clifton * Makefile.am (BUILD_CFILES): New variable: List of C source - files created in build directory. - (BUILD_HFILES): New variable: List of header files created in - build directory. - (POTFILES): Delete. - (po/POTFILES.in): Replace rule with empty entry. - (po/SRC-POTFILES.in): New rule: Create a list of source files - in the source directory. - (po/BLD-POTFILES.in): New rule: Create a list of source files - in the build directory. - (MOSTLYCLEAN): Do not delete source files created in build - directory. - * Makefile.in: Regenerate. - * configure.in: Insert SRC-POTFILES.in and BLD-POTFILES.in - into po/Makefile. - * configure: Regenerate. - - * po/Make-in: Replace occurrences of POTFILES with SRC-POTFILES - and BLD_POTFILES. + files created in build directory. + (BUILD_HFILES): New variable: List of header files created in + build directory. + (POTFILES): Delete. + (po/POTFILES.in): Replace rule with empty entry. + (po/SRC-POTFILES.in): New rule: Create a list of source files + in the source directory. + (po/BLD-POTFILES.in): New rule: Create a list of source files + in the build directory. + (MOSTLYCLEAN): Do not delete source files created in build + directory. + * Makefile.in: Regenerate. + * configure.in: Insert SRC-POTFILES.in and BLD-POTFILES.in + into po/Makefile. + * configure: Regenerate. + + * po/Make-in: Replace occurrences of POTFILES with SRC-POTFILES + and BLD_POTFILES. Add .. to the search path when building bfd.pot. - Delete POTFILES when performing distclean. - Add comment describing why distclean is broken in maintainer mode. + Delete POTFILES when performing distclean. + Add comment describing why distclean is broken in maintainer mode. * po/POTFILES.in: Delete. * po/SRC-POTFILES.in: New file. * po/BLD-POTFILES.in: New file. - * po/bfd.pot: Regenerate. + * po/bfd.pot: Regenerate. 2001-03-22 Hans-Peter Nilsson @@ -1149,7 +1172,7 @@ of offset in BLX(1) instruction. * coff-arm.c (coff_arm_relocate_section): Clear bit zero of offset in BLX(1) instruction. - Fix formatting. + Fix formatting. 2001-03-06 Nick Clifton @@ -1207,7 +1230,7 @@ * coffcode.h (styp_to_sec_flags) [COFF_WITH_PE version]: Tidy up, replacing multiple if statements with a switch. - (handle_COMDAT): New function. + (handle_COMDAT): New function. 2001-02-26 H.J. Lu diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index a5693ff336a..f3405907758 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -628,6 +628,14 @@ struct elf_backend_data unsigned int (*elf_backend_count_relocs) PARAMS ((asection *, Elf_Internal_Rela *)); + /* This function, if defined, is called when an NT_PRSTATUS note is found + in a core file. */ + boolean (*elf_backend_grok_prstatus) PARAMS ((bfd *, Elf_Internal_Note *)); + + /* This function, if defined, is called when an NT_PSINFO or NT_PRPSINFO + note is found in a core file. */ + boolean (*elf_backend_grok_psinfo) PARAMS ((bfd *, Elf_Internal_Note *)); + /* The swapping table to use when dealing with ECOFF information. Used for the MIPS ELF .mdebug section. */ const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap; @@ -1098,6 +1106,9 @@ boolean _bfd_elf_create_got_section PARAMS ((bfd *, unsigned long _bfd_elf_link_renumber_dynsyms PARAMS ((bfd *, struct bfd_link_info *)); +boolean _bfd_elfcore_make_pseudosection PARAMS ((bfd *, char *, int, int)); +char *_bfd_elfcore_strndup PARAMS ((bfd *, char *, int)); + elf_linker_section_t *_bfd_elf_create_linker_section PARAMS ((bfd *abfd, struct bfd_link_info *info, diff --git a/bfd/elf.c b/bfd/elf.c index 191627c4aed..5b2114fb0c3 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5376,6 +5376,46 @@ elfcore_maybe_make_sect (abfd, name, sect) return true; } +/* Create a pseudosection containing SIZE bytes at FILEPOS. This + actually creates up to two pseudosections: + - For the single-threaded case, a section named NAME, unless + such a section already exists. + - For the multi-threaded case, a section named "NAME/PID", where + PID is elfcore_make_pid (abfd). + Both pseudosections have identical contents. */ +boolean +_bfd_elfcore_make_pseudosection (abfd, name, size, filepos) + bfd *abfd; + char *name; + int size; + int filepos; +{ + char buf[100]; + char *threaded_name; + asection *sect; + + /* Build the section name. */ + + sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); + threaded_name = bfd_alloc (abfd, strlen (buf) + 1); + if (threaded_name == NULL) + return false; + strcpy (threaded_name, buf); + + sect = bfd_make_section (abfd, threaded_name); + if (sect == NULL) + return false; + sect->_raw_size = size; + sect->filepos = filepos; + sect->flags = SEC_HAS_CONTENTS; + sect->alignment_power = 2; + + if (! elfcore_maybe_make_sect (abfd, name, sect)) + return false; + + return true; +} + /* prstatus_t exists on: solaris 2.5+ linux 2.[01] + glibc @@ -5388,9 +5428,6 @@ elfcore_grok_prstatus (abfd, note) bfd *abfd; Elf_Internal_Note *note; { - char buf[100]; - char *name; - asection *sect; int raw_size; int offset; @@ -5446,69 +5483,23 @@ elfcore_grok_prstatus (abfd, note) return true; } - /* Make a ".reg/999" section. */ - - sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); - name = bfd_alloc (abfd, strlen (buf) + 1); - if (name == NULL) - return false; - strcpy (name, buf); - - sect = bfd_make_section (abfd, name); - if (sect == NULL) - return false; - - sect->_raw_size = raw_size; - sect->filepos = note->descpos + offset; - - sect->flags = SEC_HAS_CONTENTS; - sect->alignment_power = 2; - - if (! elfcore_maybe_make_sect (abfd, ".reg", sect)) + /* Make a ".reg/999" section and a ".reg" section. */ + if (! _bfd_elfcore_make_pseudosection (abfd, ".reg", + raw_size, note->descpos + offset)); return false; return true; } #endif /* defined (HAVE_PRSTATUS_T) */ -/* Create a pseudosection containing the exact contents of NOTE. This - actually creates up to two pseudosections: - - For the single-threaded case, a section named NAME, unless - such a section already exists. - - For the multi-threaded case, a section named "NAME/PID", where - PID is elfcore_make_pid (abfd). - Both pseudosections have identical contents: the contents of NOTE. */ - +/* Create a pseudosection containing the exact contents of NOTE. */ static boolean elfcore_make_note_pseudosection (abfd, name, note) bfd *abfd; char *name; Elf_Internal_Note *note; { - char buf[100]; - char *threaded_name; - asection *sect; - - /* Build the section name. */ - - sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); - threaded_name = bfd_alloc (abfd, strlen (buf) + 1); - if (threaded_name == NULL) - return false; - strcpy (threaded_name, buf); - - sect = bfd_make_section (abfd, threaded_name); - if (sect == NULL) - return false; - sect->_raw_size = note->descsz; - sect->filepos = note->descpos; - sect->flags = SEC_HAS_CONTENTS; - sect->alignment_power = 2; - - if (! elfcore_maybe_make_sect (abfd, name, sect)) - return false; - - return true; + return _bfd_elfcore_make_pseudosection (abfd, name, note->descsz, note->descpos); } /* There isn't a consistent prfpregset_t across platforms, @@ -5549,14 +5540,12 @@ typedef psinfo32_t elfcore_psinfo32_t; #endif #endif -#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) - /* return a malloc'ed copy of a string at START which is at most MAX bytes long, possibly without a terminating '\0'. the copy will always have a terminating '\0'. */ -static char* -elfcore_strndup (abfd, start, max) +char* +_bfd_elfcore_strndup (abfd, start, max) bfd *abfd; char *start; int max; @@ -5580,6 +5569,8 @@ elfcore_strndup (abfd, start, max) return dup; } +#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) + static boolean elfcore_grok_psinfo (abfd, note) bfd *abfd; @@ -5592,10 +5583,10 @@ elfcore_grok_psinfo (abfd, note) memcpy (&psinfo, note->descdata, sizeof (psinfo)); elf_tdata (abfd)->core_program - = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); + = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); elf_tdata (abfd)->core_command - = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); + = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); } #if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T) else if (note->descsz == sizeof (elfcore_psinfo32_t)) @@ -5606,10 +5597,10 @@ elfcore_grok_psinfo (abfd, note) memcpy (&psinfo, note->descdata, sizeof (psinfo)); elf_tdata (abfd)->core_program - = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); + = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname)); elf_tdata (abfd)->core_command - = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); + = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs)); } #endif @@ -5841,14 +5832,21 @@ elfcore_grok_note (abfd, note) bfd *abfd; Elf_Internal_Note *note; { + struct elf_backend_data *bed = get_elf_backend_data (abfd); + switch (note->type) { default: return true; -#if defined (HAVE_PRSTATUS_T) case NT_PRSTATUS: + if (bed->elf_backend_grok_prstatus) + if ((*bed->elf_backend_grok_prstatus) (abfd, note)) + return true; +#if defined (HAVE_PRSTATUS_T) return elfcore_grok_prstatus (abfd, note); +#else + return true; #endif #if defined (HAVE_PSTATUS_T) @@ -5876,10 +5874,15 @@ elfcore_grok_note (abfd, note) else return true; -#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) case NT_PRPSINFO: case NT_PSINFO: + if (bed->elf_backend_grok_psinfo) + if ((*bed->elf_backend_grok_psinfo) (abfd, note)) + return true; +#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) return elfcore_grok_psinfo (abfd, note); +#else + return true; #endif } } diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index 0ac7b5ab5c0..44c2a4c9da5 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -9134,6 +9134,73 @@ _bfd_mips_elf_finish_dynamic_sections (output_bfd, info) return true; } +/* Support for core dump NOTE sections */ +static boolean +_bfd_elf32_mips_grok_prstatus (abfd, note) + bfd *abfd; + Elf_Internal_Note *note; +{ + int offset; + int raw_size; + + switch (note->descsz) + { + default: + return false; + + case 256: /* Linux/MIPS */ + /* pr_cursig */ + elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); + + /* pr_pid */ + elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); + + /* pr_reg */ + offset = 72; + raw_size = 180; + + break; + } + + /* Make a ".reg/999" section. */ + if (! _bfd_elfcore_make_pseudosection (abfd, ".reg", + raw_size, note->descpos + offset)) + return false; + + return true; +} + +static boolean _bfd_elf32_mips_grok_psinfo (abfd, note) + bfd *abfd; + Elf_Internal_Note *note; +{ + switch (note->descsz) + { + default: + return false; + + case 128: /* Linux/MIPS elf_prpsinfo */ + elf_tdata (abfd)->core_program + = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); + elf_tdata (abfd)->core_command + = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); + } + + /* Note that for some reason, a spurious space is tacked + onto the end of the args in some (at least one anyway) + implementations, so strip it off if it exists. */ + + { + char *command = elf_tdata (abfd)->core_command; + int n = strlen (command); + + if (0 < n && command[n - 1] == ' ') + command[n - 1] = '\0'; + } + + return true; +} + /* This is almost identical to bfd_generic_get_... except that some MIPS relocations need to be handled specially. Sigh. */ @@ -9421,6 +9488,8 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = { _bfd_mips_elf_copy_indirect_symbol #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol +#define elf_backend_grok_prstatus _bfd_elf32_mips_grok_prstatus +#define elf_backend_grok_psinfo _bfd_elf32_mips_grok_psinfo #define bfd_elf32_bfd_is_local_label_name \ mips_elf_is_local_label_name diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 8258a6add98..5f413d2be96 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -329,6 +329,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef elf_backend_count_relocs #define elf_backend_count_relocs NULL #endif +#ifndef elf_backend_grok_prstatus +#define elf_backend_grok_prstatus NULL +#endif +#ifndef elf_backend_grok_psinfo +#define elf_backend_grok_psinfo NULL +#endif /* Previously, backends could only use SHT_REL or SHT_RELA relocation sections, but not both. They defined USE_REL to indicate SHT_REL @@ -412,6 +418,8 @@ static CONST struct elf_backend_data elfNN_bed = elf_backend_hide_symbol, elf_backend_emit_relocs, elf_backend_count_relocs, + elf_backend_grok_prstatus, + elf_backend_grok_psinfo, elf_backend_ecoff_debug_swap, ELF_MACHINE_ALT1, ELF_MACHINE_ALT2, -- 2.30.2