From ded962a7a5690f61c859738ee8fb3e50aee146b7 Mon Sep 17 00:00:00 2001 From: kevinb Date: Mon, 30 Oct 2000 23:31:16 +0000 Subject: [PATCH] solib.c relocation improvements --- gdb/ChangeLog | 26 ++++++++++++++++++++++++ gdb/solib-svr4.c | 10 ++++++++- gdb/solib.c | 62 +++++++++++++++++--------------------------------------- gdb/solist.h | 24 +++++++++++++++++++--- 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 667a3be8cb..3109ba83c8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,29 @@ +2000-10-30 Kevin Buettner + + Changes based on analysis from Peter Schauer: + * solist.h (struct so_list): Remove field lmend. + (struct target_so_ops): Remove field lm_addr. Add field + relocate_section_addresses. Add comments for all fields + in this structure + (TARGET_SO_LM_ADDR): Remove. + (TARGET_SO_RELOCATE_SECTION_ADDRESSES): New macro. + * solib-svr4.c (svr4_relocate_section_addresses): New function. + (_initialize_svr4_solib): Remove lm_addr initialization. Add + initialization for relocate_section_addresses. + * solib.c (solib_map_sections): Invoke + TARGET_SO_RELOCATE_SECTION_ADDRESSES instead of using now + defunct TARGET_SO_LM_ADDR to relocate the section addresses. + Also, eliminate assignment to the lmend field since this + field no longer exists. + (symbol_add_stub): Remove machinery for determining the lowest + section. + (info_sharedlibrary_command): Print the text section starting + and ending addresses. + (solib_address): Don't use TARGET_SO_LM_ADDR, nor so->lmend to + determine if an address is in a shared object. Instead, scan + the section table and test against the starting and ending + addresses for each section. + 2000-10-30 Michael Snyder * config/m68k/linux.mh: Remove solib.c, solib-svr4.c from NATDEPFILES. diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 13fea47e52..b5a0725480 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1567,12 +1567,20 @@ svr4_free_so (struct so_list *so) free (so->lm_info); } +static void +svr4_relocate_section_addresses (struct so_list *so, + struct section_table *sec) +{ + sec->addr += LM_ADDR (so); + sec->endaddr += LM_ADDR (so); +} + static struct target_so_ops svr4_so_ops; void _initialize_svr4_solib (void) { - svr4_so_ops.lm_addr = LM_ADDR; + svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses; svr4_so_ops.free_so = svr4_free_so; svr4_so_ops.clear_solib = svr4_clear_solib; svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook; diff --git a/gdb/solib.c b/gdb/solib.c index 7efc56eb8e..7da15b9370 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -180,9 +180,7 @@ solib_map_sections (PTR arg) /* Relocate the section binding addresses as recorded in the shared object's file by the base address to which the object was actually mapped. */ - p->addr += TARGET_SO_LM_ADDR (so); - p->endaddr += TARGET_SO_LM_ADDR (so); - so->lmend = max (p->endaddr, so->lmend); + TARGET_SO_RELOCATE_SECTION_ADDRESSES (so, p); if (STREQ (p->the_bfd_section->name, ".text")) { so->textsection = p; @@ -248,9 +246,6 @@ symbol_add_stub (PTR arg) { register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */ struct section_addr_info *sap; - CORE_ADDR lowest_addr = 0; - int lowest_index; - asection *lowest_sect = NULL; /* Have we already loaded this shared object? */ ALL_OBJFILES (so->objfile) @@ -259,35 +254,9 @@ symbol_add_stub (PTR arg) return 1; } - /* Find the shared object's text segment. */ - if (so->textsection) - { - lowest_addr = so->textsection->addr; - lowest_sect = bfd_get_section_by_name (so->abfd, ".text"); - lowest_index = lowest_sect->index; - } - else if (so->abfd != NULL) - { - /* If we didn't find a mapped non zero sized .text section, set - up lowest_addr so that the relocation in symbol_file_add does - no harm. */ - lowest_sect = bfd_get_section_by_name (so->abfd, ".text"); - if (lowest_sect == NULL) - bfd_map_over_sections (so->abfd, find_lowest_section, - (PTR) &lowest_sect); - if (lowest_sect) - { - lowest_addr = bfd_section_vma (so->abfd, lowest_sect) - + TARGET_SO_LM_ADDR (so); - lowest_index = lowest_sect->index; - } - } - sap = build_section_addr_info_from_section_table (so->sections, so->sections_end); - sap->other[lowest_index].addr = lowest_addr; - so->objfile = symbol_file_add (so->so_name, so->from_tty, sap, 0, OBJF_SHARED); free_section_addr_info (sap); @@ -610,12 +579,17 @@ info_sharedlibrary_command (char *ignore, int from_tty) } printf_unfiltered ("%-*s", addr_width, - local_hex_string_custom ( - (unsigned long) TARGET_SO_LM_ADDR (so), - addr_fmt)); + so->textsection != NULL + ? local_hex_string_custom ( + (unsigned long) so->textsection->addr, + addr_fmt) + : ""); printf_unfiltered ("%-*s", addr_width, - local_hex_string_custom ((unsigned long) so->lmend, - addr_fmt)); + so->textsection != NULL + ? local_hex_string_custom ( + (unsigned long) so->textsection->endaddr, + addr_fmt) + : ""); printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No"); printf_unfiltered ("%s\n", so->so_name); } @@ -640,10 +614,7 @@ info_sharedlibrary_command (char *ignore, int from_tty) Provides a hook for other gdb routines to discover whether or not a particular address is within the mapped address space of - a shared library. Any address between the base mapping address - and the first address beyond the end of the last mapping, is - considered to be within the shared library address space, for - our purposes. + a shared library. For example, this routine is called at one point to disable breakpoints which are in shared libraries that are not currently @@ -657,8 +628,13 @@ solib_address (CORE_ADDR address) for (so = so_list_head; so; so = so->next) { - if (TARGET_SO_LM_ADDR (so) <= address && address < so->lmend) - return (so->so_name); + struct section_table *p; + + for (p = so->sections; p < so->sections_end; p++) + { + if (p->addr <= address && address < p->endaddr) + return (so->so_name); + } } return (0); diff --git a/gdb/solist.h b/gdb/solist.h index 784ea1bed0..e55190dc8a 100644 --- a/gdb/solist.h +++ b/gdb/solist.h @@ -54,7 +54,6 @@ struct so_list are initialized when we actually add it to our symbol tables. */ bfd *abfd; - CORE_ADDR lmend; /* upper addr bound of mapped object */ char symbols_loaded; /* flag: symbols read in yet? */ char from_tty; /* flag: print msgs? */ struct objfile *objfile; /* objfile for loaded lib */ @@ -65,12 +64,30 @@ struct so_list struct target_so_ops { - CORE_ADDR (*lm_addr) (struct so_list *so); + /* Adjust the section binding addresses by the base address at + which the object was actually mapped. */ + void (*relocate_section_addresses) (struct so_list *so, + struct section_table *); + + /* Free the the link map info and any other private data + structures associated with a so_list entry. */ void (*free_so) (struct so_list *so); + + /* Reset or free private data structures not associated with + so_list entries. */ void (*clear_solib) (void); + + /* Target dependent code to run after child process fork. */ void (*solib_create_inferior_hook) (void); + + /* Do additional symbol handling, lookup, etc. after symbols + for a shared object have been loaded. */ void (*special_symbol_handling) (void); + + /* Construct a list of the currently loaded shared objects. */ struct so_list *(*current_sos) (void); + + /* Find, open, and read the symbols for the main executable. */ int (*open_symbol_file_object) (void *from_ttyp); }; @@ -79,7 +96,8 @@ void free_so (struct so_list *so); /* FIXME: gdbarch needs to control this variable */ extern struct target_so_ops *current_target_so_ops; -#define TARGET_SO_LM_ADDR (current_target_so_ops->lm_addr) +#define TARGET_SO_RELOCATE_SECTION_ADDRESSES \ + (current_target_so_ops->relocate_section_addresses) #define TARGET_SO_FREE_SO (current_target_so_ops->free_so) #define TARGET_SO_CLEAR_SOLIB (current_target_so_ops->clear_solib) #define TARGET_SO_SOLIB_CREATE_INFERIOR_HOOK \ -- 2.11.0