1 /* Handle SVR4 shared libraries for GDB, the GNU Debugger.
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
4 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "elf/external.h"
25 #include "elf/common.h"
35 #include "gdbthread.h"
37 #include "gdb_assert.h"
41 #include "solib-svr4.h"
43 #include "bfd-target.h"
47 #include "exceptions.h"
49 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
50 static int svr4_have_link_map_offsets (void);
52 /* Link map info to include in an allocated so_list entry */
56 /* Pointer to copy of link map from inferior. The type is char *
57 rather than void *, so that we may use byte offsets to find the
58 various fields without the need for a cast. */
61 /* Amount by which addresses in the binary should be relocated to
62 match the inferior. This could most often be taken directly
63 from lm, but when prelinking is involved and the prelink base
64 address changes, we may need a different offset, we want to
65 warn about the difference and compute it only once. */
68 /* The target location of lm. */
72 /* On SVR4 systems, a list of symbols in the dynamic linker where
73 GDB can try to place a breakpoint to monitor shared library
76 If none of these symbols are found, or other errors occur, then
77 SVR4 systems will fall back to using a symbol as the "startup
78 mapping complete" breakpoint address. */
80 static char *solib_break_names[] =
91 static char *bkpt_names[] =
99 static char *main_name_list[] =
105 /* Return non-zero if GDB_SO_NAME and INFERIOR_SO_NAME represent
106 the same shared library. */
109 svr4_same_1 (const char *gdb_so_name, const char *inferior_so_name)
111 if (strcmp (gdb_so_name, inferior_so_name) == 0)
114 /* On Solaris, when starting inferior we think that dynamic linker is
115 /usr/lib/ld.so.1, but later on, the table of loaded shared libraries
116 contains /lib/ld.so.1. Sometimes one file is a link to another, but
117 sometimes they have identical content, but are not linked to each
118 other. We don't restrict this check for Solaris, but the chances
119 of running into this situation elsewhere are very low. */
120 if (strcmp (gdb_so_name, "/usr/lib/ld.so.1") == 0
121 && strcmp (inferior_so_name, "/lib/ld.so.1") == 0)
124 /* Similarly, we observed the same issue with sparc64, but with
125 different locations. */
126 if (strcmp (gdb_so_name, "/usr/lib/sparcv9/ld.so.1") == 0
127 && strcmp (inferior_so_name, "/lib/sparcv9/ld.so.1") == 0)
134 svr4_same (struct so_list *gdb, struct so_list *inferior)
136 return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
139 /* link map access functions */
142 LM_ADDR_FROM_LINK_MAP (struct so_list *so)
144 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
145 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
147 return extract_typed_address (so->lm_info->lm + lmo->l_addr_offset,
152 HAS_LM_DYNAMIC_FROM_LINK_MAP (void)
154 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
156 return lmo->l_ld_offset >= 0;
160 LM_DYNAMIC_FROM_LINK_MAP (struct so_list *so)
162 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
163 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
165 return extract_typed_address (so->lm_info->lm + lmo->l_ld_offset,
170 LM_ADDR_CHECK (struct so_list *so, bfd *abfd)
172 if (so->lm_info->l_addr == (CORE_ADDR)-1)
174 struct bfd_section *dyninfo_sect;
175 CORE_ADDR l_addr, l_dynaddr, dynaddr, align = 0x1000;
177 l_addr = LM_ADDR_FROM_LINK_MAP (so);
179 if (! abfd || ! HAS_LM_DYNAMIC_FROM_LINK_MAP ())
182 l_dynaddr = LM_DYNAMIC_FROM_LINK_MAP (so);
184 dyninfo_sect = bfd_get_section_by_name (abfd, ".dynamic");
185 if (dyninfo_sect == NULL)
188 dynaddr = bfd_section_vma (abfd, dyninfo_sect);
190 if (dynaddr + l_addr != l_dynaddr)
192 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
194 Elf_Internal_Ehdr *ehdr = elf_tdata (abfd)->elf_header;
195 Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr;
200 for (i = 0; i < ehdr->e_phnum; i++)
201 if (phdr[i].p_type == PT_LOAD && phdr[i].p_align > align)
202 align = phdr[i].p_align;
205 /* Turn it into a mask. */
208 /* If the changes match the alignment requirements, we
209 assume we're using a core file that was generated by the
210 same binary, just prelinked with a different base offset.
211 If it doesn't match, we may have a different binary, the
212 same binary with the dynamic table loaded at an unrelated
213 location, or anything, really. To avoid regressions,
214 don't adjust the base offset in the latter case, although
215 odds are that, if things really changed, debugging won't
217 if ((l_addr & align) == ((l_dynaddr - dynaddr) & align))
219 l_addr = l_dynaddr - dynaddr;
221 warning (_(".dynamic section for \"%s\" "
222 "is not at the expected address"), so->so_name);
223 warning (_("difference appears to be caused by prelink, "
224 "adjusting expectations"));
227 warning (_(".dynamic section for \"%s\" "
228 "is not at the expected address "
229 "(wrong library or version mismatch?)"), so->so_name);
233 so->lm_info->l_addr = l_addr;
236 return so->lm_info->l_addr;
240 LM_NEXT (struct so_list *so)
242 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
243 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
245 return extract_typed_address (so->lm_info->lm + lmo->l_next_offset,
250 LM_NAME (struct so_list *so)
252 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
253 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
255 return extract_typed_address (so->lm_info->lm + lmo->l_name_offset,
260 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list *so)
262 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
263 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
265 /* Assume that everything is a library if the dynamic loader was loaded
266 late by a static executable. */
267 if (bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
270 return extract_typed_address (so->lm_info->lm + lmo->l_prev_offset,
274 static CORE_ADDR debug_base; /* Base of dynamic linker structures */
276 /* Validity flag for debug_loader_offset. */
277 static int debug_loader_offset_p;
279 /* Load address for the dynamic linker, inferred. */
280 static CORE_ADDR debug_loader_offset;
282 /* Name of the dynamic linker, valid if debug_loader_offset_p. */
283 static char *debug_loader_name;
285 /* Load map address for the main executable. */
286 static CORE_ADDR main_lm_addr;
288 /* Local function prototypes */
290 static int match_main (char *);
292 static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
298 bfd_lookup_symbol -- lookup the value for a specific symbol
302 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
306 An expensive way to lookup the value of a single symbol for
307 bfd's that are only temporary anyway. This is used by the
308 shared library support to find the address of the debugger
309 notification routine in the shared library.
311 The returned symbol may be in a code or data section; functions
312 will normally be in a code section, but may be in a data section
313 if this architecture uses function descriptors.
315 Note that 0 is specifically allowed as an error return (no
320 bfd_lookup_symbol (bfd *abfd, char *symname)
324 asymbol **symbol_table;
325 unsigned int number_of_symbols;
327 struct cleanup *back_to;
328 CORE_ADDR symaddr = 0;
330 storage_needed = bfd_get_symtab_upper_bound (abfd);
332 if (storage_needed > 0)
334 symbol_table = (asymbol **) xmalloc (storage_needed);
335 back_to = make_cleanup (xfree, symbol_table);
336 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
338 for (i = 0; i < number_of_symbols; i++)
340 sym = *symbol_table++;
341 if (strcmp (sym->name, symname) == 0
342 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
344 /* BFD symbols are section relative. */
345 symaddr = sym->value + sym->section->vma;
349 do_cleanups (back_to);
355 /* On FreeBSD, the dynamic linker is stripped by default. So we'll
356 have to check the dynamic string table too. */
358 storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
360 if (storage_needed > 0)
362 symbol_table = (asymbol **) xmalloc (storage_needed);
363 back_to = make_cleanup (xfree, symbol_table);
364 number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
366 for (i = 0; i < number_of_symbols; i++)
368 sym = *symbol_table++;
370 if (strcmp (sym->name, symname) == 0
371 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
373 /* BFD symbols are section relative. */
374 symaddr = sym->value + sym->section->vma;
378 do_cleanups (back_to);
385 /* Read program header TYPE from inferior memory. The header is found
386 by scanning the OS auxillary vector.
388 Return a pointer to allocated memory holding the program header contents,
389 or NULL on failure. If sucessful, and unless P_SECT_SIZE is NULL, the
390 size of those contents is returned to P_SECT_SIZE. Likewise, the target
391 architecture size (32-bit or 64-bit) is returned to P_ARCH_SIZE. */
394 read_program_header (int type, int *p_sect_size, int *p_arch_size)
396 CORE_ADDR at_phdr, at_phent, at_phnum;
397 int arch_size, sect_size;
401 /* Get required auxv elements from target. */
402 if (target_auxv_search (¤t_target, AT_PHDR, &at_phdr) <= 0)
404 if (target_auxv_search (¤t_target, AT_PHENT, &at_phent) <= 0)
406 if (target_auxv_search (¤t_target, AT_PHNUM, &at_phnum) <= 0)
408 if (!at_phdr || !at_phnum)
411 /* Determine ELF architecture type. */
412 if (at_phent == sizeof (Elf32_External_Phdr))
414 else if (at_phent == sizeof (Elf64_External_Phdr))
419 /* Find .dynamic section via the PT_DYNAMIC PHDR. */
422 Elf32_External_Phdr phdr;
425 /* Search for requested PHDR. */
426 for (i = 0; i < at_phnum; i++)
428 if (target_read_memory (at_phdr + i * sizeof (phdr),
429 (gdb_byte *)&phdr, sizeof (phdr)))
432 if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, 4) == type)
439 /* Retrieve address and size. */
440 sect_addr = extract_unsigned_integer ((gdb_byte *)phdr.p_vaddr, 4);
441 sect_size = extract_unsigned_integer ((gdb_byte *)phdr.p_memsz, 4);
445 Elf64_External_Phdr phdr;
448 /* Search for requested PHDR. */
449 for (i = 0; i < at_phnum; i++)
451 if (target_read_memory (at_phdr + i * sizeof (phdr),
452 (gdb_byte *)&phdr, sizeof (phdr)))
455 if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, 4) == type)
462 /* Retrieve address and size. */
463 sect_addr = extract_unsigned_integer ((gdb_byte *)phdr.p_vaddr, 8);
464 sect_size = extract_unsigned_integer ((gdb_byte *)phdr.p_memsz, 8);
467 /* Read in requested program header. */
468 buf = xmalloc (sect_size);
469 if (target_read_memory (sect_addr, buf, sect_size))
476 *p_arch_size = arch_size;
478 *p_sect_size = sect_size;
484 /* Return program interpreter string. */
486 find_program_interpreter (void)
488 gdb_byte *buf = NULL;
490 /* If we have an exec_bfd, use its section table. */
492 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
494 struct bfd_section *interp_sect;
496 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
497 if (interp_sect != NULL)
499 CORE_ADDR sect_addr = bfd_section_vma (exec_bfd, interp_sect);
500 int sect_size = bfd_section_size (exec_bfd, interp_sect);
502 buf = xmalloc (sect_size);
503 bfd_get_section_contents (exec_bfd, interp_sect, buf, 0, sect_size);
507 /* If we didn't find it, use the target auxillary vector. */
509 buf = read_program_header (PT_INTERP, NULL, NULL);
515 /* Scan for DYNTAG in .dynamic section of ABFD. If DYNTAG is found 1 is
516 returned and the corresponding PTR is set. */
519 scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
521 int arch_size, step, sect_size;
523 CORE_ADDR dyn_ptr, dyn_addr;
524 gdb_byte *bufend, *bufstart, *buf;
525 Elf32_External_Dyn *x_dynp_32;
526 Elf64_External_Dyn *x_dynp_64;
527 struct bfd_section *sect;
531 arch_size = bfd_get_arch_size (abfd);
535 /* Find the start address of the .dynamic section. */
536 sect = bfd_get_section_by_name (abfd, ".dynamic");
539 dyn_addr = bfd_section_vma (abfd, sect);
541 /* Read in .dynamic from the BFD. We will get the actual value
542 from memory later. */
543 sect_size = bfd_section_size (abfd, sect);
544 buf = bufstart = alloca (sect_size);
545 if (!bfd_get_section_contents (abfd, sect,
549 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
550 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
551 : sizeof (Elf64_External_Dyn);
552 for (bufend = buf + sect_size;
558 x_dynp_32 = (Elf32_External_Dyn *) buf;
559 dyn_tag = bfd_h_get_32 (abfd, (bfd_byte *) x_dynp_32->d_tag);
560 dyn_ptr = bfd_h_get_32 (abfd, (bfd_byte *) x_dynp_32->d_un.d_ptr);
564 x_dynp_64 = (Elf64_External_Dyn *) buf;
565 dyn_tag = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_tag);
566 dyn_ptr = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_un.d_ptr);
568 if (dyn_tag == DT_NULL)
570 if (dyn_tag == dyntag)
572 /* If requested, try to read the runtime value of this .dynamic
576 struct type *ptr_type;
580 ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
581 ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
582 if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0)
583 dyn_ptr = extract_typed_address (ptr_buf, ptr_type);
593 /* Scan for DYNTAG in .dynamic section of the target's main executable,
594 found by consulting the OS auxillary vector. If DYNTAG is found 1 is
595 returned and the corresponding PTR is set. */
598 scan_dyntag_auxv (int dyntag, CORE_ADDR *ptr)
600 int sect_size, arch_size, step;
603 gdb_byte *bufend, *bufstart, *buf;
605 /* Read in .dynamic section. */
606 buf = bufstart = read_program_header (PT_DYNAMIC, §_size, &arch_size);
610 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
611 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
612 : sizeof (Elf64_External_Dyn);
613 for (bufend = buf + sect_size;
619 Elf32_External_Dyn *dynp = (Elf32_External_Dyn *) buf;
620 dyn_tag = extract_unsigned_integer ((gdb_byte *) dynp->d_tag, 4);
621 dyn_ptr = extract_unsigned_integer ((gdb_byte *) dynp->d_un.d_ptr, 4);
625 Elf64_External_Dyn *dynp = (Elf64_External_Dyn *) buf;
626 dyn_tag = extract_unsigned_integer ((gdb_byte *) dynp->d_tag, 8);
627 dyn_ptr = extract_unsigned_integer ((gdb_byte *) dynp->d_un.d_ptr, 8);
629 if (dyn_tag == DT_NULL)
632 if (dyn_tag == dyntag)
651 elf_locate_base -- locate the base address of dynamic linker structs
652 for SVR4 elf targets.
656 CORE_ADDR elf_locate_base (void)
660 For SVR4 elf targets the address of the dynamic linker's runtime
661 structure is contained within the dynamic info section in the
662 executable file. The dynamic section is also mapped into the
663 inferior address space. Because the runtime loader fills in the
664 real address before starting the inferior, we have to read in the
665 dynamic info section from the inferior address space.
666 If there are any errors while trying to find the address, we
667 silently return 0, otherwise the found address is returned.
672 elf_locate_base (void)
674 struct minimal_symbol *msymbol;
677 /* Look for DT_MIPS_RLD_MAP first. MIPS executables use this
678 instead of DT_DEBUG, although they sometimes contain an unused
680 if (scan_dyntag (DT_MIPS_RLD_MAP, exec_bfd, &dyn_ptr)
681 || scan_dyntag_auxv (DT_MIPS_RLD_MAP, &dyn_ptr))
683 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
685 int pbuf_size = TYPE_LENGTH (ptr_type);
686 pbuf = alloca (pbuf_size);
687 /* DT_MIPS_RLD_MAP contains a pointer to the address
688 of the dynamic link structure. */
689 if (target_read_memory (dyn_ptr, pbuf, pbuf_size))
691 return extract_typed_address (pbuf, ptr_type);
695 if (scan_dyntag (DT_DEBUG, exec_bfd, &dyn_ptr)
696 || scan_dyntag_auxv (DT_DEBUG, &dyn_ptr))
699 /* This may be a static executable. Look for the symbol
700 conventionally named _r_debug, as a last resort. */
701 msymbol = lookup_minimal_symbol ("_r_debug", NULL, symfile_objfile);
703 return SYMBOL_VALUE_ADDRESS (msymbol);
705 /* DT_DEBUG entry not found. */
713 locate_base -- locate the base address of dynamic linker structs
717 CORE_ADDR locate_base (void)
721 For both the SunOS and SVR4 shared library implementations, if the
722 inferior executable has been linked dynamically, there is a single
723 address somewhere in the inferior's data space which is the key to
724 locating all of the dynamic linker's runtime structures. This
725 address is the value of the debug base symbol. The job of this
726 function is to find and return that address, or to return 0 if there
727 is no such address (the executable is statically linked for example).
729 For SunOS, the job is almost trivial, since the dynamic linker and
730 all of it's structures are statically linked to the executable at
731 link time. Thus the symbol for the address we are looking for has
732 already been added to the minimal symbol table for the executable's
733 objfile at the time the symbol file's symbols were read, and all we
734 have to do is look it up there. Note that we explicitly do NOT want
735 to find the copies in the shared library.
737 The SVR4 version is a bit more complicated because the address
738 is contained somewhere in the dynamic info section. We have to go
739 to a lot more work to discover the address of the debug base symbol.
740 Because of this complexity, we cache the value we find and return that
741 value on subsequent invocations. Note there is no copy in the
742 executable symbol tables.
749 /* Check to see if we have a currently valid address, and if so, avoid
750 doing all this work again and just return the cached address. If
751 we have no cached address, try to locate it in the dynamic info
752 section for ELF executables. There's no point in doing any of this
753 though if we don't have some link map offsets to work with. */
755 if (debug_base == 0 && svr4_have_link_map_offsets ())
758 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
759 debug_base = elf_locate_base ();
764 /* Find the first element in the inferior's dynamic link map, and
765 return its address in the inferior.
767 FIXME: Perhaps we should validate the info somehow, perhaps by
768 checking r_version for a known version number, or r_state for
772 solib_svr4_r_map (void)
774 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
775 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
777 return read_memory_typed_address (debug_base + lmo->r_map_offset, ptr_type);
780 /* Find r_brk from the inferior's debug base. */
783 solib_svr4_r_brk (void)
785 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
786 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
788 return read_memory_typed_address (debug_base + lmo->r_brk_offset, ptr_type);
791 /* Find the link map for the dynamic linker (if it is not in the
792 normal list of loaded shared objects). */
795 solib_svr4_r_ldsomap (void)
797 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
798 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
801 /* Check version, and return zero if `struct r_debug' doesn't have
802 the r_ldsomap member. */
803 version = read_memory_unsigned_integer (debug_base + lmo->r_version_offset,
804 lmo->r_version_size);
805 if (version < 2 || lmo->r_ldsomap_offset == -1)
808 return read_memory_typed_address (debug_base + lmo->r_ldsomap_offset,
816 open_symbol_file_object
820 void open_symbol_file_object (void *from_tty)
824 If no open symbol file, attempt to locate and open the main symbol
825 file. On SVR4 systems, this is the first link map entry. If its
826 name is here, we can open it. Useful when attaching to a process
827 without first loading its symbol file.
829 If FROM_TTYP dereferences to a non-zero integer, allow messages to
830 be printed. This parameter is a pointer rather than an int because
831 open_symbol_file_object() is called via catch_errors() and
832 catch_errors() requires a pointer argument. */
835 open_symbol_file_object (void *from_ttyp)
837 CORE_ADDR lm, l_name;
840 int from_tty = *(int *)from_ttyp;
841 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
842 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
843 int l_name_size = TYPE_LENGTH (ptr_type);
844 gdb_byte *l_name_buf = xmalloc (l_name_size);
845 struct cleanup *cleanups = make_cleanup (xfree, l_name_buf);
848 if (!query (_("Attempt to reload symbols from process? ")))
851 /* Always locate the debug struct, in case it has moved. */
853 if (locate_base () == 0)
854 return 0; /* failed somehow... */
856 /* First link map member should be the executable. */
857 lm = solib_svr4_r_map ();
859 return 0; /* failed somehow... */
861 /* Read address of name from target memory to GDB. */
862 read_memory (lm + lmo->l_name_offset, l_name_buf, l_name_size);
864 /* Convert the address to host format. */
865 l_name = extract_typed_address (l_name_buf, ptr_type);
867 /* Free l_name_buf. */
868 do_cleanups (cleanups);
871 return 0; /* No filename. */
873 /* Now fetch the filename from target memory. */
874 target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
875 make_cleanup (xfree, filename);
879 warning (_("failed to read exec filename from attached file: %s"),
880 safe_strerror (errcode));
884 /* Have a pathname: read the symbol file. */
885 symbol_file_add_main (filename, from_tty);
890 /* If no shared library information is available from the dynamic
891 linker, build a fallback list from other sources. */
893 static struct so_list *
894 svr4_default_sos (void)
896 struct so_list *head = NULL;
897 struct so_list **link_ptr = &head;
899 if (debug_loader_offset_p)
901 struct so_list *new = XZALLOC (struct so_list);
903 new->lm_info = xmalloc (sizeof (struct lm_info));
905 /* Nothing will ever check the cached copy of the link
906 map if we set l_addr. */
907 new->lm_info->l_addr = debug_loader_offset;
908 new->lm_info->lm_addr = 0;
909 new->lm_info->lm = NULL;
911 strncpy (new->so_name, debug_loader_name, SO_NAME_MAX_PATH_SIZE - 1);
912 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
913 strcpy (new->so_original_name, new->so_name);
916 link_ptr = &new->next;
924 current_sos -- build a list of currently loaded shared objects
928 struct so_list *current_sos ()
932 Build a list of `struct so_list' objects describing the shared
933 objects currently loaded in the inferior. This list does not
934 include an entry for the main executable file.
936 Note that we only gather information directly available from the
937 inferior --- we don't examine any of the shared library files
938 themselves. The declaration of `struct so_list' says which fields
939 we provide values for. */
941 static struct so_list *
942 svr4_current_sos (void)
945 struct so_list *head = 0;
946 struct so_list **link_ptr = &head;
947 CORE_ADDR ldsomap = 0;
949 /* Always locate the debug struct, in case it has moved. */
953 /* If we can't find the dynamic linker's base structure, this
954 must not be a dynamically linked executable. Hmm. */
956 return svr4_default_sos ();
958 /* Walk the inferior's link map list, and build our list of
959 `struct so_list' nodes. */
960 lm = solib_svr4_r_map ();
964 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
965 struct so_list *new = XZALLOC (struct so_list);
966 struct cleanup *old_chain = make_cleanup (xfree, new);
968 new->lm_info = xmalloc (sizeof (struct lm_info));
969 make_cleanup (xfree, new->lm_info);
971 new->lm_info->l_addr = (CORE_ADDR)-1;
972 new->lm_info->lm_addr = lm;
973 new->lm_info->lm = xzalloc (lmo->link_map_size);
974 make_cleanup (xfree, new->lm_info->lm);
976 read_memory (lm, new->lm_info->lm, lmo->link_map_size);
980 /* For SVR4 versions, the first entry in the link map is for the
981 inferior executable, so we must ignore it. For some versions of
982 SVR4, it has no name. For others (Solaris 2.3 for example), it
983 does have a name, so we can no longer use a missing name to
984 decide when to ignore it. */
985 if (IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
987 main_lm_addr = new->lm_info->lm_addr;
995 /* Extract this shared object's name. */
996 target_read_string (LM_NAME (new), &buffer,
997 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
999 warning (_("Can't read pathname for load map: %s."),
1000 safe_strerror (errcode));
1003 strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
1004 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
1005 strcpy (new->so_original_name, new->so_name);
1009 /* If this entry has no name, or its name matches the name
1010 for the main executable, don't include it in the list. */
1011 if (! new->so_name[0]
1012 || match_main (new->so_name))
1018 link_ptr = &new->next;
1022 /* On Solaris, the dynamic linker is not in the normal list of
1023 shared objects, so make sure we pick it up too. Having
1024 symbol information for the dynamic linker is quite crucial
1025 for skipping dynamic linker resolver code. */
1026 if (lm == 0 && ldsomap == 0)
1027 lm = ldsomap = solib_svr4_r_ldsomap ();
1029 discard_cleanups (old_chain);
1033 return svr4_default_sos ();
1038 /* Get the address of the link_map for a given OBJFILE. */
1041 svr4_fetch_objfile_link_map (struct objfile *objfile)
1045 /* Cause svr4_current_sos() to be run if it hasn't been already. */
1046 if (main_lm_addr == 0)
1047 solib_add (NULL, 0, ¤t_target, auto_solib_add);
1049 /* svr4_current_sos() will set main_lm_addr for the main executable. */
1050 if (objfile == symfile_objfile)
1051 return main_lm_addr;
1053 /* The other link map addresses may be found by examining the list
1054 of shared libraries. */
1055 for (so = master_so_list (); so; so = so->next)
1056 if (so->objfile == objfile)
1057 return so->lm_info->lm_addr;
1063 /* On some systems, the only way to recognize the link map entry for
1064 the main executable file is by looking at its name. Return
1065 non-zero iff SONAME matches one of the known main executable names. */
1068 match_main (char *soname)
1072 for (mainp = main_name_list; *mainp != NULL; mainp++)
1074 if (strcmp (soname, *mainp) == 0)
1081 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1082 SVR4 run time loader. */
1083 static CORE_ADDR interp_text_sect_low;
1084 static CORE_ADDR interp_text_sect_high;
1085 static CORE_ADDR interp_plt_sect_low;
1086 static CORE_ADDR interp_plt_sect_high;
1089 svr4_in_dynsym_resolve_code (CORE_ADDR pc)
1091 return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
1092 || (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
1093 || in_plt_section (pc, NULL));
1096 /* Given an executable's ABFD and target, compute the entry-point
1100 exec_entry_point (struct bfd *abfd, struct target_ops *targ)
1102 /* KevinB wrote ... for most targets, the address returned by
1103 bfd_get_start_address() is the entry point for the start
1104 function. But, for some targets, bfd_get_start_address() returns
1105 the address of a function descriptor from which the entry point
1106 address may be extracted. This address is extracted by
1107 gdbarch_convert_from_func_ptr_addr(). The method
1108 gdbarch_convert_from_func_ptr_addr() is the merely the identify
1109 function for targets which don't use function descriptors. */
1110 return gdbarch_convert_from_func_ptr_addr (target_gdbarch,
1111 bfd_get_start_address (abfd),
1119 enable_break -- arrange for dynamic linker to hit breakpoint
1123 int enable_break (void)
1127 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1128 debugger interface, support for arranging for the inferior to hit
1129 a breakpoint after mapping in the shared libraries. This function
1130 enables that breakpoint.
1132 For SunOS, there is a special flag location (in_debugger) which we
1133 set to 1. When the dynamic linker sees this flag set, it will set
1134 a breakpoint at a location known only to itself, after saving the
1135 original contents of that place and the breakpoint address itself,
1136 in it's own internal structures. When we resume the inferior, it
1137 will eventually take a SIGTRAP when it runs into the breakpoint.
1138 We handle this (in a different place) by restoring the contents of
1139 the breakpointed location (which is only known after it stops),
1140 chasing around to locate the shared libraries that have been
1141 loaded, then resuming.
1143 For SVR4, the debugger interface structure contains a member (r_brk)
1144 which is statically initialized at the time the shared library is
1145 built, to the offset of a function (_r_debug_state) which is guaran-
1146 teed to be called once before mapping in a library, and again when
1147 the mapping is complete. At the time we are examining this member,
1148 it contains only the unrelocated offset of the function, so we have
1149 to do our own relocation. Later, when the dynamic linker actually
1150 runs, it relocates r_brk to be the actual address of _r_debug_state().
1152 The debugger interface structure also contains an enumeration which
1153 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1154 depending upon whether or not the library is being mapped or unmapped,
1155 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1161 struct minimal_symbol *msymbol;
1163 asection *interp_sect;
1164 gdb_byte *interp_name;
1167 /* First, remove all the solib event breakpoints. Their addresses
1168 may have changed since the last time we ran the program. */
1169 remove_solib_event_breakpoints ();
1171 interp_text_sect_low = interp_text_sect_high = 0;
1172 interp_plt_sect_low = interp_plt_sect_high = 0;
1174 /* If we already have a shared library list in the target, and
1175 r_debug contains r_brk, set the breakpoint there - this should
1176 mean r_brk has already been relocated. Assume the dynamic linker
1177 is the object containing r_brk. */
1179 solib_add (NULL, 0, ¤t_target, auto_solib_add);
1181 if (debug_base && solib_svr4_r_map () != 0)
1182 sym_addr = solib_svr4_r_brk ();
1186 struct obj_section *os;
1188 sym_addr = gdbarch_addr_bits_remove
1189 (target_gdbarch, gdbarch_convert_from_func_ptr_addr (target_gdbarch,
1193 os = find_pc_section (sym_addr);
1196 /* Record the relocated start and end address of the dynamic linker
1197 text and plt section for svr4_in_dynsym_resolve_code. */
1199 CORE_ADDR load_addr;
1201 tmp_bfd = os->objfile->obfd;
1202 load_addr = ANOFFSET (os->objfile->section_offsets,
1203 os->objfile->sect_index_text);
1205 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1208 interp_text_sect_low =
1209 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1210 interp_text_sect_high =
1211 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1213 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1216 interp_plt_sect_low =
1217 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1218 interp_plt_sect_high =
1219 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1222 create_solib_event_breakpoint (sym_addr);
1227 /* Find the program interpreter; if not found, warn the user and drop
1228 into the old breakpoint at symbol code. */
1229 interp_name = find_program_interpreter ();
1232 CORE_ADDR load_addr = 0;
1233 int load_addr_found = 0;
1234 int loader_found_in_list = 0;
1236 bfd *tmp_bfd = NULL;
1237 struct target_ops *tmp_bfd_target;
1238 volatile struct gdb_exception ex;
1242 /* Now we need to figure out where the dynamic linker was
1243 loaded so that we can load its symbols and place a breakpoint
1244 in the dynamic linker itself.
1246 This address is stored on the stack. However, I've been unable
1247 to find any magic formula to find it for Solaris (appears to
1248 be trivial on GNU/Linux). Therefore, we have to try an alternate
1249 mechanism to find the dynamic linker's base address. */
1251 TRY_CATCH (ex, RETURN_MASK_ALL)
1253 tmp_bfd = solib_bfd_open (interp_name);
1255 if (tmp_bfd == NULL)
1256 goto bkpt_at_symbol;
1258 /* Now convert the TMP_BFD into a target. That way target, as
1259 well as BFD operations can be used. Note that closing the
1260 target will also close the underlying bfd. */
1261 tmp_bfd_target = target_bfd_reopen (tmp_bfd);
1263 /* On a running target, we can get the dynamic linker's base
1264 address from the shared library table. */
1265 so = master_so_list ();
1268 if (svr4_same_1 (interp_name, so->so_original_name))
1270 load_addr_found = 1;
1271 loader_found_in_list = 1;
1272 load_addr = LM_ADDR_CHECK (so, tmp_bfd);
1278 /* If we were not able to find the base address of the loader
1279 from our so_list, then try using the AT_BASE auxilliary entry. */
1280 if (!load_addr_found)
1281 if (target_auxv_search (¤t_target, AT_BASE, &load_addr) > 0)
1282 load_addr_found = 1;
1284 /* Otherwise we find the dynamic linker's base address by examining
1285 the current pc (which should point at the entry point for the
1286 dynamic linker) and subtracting the offset of the entry point.
1288 This is more fragile than the previous approaches, but is a good
1289 fallback method because it has actually been working well in
1291 if (!load_addr_found)
1292 load_addr = (read_pc ()
1293 - exec_entry_point (tmp_bfd, tmp_bfd_target));
1295 if (!loader_found_in_list)
1297 debug_loader_name = xstrdup (interp_name);
1298 debug_loader_offset_p = 1;
1299 debug_loader_offset = load_addr;
1300 solib_add (NULL, 0, ¤t_target, auto_solib_add);
1303 /* Record the relocated start and end address of the dynamic linker
1304 text and plt section for svr4_in_dynsym_resolve_code. */
1305 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1308 interp_text_sect_low =
1309 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1310 interp_text_sect_high =
1311 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1313 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1316 interp_plt_sect_low =
1317 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1318 interp_plt_sect_high =
1319 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1322 /* Now try to set a breakpoint in the dynamic linker. */
1323 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1325 sym_addr = bfd_lookup_symbol (tmp_bfd, *bkpt_namep);
1331 /* Convert 'sym_addr' from a function pointer to an address.
1332 Because we pass tmp_bfd_target instead of the current
1333 target, this will always produce an unrelocated value. */
1334 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
1338 /* We're done with both the temporary bfd and target. Remember,
1339 closing the target closes the underlying bfd. */
1340 target_close (tmp_bfd_target, 0);
1344 create_solib_event_breakpoint (load_addr + sym_addr);
1345 xfree (interp_name);
1349 /* For whatever reason we couldn't set a breakpoint in the dynamic
1350 linker. Warn and drop into the old code. */
1352 xfree (interp_name);
1353 warning (_("Unable to find dynamic linker breakpoint function.\n"
1354 "GDB will be unable to debug shared library initializers\n"
1355 "and track explicitly loaded dynamic code."));
1358 /* Scan through the lists of symbols, trying to look up the symbol and
1359 set a breakpoint there. Terminate loop when we/if we succeed. */
1361 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1363 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1364 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1366 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1371 for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
1373 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1374 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1376 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1387 special_symbol_handling -- additional shared library symbol handling
1391 void special_symbol_handling ()
1395 Once the symbols from a shared object have been loaded in the usual
1396 way, we are called to do any system specific symbol handling that
1399 For SunOS4, this consisted of grunging around in the dynamic
1400 linkers structures to find symbol definitions for "common" symbols
1401 and adding them to the minimal symbol table for the runtime common
1404 However, for SVR4, there's nothing to do.
1409 svr4_special_symbol_handling (void)
1413 /* Relocate the main executable. This function should be called upon
1414 stopping the inferior process at the entry point to the program.
1415 The entry point from BFD is compared to the PC and if they are
1416 different, the main executable is relocated by the proper amount.
1418 As written it will only attempt to relocate executables which
1419 lack interpreter sections. It seems likely that only dynamic
1420 linker executables will get relocated, though it should work
1421 properly for a position-independent static executable as well. */
1424 svr4_relocate_main_executable (void)
1426 asection *interp_sect;
1427 CORE_ADDR pc = read_pc ();
1429 /* Decide if the objfile needs to be relocated. As indicated above,
1430 we will only be here when execution is stopped at the beginning
1431 of the program. Relocation is necessary if the address at which
1432 we are presently stopped differs from the start address stored in
1433 the executable AND there's no interpreter section. The condition
1434 regarding the interpreter section is very important because if
1435 there *is* an interpreter section, execution will begin there
1436 instead. When there is an interpreter section, the start address
1437 is (presumably) used by the interpreter at some point to start
1438 execution of the program.
1440 If there is an interpreter, it is normal for it to be set to an
1441 arbitrary address at the outset. The job of finding it is
1442 handled in enable_break().
1444 So, to summarize, relocations are necessary when there is no
1445 interpreter section and the start address obtained from the
1446 executable is different from the address at which GDB is
1449 [ The astute reader will note that we also test to make sure that
1450 the executable in question has the DYNAMIC flag set. It is my
1451 opinion that this test is unnecessary (undesirable even). It
1452 was added to avoid inadvertent relocation of an executable
1453 whose e_type member in the ELF header is not ET_DYN. There may
1454 be a time in the future when it is desirable to do relocations
1455 on other types of files as well in which case this condition
1456 should either be removed or modified to accomodate the new file
1457 type. (E.g, an ET_EXEC executable which has been built to be
1458 position-independent could safely be relocated by the OS if
1459 desired. It is true that this violates the ABI, but the ABI
1460 has been known to be bent from time to time.) - Kevin, Nov 2000. ]
1463 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
1464 if (interp_sect == NULL
1465 && (bfd_get_file_flags (exec_bfd) & DYNAMIC) != 0
1466 && (exec_entry_point (exec_bfd, &exec_ops) != pc))
1468 struct cleanup *old_chain;
1469 struct section_offsets *new_offsets;
1471 CORE_ADDR displacement;
1473 /* It is necessary to relocate the objfile. The amount to
1474 relocate by is simply the address at which we are stopped
1475 minus the starting address from the executable.
1477 We relocate all of the sections by the same amount. This
1478 behavior is mandated by recent editions of the System V ABI.
1479 According to the System V Application Binary Interface,
1480 Edition 4.1, page 5-5:
1482 ... Though the system chooses virtual addresses for
1483 individual processes, it maintains the segments' relative
1484 positions. Because position-independent code uses relative
1485 addressesing between segments, the difference between
1486 virtual addresses in memory must match the difference
1487 between virtual addresses in the file. The difference
1488 between the virtual address of any segment in memory and
1489 the corresponding virtual address in the file is thus a
1490 single constant value for any one executable or shared
1491 object in a given process. This difference is the base
1492 address. One use of the base address is to relocate the
1493 memory image of the program during dynamic linking.
1495 The same language also appears in Edition 4.0 of the System V
1496 ABI and is left unspecified in some of the earlier editions. */
1498 displacement = pc - exec_entry_point (exec_bfd, &exec_ops);
1501 new_offsets = xcalloc (symfile_objfile->num_sections,
1502 sizeof (struct section_offsets));
1503 old_chain = make_cleanup (xfree, new_offsets);
1505 for (i = 0; i < symfile_objfile->num_sections; i++)
1507 if (displacement != ANOFFSET (symfile_objfile->section_offsets, i))
1509 new_offsets->offsets[i] = displacement;
1513 objfile_relocate (symfile_objfile, new_offsets);
1515 do_cleanups (old_chain);
1523 svr4_solib_create_inferior_hook -- shared library startup support
1527 void svr4_solib_create_inferior_hook ()
1531 When gdb starts up the inferior, it nurses it along (through the
1532 shell) until it is ready to execute it's first instruction. At this
1533 point, this function gets called via expansion of the macro
1534 SOLIB_CREATE_INFERIOR_HOOK.
1536 For SunOS executables, this first instruction is typically the
1537 one at "_start", or a similar text label, regardless of whether
1538 the executable is statically or dynamically linked. The runtime
1539 startup code takes care of dynamically linking in any shared
1540 libraries, once gdb allows the inferior to continue.
1542 For SVR4 executables, this first instruction is either the first
1543 instruction in the dynamic linker (for dynamically linked
1544 executables) or the instruction at "start" for statically linked
1545 executables. For dynamically linked executables, the system
1546 first exec's /lib/libc.so.N, which contains the dynamic linker,
1547 and starts it running. The dynamic linker maps in any needed
1548 shared libraries, maps in the actual user executable, and then
1549 jumps to "start" in the user executable.
1551 For both SunOS shared libraries, and SVR4 shared libraries, we
1552 can arrange to cooperate with the dynamic linker to discover the
1553 names of shared libraries that are dynamically linked, and the
1554 base addresses to which they are linked.
1556 This function is responsible for discovering those names and
1557 addresses, and saving sufficient information about them to allow
1558 their symbols to be read at a later time.
1562 Between enable_break() and disable_break(), this code does not
1563 properly handle hitting breakpoints which the user might have
1564 set in the startup code or in the dynamic linker itself. Proper
1565 handling will probably have to wait until the implementation is
1566 changed to use the "breakpoint handler function" method.
1568 Also, what if child has exit()ed? Must exit loop somehow.
1572 svr4_solib_create_inferior_hook (void)
1574 struct inferior *inf;
1575 struct thread_info *tp;
1577 /* Relocate the main executable if necessary. */
1578 svr4_relocate_main_executable ();
1580 if (!svr4_have_link_map_offsets ())
1583 if (!enable_break ())
1586 #if defined(_SCO_DS)
1587 /* SCO needs the loop below, other systems should be using the
1588 special shared library breakpoints and the shared library breakpoint
1591 Now run the target. It will eventually hit the breakpoint, at
1592 which point all of the libraries will have been mapped in and we
1593 can go groveling around in the dynamic linker structures to find
1594 out what we need to know about them. */
1596 inf = current_inferior ();
1597 tp = inferior_thread ();
1599 clear_proceed_status ();
1600 inf->stop_soon = STOP_QUIETLY;
1601 tp->stop_signal = TARGET_SIGNAL_0;
1604 target_resume (pid_to_ptid (-1), 0, tp->stop_signal);
1605 wait_for_inferior (0);
1607 while (tp->stop_signal != TARGET_SIGNAL_TRAP);
1608 inf->stop_soon = NO_STOP_QUIETLY;
1609 #endif /* defined(_SCO_DS) */
1613 svr4_clear_solib (void)
1616 debug_loader_offset_p = 0;
1617 debug_loader_offset = 0;
1618 xfree (debug_loader_name);
1619 debug_loader_name = NULL;
1624 svr4_free_so (struct so_list *so)
1626 xfree (so->lm_info->lm);
1627 xfree (so->lm_info);
1631 /* Clear any bits of ADDR that wouldn't fit in a target-format
1632 data pointer. "Data pointer" here refers to whatever sort of
1633 address the dynamic linker uses to manage its sections. At the
1634 moment, we don't support shared libraries on any processors where
1635 code and data pointers are different sizes.
1637 This isn't really the right solution. What we really need here is
1638 a way to do arithmetic on CORE_ADDR values that respects the
1639 natural pointer/address correspondence. (For example, on the MIPS,
1640 converting a 32-bit pointer to a 64-bit CORE_ADDR requires you to
1641 sign-extend the value. There, simply truncating the bits above
1642 gdbarch_ptr_bit, as we do below, is no good.) This should probably
1643 be a new gdbarch method or something. */
1645 svr4_truncate_ptr (CORE_ADDR addr)
1647 if (gdbarch_ptr_bit (target_gdbarch) == sizeof (CORE_ADDR) * 8)
1648 /* We don't need to truncate anything, and the bit twiddling below
1649 will fail due to overflow problems. */
1652 return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (target_gdbarch)) - 1);
1657 svr4_relocate_section_addresses (struct so_list *so,
1658 struct section_table *sec)
1660 sec->addr = svr4_truncate_ptr (sec->addr + LM_ADDR_CHECK (so,
1662 sec->endaddr = svr4_truncate_ptr (sec->endaddr + LM_ADDR_CHECK (so,
1667 /* Architecture-specific operations. */
1669 /* Per-architecture data key. */
1670 static struct gdbarch_data *solib_svr4_data;
1672 struct solib_svr4_ops
1674 /* Return a description of the layout of `struct link_map'. */
1675 struct link_map_offsets *(*fetch_link_map_offsets)(void);
1678 /* Return a default for the architecture-specific operations. */
1681 solib_svr4_init (struct obstack *obstack)
1683 struct solib_svr4_ops *ops;
1685 ops = OBSTACK_ZALLOC (obstack, struct solib_svr4_ops);
1686 ops->fetch_link_map_offsets = NULL;
1690 /* Set the architecture-specific `struct link_map_offsets' fetcher for
1691 GDBARCH to FLMO. Also, install SVR4 solib_ops into GDBARCH. */
1694 set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch,
1695 struct link_map_offsets *(*flmo) (void))
1697 struct solib_svr4_ops *ops = gdbarch_data (gdbarch, solib_svr4_data);
1699 ops->fetch_link_map_offsets = flmo;
1701 set_solib_ops (gdbarch, &svr4_so_ops);
1704 /* Fetch a link_map_offsets structure using the architecture-specific
1705 `struct link_map_offsets' fetcher. */
1707 static struct link_map_offsets *
1708 svr4_fetch_link_map_offsets (void)
1710 struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
1712 gdb_assert (ops->fetch_link_map_offsets);
1713 return ops->fetch_link_map_offsets ();
1716 /* Return 1 if a link map offset fetcher has been defined, 0 otherwise. */
1719 svr4_have_link_map_offsets (void)
1721 struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
1722 return (ops->fetch_link_map_offsets != NULL);
1726 /* Most OS'es that have SVR4-style ELF dynamic libraries define a
1727 `struct r_debug' and a `struct link_map' that are binary compatible
1728 with the origional SVR4 implementation. */
1730 /* Fetch (and possibly build) an appropriate `struct link_map_offsets'
1731 for an ILP32 SVR4 system. */
1733 struct link_map_offsets *
1734 svr4_ilp32_fetch_link_map_offsets (void)
1736 static struct link_map_offsets lmo;
1737 static struct link_map_offsets *lmp = NULL;
1743 lmo.r_version_offset = 0;
1744 lmo.r_version_size = 4;
1745 lmo.r_map_offset = 4;
1746 lmo.r_brk_offset = 8;
1747 lmo.r_ldsomap_offset = 20;
1749 /* Everything we need is in the first 20 bytes. */
1750 lmo.link_map_size = 20;
1751 lmo.l_addr_offset = 0;
1752 lmo.l_name_offset = 4;
1753 lmo.l_ld_offset = 8;
1754 lmo.l_next_offset = 12;
1755 lmo.l_prev_offset = 16;
1761 /* Fetch (and possibly build) an appropriate `struct link_map_offsets'
1762 for an LP64 SVR4 system. */
1764 struct link_map_offsets *
1765 svr4_lp64_fetch_link_map_offsets (void)
1767 static struct link_map_offsets lmo;
1768 static struct link_map_offsets *lmp = NULL;
1774 lmo.r_version_offset = 0;
1775 lmo.r_version_size = 4;
1776 lmo.r_map_offset = 8;
1777 lmo.r_brk_offset = 16;
1778 lmo.r_ldsomap_offset = 40;
1780 /* Everything we need is in the first 40 bytes. */
1781 lmo.link_map_size = 40;
1782 lmo.l_addr_offset = 0;
1783 lmo.l_name_offset = 8;
1784 lmo.l_ld_offset = 16;
1785 lmo.l_next_offset = 24;
1786 lmo.l_prev_offset = 32;
1793 struct target_so_ops svr4_so_ops;
1795 /* Lookup global symbol for ELF DSOs linked with -Bsymbolic. Those DSOs have a
1796 different rule for symbol lookup. The lookup begins here in the DSO, not in
1797 the main executable. */
1799 static struct symbol *
1800 elf_lookup_lib_symbol (const struct objfile *objfile,
1802 const char *linkage_name,
1803 const domain_enum domain)
1805 if (objfile->obfd == NULL
1806 || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
1809 return lookup_global_symbol_from_objfile
1810 (objfile, name, linkage_name, domain);
1813 extern initialize_file_ftype _initialize_svr4_solib; /* -Wmissing-prototypes */
1816 _initialize_svr4_solib (void)
1818 solib_svr4_data = gdbarch_data_register_pre_init (solib_svr4_init);
1820 svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses;
1821 svr4_so_ops.free_so = svr4_free_so;
1822 svr4_so_ops.clear_solib = svr4_clear_solib;
1823 svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook;
1824 svr4_so_ops.special_symbol_handling = svr4_special_symbol_handling;
1825 svr4_so_ops.current_sos = svr4_current_sos;
1826 svr4_so_ops.open_symbol_file_object = open_symbol_file_object;
1827 svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code;
1828 svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
1829 svr4_so_ops.same = svr4_same;