* src/gdb/target.h: Remove all tests for already defined
[deliverable/binutils-gdb.git] / gdb / solib-svr4.c
CommitLineData
ab31aa69 1/* Handle SVR4 shared libraries for GDB, the GNU Debugger.
2f4950cd 2
6aba47ca 3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
0fb0cc75
JB
4 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
13437d4b
KB
6
7 This file is part of GDB.
8
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
13437d4b
KB
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
13437d4b 21
13437d4b
KB
22#include "defs.h"
23
13437d4b 24#include "elf/external.h"
21479ded 25#include "elf/common.h"
f7856c8f 26#include "elf/mips.h"
13437d4b
KB
27
28#include "symtab.h"
29#include "bfd.h"
30#include "symfile.h"
31#include "objfiles.h"
32#include "gdbcore.h"
13437d4b 33#include "target.h"
13437d4b 34#include "inferior.h"
fb14de7b 35#include "regcache.h"
2020b7ab 36#include "gdbthread.h"
13437d4b 37
4b188b9f
MK
38#include "gdb_assert.h"
39
13437d4b 40#include "solist.h"
bba93f6c 41#include "solib.h"
13437d4b
KB
42#include "solib-svr4.h"
43
2f4950cd 44#include "bfd-target.h"
cc10cae3 45#include "elf-bfd.h"
2f4950cd 46#include "exec.h"
8d4e36ba 47#include "auxv.h"
f1838a98 48#include "exceptions.h"
2f4950cd 49
e5e2b9ff 50static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
d5a921c9 51static int svr4_have_link_map_offsets (void);
1c4dcb57 52
13437d4b
KB
53/* Link map info to include in an allocated so_list entry */
54
55struct lm_info
56 {
57 /* Pointer to copy of link map from inferior. The type is char *
58 rather than void *, so that we may use byte offsets to find the
59 various fields without the need for a cast. */
4066fc10 60 gdb_byte *lm;
cc10cae3
AO
61
62 /* Amount by which addresses in the binary should be relocated to
63 match the inferior. This could most often be taken directly
64 from lm, but when prelinking is involved and the prelink base
65 address changes, we may need a different offset, we want to
66 warn about the difference and compute it only once. */
67 CORE_ADDR l_addr;
93a57060
DJ
68
69 /* The target location of lm. */
70 CORE_ADDR lm_addr;
13437d4b
KB
71 };
72
73/* On SVR4 systems, a list of symbols in the dynamic linker where
74 GDB can try to place a breakpoint to monitor shared library
75 events.
76
77 If none of these symbols are found, or other errors occur, then
78 SVR4 systems will fall back to using a symbol as the "startup
79 mapping complete" breakpoint address. */
80
13437d4b
KB
81static char *solib_break_names[] =
82{
83 "r_debug_state",
84 "_r_debug_state",
85 "_dl_debug_state",
86 "rtld_db_dlactivity",
1f72e589 87 "_rtld_debug_state",
4c0122c8 88
13437d4b
KB
89 NULL
90};
13437d4b 91
13437d4b
KB
92static char *bkpt_names[] =
93{
13437d4b 94 "_start",
ad3dcc5c 95 "__start",
13437d4b
KB
96 "main",
97 NULL
98};
13437d4b 99
13437d4b
KB
100static char *main_name_list[] =
101{
102 "main_$main",
103 NULL
104};
105
4d7b2d5b
JB
106/* Return non-zero if GDB_SO_NAME and INFERIOR_SO_NAME represent
107 the same shared library. */
108
109static int
110svr4_same_1 (const char *gdb_so_name, const char *inferior_so_name)
111{
112 if (strcmp (gdb_so_name, inferior_so_name) == 0)
113 return 1;
114
115 /* On Solaris, when starting inferior we think that dynamic linker is
116 /usr/lib/ld.so.1, but later on, the table of loaded shared libraries
117 contains /lib/ld.so.1. Sometimes one file is a link to another, but
118 sometimes they have identical content, but are not linked to each
119 other. We don't restrict this check for Solaris, but the chances
120 of running into this situation elsewhere are very low. */
121 if (strcmp (gdb_so_name, "/usr/lib/ld.so.1") == 0
122 && strcmp (inferior_so_name, "/lib/ld.so.1") == 0)
123 return 1;
124
125 /* Similarly, we observed the same issue with sparc64, but with
126 different locations. */
127 if (strcmp (gdb_so_name, "/usr/lib/sparcv9/ld.so.1") == 0
128 && strcmp (inferior_so_name, "/lib/sparcv9/ld.so.1") == 0)
129 return 1;
130
131 return 0;
132}
133
134static int
135svr4_same (struct so_list *gdb, struct so_list *inferior)
136{
137 return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
138}
139
13437d4b
KB
140/* link map access functions */
141
142static CORE_ADDR
cc10cae3 143LM_ADDR_FROM_LINK_MAP (struct so_list *so)
13437d4b 144{
4b188b9f 145 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 146 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
13437d4b 147
cfaefc65 148 return extract_typed_address (so->lm_info->lm + lmo->l_addr_offset,
b6da22b0 149 ptr_type);
13437d4b
KB
150}
151
cc10cae3 152static int
2c0b251b 153HAS_LM_DYNAMIC_FROM_LINK_MAP (void)
cc10cae3
AO
154{
155 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
156
cfaefc65 157 return lmo->l_ld_offset >= 0;
cc10cae3
AO
158}
159
160static CORE_ADDR
161LM_DYNAMIC_FROM_LINK_MAP (struct so_list *so)
162{
163 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 164 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
cc10cae3 165
cfaefc65 166 return extract_typed_address (so->lm_info->lm + lmo->l_ld_offset,
b6da22b0 167 ptr_type);
cc10cae3
AO
168}
169
170static CORE_ADDR
171LM_ADDR_CHECK (struct so_list *so, bfd *abfd)
172{
173 if (so->lm_info->l_addr == (CORE_ADDR)-1)
174 {
175 struct bfd_section *dyninfo_sect;
176 CORE_ADDR l_addr, l_dynaddr, dynaddr, align = 0x1000;
177
178 l_addr = LM_ADDR_FROM_LINK_MAP (so);
179
180 if (! abfd || ! HAS_LM_DYNAMIC_FROM_LINK_MAP ())
181 goto set_addr;
182
183 l_dynaddr = LM_DYNAMIC_FROM_LINK_MAP (so);
184
185 dyninfo_sect = bfd_get_section_by_name (abfd, ".dynamic");
186 if (dyninfo_sect == NULL)
187 goto set_addr;
188
189 dynaddr = bfd_section_vma (abfd, dyninfo_sect);
190
191 if (dynaddr + l_addr != l_dynaddr)
192 {
cc10cae3
AO
193 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
194 {
195 Elf_Internal_Ehdr *ehdr = elf_tdata (abfd)->elf_header;
196 Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr;
197 int i;
198
199 align = 1;
200
201 for (i = 0; i < ehdr->e_phnum; i++)
202 if (phdr[i].p_type == PT_LOAD && phdr[i].p_align > align)
203 align = phdr[i].p_align;
204 }
205
206 /* Turn it into a mask. */
207 align--;
208
209 /* If the changes match the alignment requirements, we
210 assume we're using a core file that was generated by the
211 same binary, just prelinked with a different base offset.
212 If it doesn't match, we may have a different binary, the
213 same binary with the dynamic table loaded at an unrelated
214 location, or anything, really. To avoid regressions,
215 don't adjust the base offset in the latter case, although
216 odds are that, if things really changed, debugging won't
217 quite work. */
f1e55806 218 if ((l_addr & align) == ((l_dynaddr - dynaddr) & align))
cc10cae3
AO
219 {
220 l_addr = l_dynaddr - dynaddr;
79d4c408
DJ
221
222 warning (_(".dynamic section for \"%s\" "
223 "is not at the expected address"), so->so_name);
cc10cae3
AO
224 warning (_("difference appears to be caused by prelink, "
225 "adjusting expectations"));
226 }
79d4c408
DJ
227 else
228 warning (_(".dynamic section for \"%s\" "
229 "is not at the expected address "
230 "(wrong library or version mismatch?)"), so->so_name);
cc10cae3
AO
231 }
232
233 set_addr:
234 so->lm_info->l_addr = l_addr;
235 }
236
237 return so->lm_info->l_addr;
238}
239
13437d4b
KB
240static CORE_ADDR
241LM_NEXT (struct so_list *so)
242{
4b188b9f 243 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 244 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
13437d4b 245
cfaefc65 246 return extract_typed_address (so->lm_info->lm + lmo->l_next_offset,
b6da22b0 247 ptr_type);
13437d4b
KB
248}
249
250static CORE_ADDR
251LM_NAME (struct so_list *so)
252{
4b188b9f 253 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 254 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
13437d4b 255
cfaefc65 256 return extract_typed_address (so->lm_info->lm + lmo->l_name_offset,
b6da22b0 257 ptr_type);
13437d4b
KB
258}
259
13437d4b
KB
260static int
261IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list *so)
262{
4b188b9f 263 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 264 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
13437d4b 265
e499d0f1
DJ
266 /* Assume that everything is a library if the dynamic loader was loaded
267 late by a static executable. */
268 if (bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
269 return 0;
270
cfaefc65 271 return extract_typed_address (so->lm_info->lm + lmo->l_prev_offset,
b6da22b0 272 ptr_type) == 0;
13437d4b
KB
273}
274
13437d4b 275static CORE_ADDR debug_base; /* Base of dynamic linker structures */
13437d4b 276
34439770
DJ
277/* Validity flag for debug_loader_offset. */
278static int debug_loader_offset_p;
279
280/* Load address for the dynamic linker, inferred. */
281static CORE_ADDR debug_loader_offset;
282
283/* Name of the dynamic linker, valid if debug_loader_offset_p. */
284static char *debug_loader_name;
285
93a57060
DJ
286/* Load map address for the main executable. */
287static CORE_ADDR main_lm_addr;
288
13437d4b
KB
289/* Local function prototypes */
290
291static int match_main (char *);
292
2bbe3cc1 293static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
13437d4b
KB
294
295/*
296
297 LOCAL FUNCTION
298
299 bfd_lookup_symbol -- lookup the value for a specific symbol
300
301 SYNOPSIS
302
2bbe3cc1 303 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
13437d4b
KB
304
305 DESCRIPTION
306
307 An expensive way to lookup the value of a single symbol for
308 bfd's that are only temporary anyway. This is used by the
309 shared library support to find the address of the debugger
2bbe3cc1 310 notification routine in the shared library.
13437d4b 311
2bbe3cc1
DJ
312 The returned symbol may be in a code or data section; functions
313 will normally be in a code section, but may be in a data section
314 if this architecture uses function descriptors.
87f84c9d 315
13437d4b
KB
316 Note that 0 is specifically allowed as an error return (no
317 such symbol).
318 */
319
320static CORE_ADDR
2bbe3cc1 321bfd_lookup_symbol (bfd *abfd, char *symname)
13437d4b 322{
435b259c 323 long storage_needed;
13437d4b
KB
324 asymbol *sym;
325 asymbol **symbol_table;
326 unsigned int number_of_symbols;
327 unsigned int i;
328 struct cleanup *back_to;
329 CORE_ADDR symaddr = 0;
330
331 storage_needed = bfd_get_symtab_upper_bound (abfd);
332
333 if (storage_needed > 0)
334 {
335 symbol_table = (asymbol **) xmalloc (storage_needed);
4efb68b1 336 back_to = make_cleanup (xfree, symbol_table);
13437d4b
KB
337 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
338
339 for (i = 0; i < number_of_symbols; i++)
340 {
341 sym = *symbol_table++;
6314a349 342 if (strcmp (sym->name, symname) == 0
2bbe3cc1 343 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
13437d4b 344 {
2bbe3cc1 345 /* BFD symbols are section relative. */
13437d4b
KB
346 symaddr = sym->value + sym->section->vma;
347 break;
348 }
349 }
350 do_cleanups (back_to);
351 }
352
353 if (symaddr)
354 return symaddr;
355
356 /* On FreeBSD, the dynamic linker is stripped by default. So we'll
357 have to check the dynamic string table too. */
358
359 storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
360
361 if (storage_needed > 0)
362 {
363 symbol_table = (asymbol **) xmalloc (storage_needed);
4efb68b1 364 back_to = make_cleanup (xfree, symbol_table);
13437d4b
KB
365 number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
366
367 for (i = 0; i < number_of_symbols; i++)
368 {
369 sym = *symbol_table++;
87f84c9d 370
6314a349 371 if (strcmp (sym->name, symname) == 0
2bbe3cc1 372 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
13437d4b 373 {
2bbe3cc1 374 /* BFD symbols are section relative. */
13437d4b
KB
375 symaddr = sym->value + sym->section->vma;
376 break;
377 }
378 }
379 do_cleanups (back_to);
380 }
381
382 return symaddr;
383}
384
97ec2c2f
UW
385
386/* Read program header TYPE from inferior memory. The header is found
387 by scanning the OS auxillary vector.
388
389 Return a pointer to allocated memory holding the program header contents,
390 or NULL on failure. If sucessful, and unless P_SECT_SIZE is NULL, the
391 size of those contents is returned to P_SECT_SIZE. Likewise, the target
392 architecture size (32-bit or 64-bit) is returned to P_ARCH_SIZE. */
393
394static gdb_byte *
395read_program_header (int type, int *p_sect_size, int *p_arch_size)
396{
397 CORE_ADDR at_phdr, at_phent, at_phnum;
398 int arch_size, sect_size;
399 CORE_ADDR sect_addr;
400 gdb_byte *buf;
401
402 /* Get required auxv elements from target. */
403 if (target_auxv_search (&current_target, AT_PHDR, &at_phdr) <= 0)
404 return 0;
405 if (target_auxv_search (&current_target, AT_PHENT, &at_phent) <= 0)
406 return 0;
407 if (target_auxv_search (&current_target, AT_PHNUM, &at_phnum) <= 0)
408 return 0;
409 if (!at_phdr || !at_phnum)
410 return 0;
411
412 /* Determine ELF architecture type. */
413 if (at_phent == sizeof (Elf32_External_Phdr))
414 arch_size = 32;
415 else if (at_phent == sizeof (Elf64_External_Phdr))
416 arch_size = 64;
417 else
418 return 0;
419
420 /* Find .dynamic section via the PT_DYNAMIC PHDR. */
421 if (arch_size == 32)
422 {
423 Elf32_External_Phdr phdr;
424 int i;
425
426 /* Search for requested PHDR. */
427 for (i = 0; i < at_phnum; i++)
428 {
429 if (target_read_memory (at_phdr + i * sizeof (phdr),
430 (gdb_byte *)&phdr, sizeof (phdr)))
431 return 0;
432
433 if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, 4) == type)
434 break;
435 }
436
437 if (i == at_phnum)
438 return 0;
439
440 /* Retrieve address and size. */
441 sect_addr = extract_unsigned_integer ((gdb_byte *)phdr.p_vaddr, 4);
442 sect_size = extract_unsigned_integer ((gdb_byte *)phdr.p_memsz, 4);
443 }
444 else
445 {
446 Elf64_External_Phdr phdr;
447 int i;
448
449 /* Search for requested PHDR. */
450 for (i = 0; i < at_phnum; i++)
451 {
452 if (target_read_memory (at_phdr + i * sizeof (phdr),
453 (gdb_byte *)&phdr, sizeof (phdr)))
454 return 0;
455
456 if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, 4) == type)
457 break;
458 }
459
460 if (i == at_phnum)
461 return 0;
462
463 /* Retrieve address and size. */
464 sect_addr = extract_unsigned_integer ((gdb_byte *)phdr.p_vaddr, 8);
465 sect_size = extract_unsigned_integer ((gdb_byte *)phdr.p_memsz, 8);
466 }
467
468 /* Read in requested program header. */
469 buf = xmalloc (sect_size);
470 if (target_read_memory (sect_addr, buf, sect_size))
471 {
472 xfree (buf);
473 return NULL;
474 }
475
476 if (p_arch_size)
477 *p_arch_size = arch_size;
478 if (p_sect_size)
479 *p_sect_size = sect_size;
480
481 return buf;
482}
483
484
485/* Return program interpreter string. */
486static gdb_byte *
487find_program_interpreter (void)
488{
489 gdb_byte *buf = NULL;
490
491 /* If we have an exec_bfd, use its section table. */
492 if (exec_bfd
493 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
494 {
495 struct bfd_section *interp_sect;
496
497 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
498 if (interp_sect != NULL)
499 {
500 CORE_ADDR sect_addr = bfd_section_vma (exec_bfd, interp_sect);
501 int sect_size = bfd_section_size (exec_bfd, interp_sect);
502
503 buf = xmalloc (sect_size);
504 bfd_get_section_contents (exec_bfd, interp_sect, buf, 0, sect_size);
505 }
506 }
507
508 /* If we didn't find it, use the target auxillary vector. */
509 if (!buf)
510 buf = read_program_header (PT_INTERP, NULL, NULL);
511
512 return buf;
513}
514
515
3a40aaa0
UW
516/* Scan for DYNTAG in .dynamic section of ABFD. If DYNTAG is found 1 is
517 returned and the corresponding PTR is set. */
518
519static int
520scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
521{
522 int arch_size, step, sect_size;
523 long dyn_tag;
524 CORE_ADDR dyn_ptr, dyn_addr;
65728c26 525 gdb_byte *bufend, *bufstart, *buf;
3a40aaa0
UW
526 Elf32_External_Dyn *x_dynp_32;
527 Elf64_External_Dyn *x_dynp_64;
528 struct bfd_section *sect;
529
530 if (abfd == NULL)
531 return 0;
532 arch_size = bfd_get_arch_size (abfd);
533 if (arch_size == -1)
534 return 0;
535
536 /* Find the start address of the .dynamic section. */
537 sect = bfd_get_section_by_name (abfd, ".dynamic");
538 if (sect == NULL)
539 return 0;
540 dyn_addr = bfd_section_vma (abfd, sect);
541
65728c26
DJ
542 /* Read in .dynamic from the BFD. We will get the actual value
543 from memory later. */
3a40aaa0 544 sect_size = bfd_section_size (abfd, sect);
65728c26
DJ
545 buf = bufstart = alloca (sect_size);
546 if (!bfd_get_section_contents (abfd, sect,
547 buf, 0, sect_size))
548 return 0;
3a40aaa0
UW
549
550 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
551 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
552 : sizeof (Elf64_External_Dyn);
553 for (bufend = buf + sect_size;
554 buf < bufend;
555 buf += step)
556 {
557 if (arch_size == 32)
558 {
559 x_dynp_32 = (Elf32_External_Dyn *) buf;
560 dyn_tag = bfd_h_get_32 (abfd, (bfd_byte *) x_dynp_32->d_tag);
561 dyn_ptr = bfd_h_get_32 (abfd, (bfd_byte *) x_dynp_32->d_un.d_ptr);
562 }
65728c26 563 else
3a40aaa0
UW
564 {
565 x_dynp_64 = (Elf64_External_Dyn *) buf;
566 dyn_tag = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_tag);
567 dyn_ptr = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_un.d_ptr);
568 }
569 if (dyn_tag == DT_NULL)
570 return 0;
571 if (dyn_tag == dyntag)
572 {
65728c26
DJ
573 /* If requested, try to read the runtime value of this .dynamic
574 entry. */
3a40aaa0 575 if (ptr)
65728c26 576 {
b6da22b0 577 struct type *ptr_type;
65728c26
DJ
578 gdb_byte ptr_buf[8];
579 CORE_ADDR ptr_addr;
580
b6da22b0 581 ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
65728c26
DJ
582 ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
583 if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0)
b6da22b0 584 dyn_ptr = extract_typed_address (ptr_buf, ptr_type);
65728c26
DJ
585 *ptr = dyn_ptr;
586 }
587 return 1;
3a40aaa0
UW
588 }
589 }
590
591 return 0;
592}
593
97ec2c2f
UW
594/* Scan for DYNTAG in .dynamic section of the target's main executable,
595 found by consulting the OS auxillary vector. If DYNTAG is found 1 is
596 returned and the corresponding PTR is set. */
597
598static int
599scan_dyntag_auxv (int dyntag, CORE_ADDR *ptr)
600{
601 int sect_size, arch_size, step;
602 long dyn_tag;
603 CORE_ADDR dyn_ptr;
604 gdb_byte *bufend, *bufstart, *buf;
605
606 /* Read in .dynamic section. */
607 buf = bufstart = read_program_header (PT_DYNAMIC, &sect_size, &arch_size);
608 if (!buf)
609 return 0;
610
611 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
612 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
613 : sizeof (Elf64_External_Dyn);
614 for (bufend = buf + sect_size;
615 buf < bufend;
616 buf += step)
617 {
618 if (arch_size == 32)
619 {
620 Elf32_External_Dyn *dynp = (Elf32_External_Dyn *) buf;
621 dyn_tag = extract_unsigned_integer ((gdb_byte *) dynp->d_tag, 4);
622 dyn_ptr = extract_unsigned_integer ((gdb_byte *) dynp->d_un.d_ptr, 4);
623 }
624 else
625 {
626 Elf64_External_Dyn *dynp = (Elf64_External_Dyn *) buf;
627 dyn_tag = extract_unsigned_integer ((gdb_byte *) dynp->d_tag, 8);
628 dyn_ptr = extract_unsigned_integer ((gdb_byte *) dynp->d_un.d_ptr, 8);
629 }
630 if (dyn_tag == DT_NULL)
631 break;
632
633 if (dyn_tag == dyntag)
634 {
635 if (ptr)
636 *ptr = dyn_ptr;
637
638 xfree (bufstart);
639 return 1;
640 }
641 }
642
643 xfree (bufstart);
644 return 0;
645}
646
3a40aaa0 647
13437d4b
KB
648/*
649
650 LOCAL FUNCTION
651
652 elf_locate_base -- locate the base address of dynamic linker structs
653 for SVR4 elf targets.
654
655 SYNOPSIS
656
657 CORE_ADDR elf_locate_base (void)
658
659 DESCRIPTION
660
661 For SVR4 elf targets the address of the dynamic linker's runtime
662 structure is contained within the dynamic info section in the
663 executable file. The dynamic section is also mapped into the
664 inferior address space. Because the runtime loader fills in the
665 real address before starting the inferior, we have to read in the
666 dynamic info section from the inferior address space.
667 If there are any errors while trying to find the address, we
668 silently return 0, otherwise the found address is returned.
669
670 */
671
672static CORE_ADDR
673elf_locate_base (void)
674{
3a40aaa0
UW
675 struct minimal_symbol *msymbol;
676 CORE_ADDR dyn_ptr;
13437d4b 677
65728c26
DJ
678 /* Look for DT_MIPS_RLD_MAP first. MIPS executables use this
679 instead of DT_DEBUG, although they sometimes contain an unused
680 DT_DEBUG. */
97ec2c2f
UW
681 if (scan_dyntag (DT_MIPS_RLD_MAP, exec_bfd, &dyn_ptr)
682 || scan_dyntag_auxv (DT_MIPS_RLD_MAP, &dyn_ptr))
3a40aaa0 683 {
b6da22b0 684 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
3a40aaa0 685 gdb_byte *pbuf;
b6da22b0 686 int pbuf_size = TYPE_LENGTH (ptr_type);
3a40aaa0
UW
687 pbuf = alloca (pbuf_size);
688 /* DT_MIPS_RLD_MAP contains a pointer to the address
689 of the dynamic link structure. */
690 if (target_read_memory (dyn_ptr, pbuf, pbuf_size))
e499d0f1 691 return 0;
b6da22b0 692 return extract_typed_address (pbuf, ptr_type);
e499d0f1
DJ
693 }
694
65728c26 695 /* Find DT_DEBUG. */
97ec2c2f
UW
696 if (scan_dyntag (DT_DEBUG, exec_bfd, &dyn_ptr)
697 || scan_dyntag_auxv (DT_DEBUG, &dyn_ptr))
65728c26
DJ
698 return dyn_ptr;
699
3a40aaa0
UW
700 /* This may be a static executable. Look for the symbol
701 conventionally named _r_debug, as a last resort. */
702 msymbol = lookup_minimal_symbol ("_r_debug", NULL, symfile_objfile);
703 if (msymbol != NULL)
704 return SYMBOL_VALUE_ADDRESS (msymbol);
13437d4b
KB
705
706 /* DT_DEBUG entry not found. */
707 return 0;
708}
709
13437d4b
KB
710/*
711
712 LOCAL FUNCTION
713
714 locate_base -- locate the base address of dynamic linker structs
715
716 SYNOPSIS
717
718 CORE_ADDR locate_base (void)
719
720 DESCRIPTION
721
722 For both the SunOS and SVR4 shared library implementations, if the
723 inferior executable has been linked dynamically, there is a single
724 address somewhere in the inferior's data space which is the key to
725 locating all of the dynamic linker's runtime structures. This
726 address is the value of the debug base symbol. The job of this
727 function is to find and return that address, or to return 0 if there
728 is no such address (the executable is statically linked for example).
729
730 For SunOS, the job is almost trivial, since the dynamic linker and
731 all of it's structures are statically linked to the executable at
732 link time. Thus the symbol for the address we are looking for has
733 already been added to the minimal symbol table for the executable's
734 objfile at the time the symbol file's symbols were read, and all we
735 have to do is look it up there. Note that we explicitly do NOT want
736 to find the copies in the shared library.
737
738 The SVR4 version is a bit more complicated because the address
739 is contained somewhere in the dynamic info section. We have to go
740 to a lot more work to discover the address of the debug base symbol.
741 Because of this complexity, we cache the value we find and return that
742 value on subsequent invocations. Note there is no copy in the
743 executable symbol tables.
744
745 */
746
747static CORE_ADDR
748locate_base (void)
749{
13437d4b
KB
750 /* Check to see if we have a currently valid address, and if so, avoid
751 doing all this work again and just return the cached address. If
752 we have no cached address, try to locate it in the dynamic info
d5a921c9
KB
753 section for ELF executables. There's no point in doing any of this
754 though if we don't have some link map offsets to work with. */
13437d4b 755
d5a921c9 756 if (debug_base == 0 && svr4_have_link_map_offsets ())
13437d4b
KB
757 {
758 if (exec_bfd != NULL
759 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
760 debug_base = elf_locate_base ();
13437d4b
KB
761 }
762 return (debug_base);
13437d4b
KB
763}
764
e4cd0d6a
MK
765/* Find the first element in the inferior's dynamic link map, and
766 return its address in the inferior.
13437d4b 767
e4cd0d6a
MK
768 FIXME: Perhaps we should validate the info somehow, perhaps by
769 checking r_version for a known version number, or r_state for
770 RT_CONSISTENT. */
13437d4b
KB
771
772static CORE_ADDR
e4cd0d6a 773solib_svr4_r_map (void)
13437d4b 774{
4b188b9f 775 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 776 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
13437d4b 777
b6da22b0 778 return read_memory_typed_address (debug_base + lmo->r_map_offset, ptr_type);
e4cd0d6a 779}
13437d4b 780
7cd25cfc
DJ
781/* Find r_brk from the inferior's debug base. */
782
783static CORE_ADDR
784solib_svr4_r_brk (void)
785{
786 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 787 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
7cd25cfc 788
b6da22b0 789 return read_memory_typed_address (debug_base + lmo->r_brk_offset, ptr_type);
7cd25cfc
DJ
790}
791
e4cd0d6a
MK
792/* Find the link map for the dynamic linker (if it is not in the
793 normal list of loaded shared objects). */
13437d4b 794
e4cd0d6a
MK
795static CORE_ADDR
796solib_svr4_r_ldsomap (void)
797{
798 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0 799 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
e4cd0d6a 800 ULONGEST version;
13437d4b 801
e4cd0d6a
MK
802 /* Check version, and return zero if `struct r_debug' doesn't have
803 the r_ldsomap member. */
804 version = read_memory_unsigned_integer (debug_base + lmo->r_version_offset,
805 lmo->r_version_size);
806 if (version < 2 || lmo->r_ldsomap_offset == -1)
807 return 0;
13437d4b 808
e4cd0d6a 809 return read_memory_typed_address (debug_base + lmo->r_ldsomap_offset,
b6da22b0 810 ptr_type);
13437d4b
KB
811}
812
13437d4b
KB
813/*
814
815 LOCAL FUNCTION
816
817 open_symbol_file_object
818
819 SYNOPSIS
820
821 void open_symbol_file_object (void *from_tty)
822
823 DESCRIPTION
824
825 If no open symbol file, attempt to locate and open the main symbol
826 file. On SVR4 systems, this is the first link map entry. If its
827 name is here, we can open it. Useful when attaching to a process
828 without first loading its symbol file.
829
830 If FROM_TTYP dereferences to a non-zero integer, allow messages to
831 be printed. This parameter is a pointer rather than an int because
832 open_symbol_file_object() is called via catch_errors() and
833 catch_errors() requires a pointer argument. */
834
835static int
836open_symbol_file_object (void *from_ttyp)
837{
838 CORE_ADDR lm, l_name;
839 char *filename;
840 int errcode;
841 int from_tty = *(int *)from_ttyp;
4b188b9f 842 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
b6da22b0
UW
843 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
844 int l_name_size = TYPE_LENGTH (ptr_type);
cfaefc65 845 gdb_byte *l_name_buf = xmalloc (l_name_size);
b8c9b27d 846 struct cleanup *cleanups = make_cleanup (xfree, l_name_buf);
13437d4b
KB
847
848 if (symfile_objfile)
9e2f0ad4 849 if (!query (_("Attempt to reload symbols from process? ")))
13437d4b
KB
850 return 0;
851
7cd25cfc
DJ
852 /* Always locate the debug struct, in case it has moved. */
853 debug_base = 0;
854 if (locate_base () == 0)
13437d4b
KB
855 return 0; /* failed somehow... */
856
857 /* First link map member should be the executable. */
e4cd0d6a
MK
858 lm = solib_svr4_r_map ();
859 if (lm == 0)
13437d4b
KB
860 return 0; /* failed somehow... */
861
862 /* Read address of name from target memory to GDB. */
cfaefc65 863 read_memory (lm + lmo->l_name_offset, l_name_buf, l_name_size);
13437d4b 864
cfaefc65 865 /* Convert the address to host format. */
b6da22b0 866 l_name = extract_typed_address (l_name_buf, ptr_type);
13437d4b
KB
867
868 /* Free l_name_buf. */
869 do_cleanups (cleanups);
870
871 if (l_name == 0)
872 return 0; /* No filename. */
873
874 /* Now fetch the filename from target memory. */
875 target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
ea5bf0a1 876 make_cleanup (xfree, filename);
13437d4b
KB
877
878 if (errcode)
879 {
8a3fe4f8 880 warning (_("failed to read exec filename from attached file: %s"),
13437d4b
KB
881 safe_strerror (errcode));
882 return 0;
883 }
884
13437d4b 885 /* Have a pathname: read the symbol file. */
1adeb98a 886 symbol_file_add_main (filename, from_tty);
13437d4b
KB
887
888 return 1;
889}
13437d4b 890
34439770
DJ
891/* If no shared library information is available from the dynamic
892 linker, build a fallback list from other sources. */
893
894static struct so_list *
895svr4_default_sos (void)
896{
897 struct so_list *head = NULL;
898 struct so_list **link_ptr = &head;
899
900 if (debug_loader_offset_p)
901 {
902 struct so_list *new = XZALLOC (struct so_list);
903
904 new->lm_info = xmalloc (sizeof (struct lm_info));
905
906 /* Nothing will ever check the cached copy of the link
907 map if we set l_addr. */
908 new->lm_info->l_addr = debug_loader_offset;
93a57060 909 new->lm_info->lm_addr = 0;
34439770
DJ
910 new->lm_info->lm = NULL;
911
912 strncpy (new->so_name, debug_loader_name, SO_NAME_MAX_PATH_SIZE - 1);
913 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
914 strcpy (new->so_original_name, new->so_name);
915
916 *link_ptr = new;
917 link_ptr = &new->next;
918 }
919
920 return head;
921}
922
13437d4b
KB
923/* LOCAL FUNCTION
924
925 current_sos -- build a list of currently loaded shared objects
926
927 SYNOPSIS
928
929 struct so_list *current_sos ()
930
931 DESCRIPTION
932
933 Build a list of `struct so_list' objects describing the shared
934 objects currently loaded in the inferior. This list does not
935 include an entry for the main executable file.
936
937 Note that we only gather information directly available from the
938 inferior --- we don't examine any of the shared library files
939 themselves. The declaration of `struct so_list' says which fields
940 we provide values for. */
941
942static struct so_list *
943svr4_current_sos (void)
944{
945 CORE_ADDR lm;
946 struct so_list *head = 0;
947 struct so_list **link_ptr = &head;
e4cd0d6a 948 CORE_ADDR ldsomap = 0;
13437d4b 949
7cd25cfc
DJ
950 /* Always locate the debug struct, in case it has moved. */
951 debug_base = 0;
952 locate_base ();
13437d4b 953
7cd25cfc
DJ
954 /* If we can't find the dynamic linker's base structure, this
955 must not be a dynamically linked executable. Hmm. */
956 if (! debug_base)
957 return svr4_default_sos ();
13437d4b
KB
958
959 /* Walk the inferior's link map list, and build our list of
960 `struct so_list' nodes. */
e4cd0d6a 961 lm = solib_svr4_r_map ();
34439770 962
13437d4b
KB
963 while (lm)
964 {
4b188b9f 965 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
f4456994 966 struct so_list *new = XZALLOC (struct so_list);
b8c9b27d 967 struct cleanup *old_chain = make_cleanup (xfree, new);
13437d4b 968
13437d4b 969 new->lm_info = xmalloc (sizeof (struct lm_info));
b8c9b27d 970 make_cleanup (xfree, new->lm_info);
13437d4b 971
831004b7 972 new->lm_info->l_addr = (CORE_ADDR)-1;
93a57060 973 new->lm_info->lm_addr = lm;
f4456994 974 new->lm_info->lm = xzalloc (lmo->link_map_size);
b8c9b27d 975 make_cleanup (xfree, new->lm_info->lm);
13437d4b
KB
976
977 read_memory (lm, new->lm_info->lm, lmo->link_map_size);
978
979 lm = LM_NEXT (new);
980
981 /* For SVR4 versions, the first entry in the link map is for the
982 inferior executable, so we must ignore it. For some versions of
983 SVR4, it has no name. For others (Solaris 2.3 for example), it
984 does have a name, so we can no longer use a missing name to
985 decide when to ignore it. */
e4cd0d6a 986 if (IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
93a57060
DJ
987 {
988 main_lm_addr = new->lm_info->lm_addr;
989 free_so (new);
990 }
13437d4b
KB
991 else
992 {
993 int errcode;
994 char *buffer;
995
996 /* Extract this shared object's name. */
997 target_read_string (LM_NAME (new), &buffer,
998 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
999 if (errcode != 0)
8a3fe4f8
AC
1000 warning (_("Can't read pathname for load map: %s."),
1001 safe_strerror (errcode));
13437d4b
KB
1002 else
1003 {
1004 strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
1005 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
13437d4b
KB
1006 strcpy (new->so_original_name, new->so_name);
1007 }
ea5bf0a1 1008 xfree (buffer);
13437d4b
KB
1009
1010 /* If this entry has no name, or its name matches the name
1011 for the main executable, don't include it in the list. */
1012 if (! new->so_name[0]
1013 || match_main (new->so_name))
1014 free_so (new);
1015 else
1016 {
1017 new->next = 0;
1018 *link_ptr = new;
1019 link_ptr = &new->next;
1020 }
1021 }
1022
e4cd0d6a
MK
1023 /* On Solaris, the dynamic linker is not in the normal list of
1024 shared objects, so make sure we pick it up too. Having
1025 symbol information for the dynamic linker is quite crucial
1026 for skipping dynamic linker resolver code. */
1027 if (lm == 0 && ldsomap == 0)
1028 lm = ldsomap = solib_svr4_r_ldsomap ();
1029
13437d4b
KB
1030 discard_cleanups (old_chain);
1031 }
1032
34439770
DJ
1033 if (head == NULL)
1034 return svr4_default_sos ();
1035
13437d4b
KB
1036 return head;
1037}
1038
93a57060 1039/* Get the address of the link_map for a given OBJFILE. */
bc4a16ae
EZ
1040
1041CORE_ADDR
1042svr4_fetch_objfile_link_map (struct objfile *objfile)
1043{
93a57060 1044 struct so_list *so;
bc4a16ae 1045
93a57060
DJ
1046 /* Cause svr4_current_sos() to be run if it hasn't been already. */
1047 if (main_lm_addr == 0)
1048 solib_add (NULL, 0, &current_target, auto_solib_add);
bc4a16ae 1049
93a57060
DJ
1050 /* svr4_current_sos() will set main_lm_addr for the main executable. */
1051 if (objfile == symfile_objfile)
1052 return main_lm_addr;
1053
1054 /* The other link map addresses may be found by examining the list
1055 of shared libraries. */
1056 for (so = master_so_list (); so; so = so->next)
1057 if (so->objfile == objfile)
1058 return so->lm_info->lm_addr;
1059
1060 /* Not found! */
bc4a16ae
EZ
1061 return 0;
1062}
13437d4b
KB
1063
1064/* On some systems, the only way to recognize the link map entry for
1065 the main executable file is by looking at its name. Return
1066 non-zero iff SONAME matches one of the known main executable names. */
1067
1068static int
1069match_main (char *soname)
1070{
1071 char **mainp;
1072
1073 for (mainp = main_name_list; *mainp != NULL; mainp++)
1074 {
1075 if (strcmp (soname, *mainp) == 0)
1076 return (1);
1077 }
1078
1079 return (0);
1080}
1081
13437d4b
KB
1082/* Return 1 if PC lies in the dynamic symbol resolution code of the
1083 SVR4 run time loader. */
13437d4b
KB
1084static CORE_ADDR interp_text_sect_low;
1085static CORE_ADDR interp_text_sect_high;
1086static CORE_ADDR interp_plt_sect_low;
1087static CORE_ADDR interp_plt_sect_high;
1088
7d522c90 1089int
d7fa2ae2 1090svr4_in_dynsym_resolve_code (CORE_ADDR pc)
13437d4b
KB
1091{
1092 return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
1093 || (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
1094 || in_plt_section (pc, NULL));
1095}
13437d4b 1096
2f4950cd
AC
1097/* Given an executable's ABFD and target, compute the entry-point
1098 address. */
1099
1100static CORE_ADDR
1101exec_entry_point (struct bfd *abfd, struct target_ops *targ)
1102{
1103 /* KevinB wrote ... for most targets, the address returned by
1104 bfd_get_start_address() is the entry point for the start
1105 function. But, for some targets, bfd_get_start_address() returns
1106 the address of a function descriptor from which the entry point
1107 address may be extracted. This address is extracted by
1108 gdbarch_convert_from_func_ptr_addr(). The method
1109 gdbarch_convert_from_func_ptr_addr() is the merely the identify
1110 function for targets which don't use function descriptors. */
1cf3db46 1111 return gdbarch_convert_from_func_ptr_addr (target_gdbarch,
2f4950cd
AC
1112 bfd_get_start_address (abfd),
1113 targ);
1114}
13437d4b
KB
1115
1116/*
1117
1118 LOCAL FUNCTION
1119
1120 enable_break -- arrange for dynamic linker to hit breakpoint
1121
1122 SYNOPSIS
1123
1124 int enable_break (void)
1125
1126 DESCRIPTION
1127
1128 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1129 debugger interface, support for arranging for the inferior to hit
1130 a breakpoint after mapping in the shared libraries. This function
1131 enables that breakpoint.
1132
1133 For SunOS, there is a special flag location (in_debugger) which we
1134 set to 1. When the dynamic linker sees this flag set, it will set
1135 a breakpoint at a location known only to itself, after saving the
1136 original contents of that place and the breakpoint address itself,
1137 in it's own internal structures. When we resume the inferior, it
1138 will eventually take a SIGTRAP when it runs into the breakpoint.
1139 We handle this (in a different place) by restoring the contents of
1140 the breakpointed location (which is only known after it stops),
1141 chasing around to locate the shared libraries that have been
1142 loaded, then resuming.
1143
1144 For SVR4, the debugger interface structure contains a member (r_brk)
1145 which is statically initialized at the time the shared library is
1146 built, to the offset of a function (_r_debug_state) which is guaran-
1147 teed to be called once before mapping in a library, and again when
1148 the mapping is complete. At the time we are examining this member,
1149 it contains only the unrelocated offset of the function, so we have
1150 to do our own relocation. Later, when the dynamic linker actually
1151 runs, it relocates r_brk to be the actual address of _r_debug_state().
1152
1153 The debugger interface structure also contains an enumeration which
1154 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1155 depending upon whether or not the library is being mapped or unmapped,
1156 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1157 */
1158
1159static int
1160enable_break (void)
1161{
13437d4b
KB
1162 struct minimal_symbol *msymbol;
1163 char **bkpt_namep;
1164 asection *interp_sect;
97ec2c2f 1165 gdb_byte *interp_name;
7cd25cfc 1166 CORE_ADDR sym_addr;
13437d4b
KB
1167
1168 /* First, remove all the solib event breakpoints. Their addresses
1169 may have changed since the last time we ran the program. */
1170 remove_solib_event_breakpoints ();
1171
13437d4b
KB
1172 interp_text_sect_low = interp_text_sect_high = 0;
1173 interp_plt_sect_low = interp_plt_sect_high = 0;
1174
7cd25cfc
DJ
1175 /* If we already have a shared library list in the target, and
1176 r_debug contains r_brk, set the breakpoint there - this should
1177 mean r_brk has already been relocated. Assume the dynamic linker
1178 is the object containing r_brk. */
1179
1180 solib_add (NULL, 0, &current_target, auto_solib_add);
1181 sym_addr = 0;
1182 if (debug_base && solib_svr4_r_map () != 0)
1183 sym_addr = solib_svr4_r_brk ();
1184
1185 if (sym_addr != 0)
1186 {
1187 struct obj_section *os;
1188
b36ec657 1189 sym_addr = gdbarch_addr_bits_remove
1cf3db46 1190 (target_gdbarch, gdbarch_convert_from_func_ptr_addr (target_gdbarch,
b36ec657
DJ
1191 sym_addr,
1192 &current_target));
1193
7cd25cfc
DJ
1194 os = find_pc_section (sym_addr);
1195 if (os != NULL)
1196 {
1197 /* Record the relocated start and end address of the dynamic linker
1198 text and plt section for svr4_in_dynsym_resolve_code. */
1199 bfd *tmp_bfd;
1200 CORE_ADDR load_addr;
1201
1202 tmp_bfd = os->objfile->obfd;
1203 load_addr = ANOFFSET (os->objfile->section_offsets,
1204 os->objfile->sect_index_text);
1205
1206 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1207 if (interp_sect)
1208 {
1209 interp_text_sect_low =
1210 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1211 interp_text_sect_high =
1212 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1213 }
1214 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1215 if (interp_sect)
1216 {
1217 interp_plt_sect_low =
1218 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1219 interp_plt_sect_high =
1220 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1221 }
1222
1223 create_solib_event_breakpoint (sym_addr);
1224 return 1;
1225 }
1226 }
1227
97ec2c2f 1228 /* Find the program interpreter; if not found, warn the user and drop
13437d4b 1229 into the old breakpoint at symbol code. */
97ec2c2f
UW
1230 interp_name = find_program_interpreter ();
1231 if (interp_name)
13437d4b 1232 {
8ad2fcde
KB
1233 CORE_ADDR load_addr = 0;
1234 int load_addr_found = 0;
2ec9a4f8 1235 int loader_found_in_list = 0;
f8766ec1 1236 struct so_list *so;
e4f7b8c8 1237 bfd *tmp_bfd = NULL;
2f4950cd 1238 struct target_ops *tmp_bfd_target;
f1838a98 1239 volatile struct gdb_exception ex;
13437d4b 1240
7cd25cfc 1241 sym_addr = 0;
13437d4b
KB
1242
1243 /* Now we need to figure out where the dynamic linker was
1244 loaded so that we can load its symbols and place a breakpoint
1245 in the dynamic linker itself.
1246
1247 This address is stored on the stack. However, I've been unable
1248 to find any magic formula to find it for Solaris (appears to
1249 be trivial on GNU/Linux). Therefore, we have to try an alternate
1250 mechanism to find the dynamic linker's base address. */
e4f7b8c8 1251
f1838a98
UW
1252 TRY_CATCH (ex, RETURN_MASK_ALL)
1253 {
97ec2c2f 1254 tmp_bfd = solib_bfd_open (interp_name);
f1838a98 1255 }
13437d4b
KB
1256 if (tmp_bfd == NULL)
1257 goto bkpt_at_symbol;
1258
2f4950cd
AC
1259 /* Now convert the TMP_BFD into a target. That way target, as
1260 well as BFD operations can be used. Note that closing the
1261 target will also close the underlying bfd. */
1262 tmp_bfd_target = target_bfd_reopen (tmp_bfd);
1263
f8766ec1
KB
1264 /* On a running target, we can get the dynamic linker's base
1265 address from the shared library table. */
f8766ec1
KB
1266 so = master_so_list ();
1267 while (so)
8ad2fcde 1268 {
97ec2c2f 1269 if (svr4_same_1 (interp_name, so->so_original_name))
8ad2fcde
KB
1270 {
1271 load_addr_found = 1;
2ec9a4f8 1272 loader_found_in_list = 1;
cc10cae3 1273 load_addr = LM_ADDR_CHECK (so, tmp_bfd);
8ad2fcde
KB
1274 break;
1275 }
f8766ec1 1276 so = so->next;
8ad2fcde
KB
1277 }
1278
8d4e36ba
JB
1279 /* If we were not able to find the base address of the loader
1280 from our so_list, then try using the AT_BASE auxilliary entry. */
1281 if (!load_addr_found)
1282 if (target_auxv_search (&current_target, AT_BASE, &load_addr) > 0)
1283 load_addr_found = 1;
1284
8ad2fcde
KB
1285 /* Otherwise we find the dynamic linker's base address by examining
1286 the current pc (which should point at the entry point for the
8d4e36ba
JB
1287 dynamic linker) and subtracting the offset of the entry point.
1288
1289 This is more fragile than the previous approaches, but is a good
1290 fallback method because it has actually been working well in
1291 most cases. */
8ad2fcde 1292 if (!load_addr_found)
fb14de7b
UW
1293 {
1294 struct regcache *regcache = get_thread_regcache (inferior_ptid);
1295 load_addr = (regcache_read_pc (regcache)
1296 - exec_entry_point (tmp_bfd, tmp_bfd_target));
1297 }
2ec9a4f8
DJ
1298
1299 if (!loader_found_in_list)
34439770 1300 {
97ec2c2f 1301 debug_loader_name = xstrdup (interp_name);
34439770
DJ
1302 debug_loader_offset_p = 1;
1303 debug_loader_offset = load_addr;
2bbe3cc1 1304 solib_add (NULL, 0, &current_target, auto_solib_add);
34439770 1305 }
13437d4b
KB
1306
1307 /* Record the relocated start and end address of the dynamic linker
d7fa2ae2 1308 text and plt section for svr4_in_dynsym_resolve_code. */
13437d4b
KB
1309 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1310 if (interp_sect)
1311 {
1312 interp_text_sect_low =
1313 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1314 interp_text_sect_high =
1315 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1316 }
1317 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1318 if (interp_sect)
1319 {
1320 interp_plt_sect_low =
1321 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1322 interp_plt_sect_high =
1323 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1324 }
1325
1326 /* Now try to set a breakpoint in the dynamic linker. */
1327 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1328 {
2bbe3cc1 1329 sym_addr = bfd_lookup_symbol (tmp_bfd, *bkpt_namep);
13437d4b
KB
1330 if (sym_addr != 0)
1331 break;
1332 }
1333
2bbe3cc1
DJ
1334 if (sym_addr != 0)
1335 /* Convert 'sym_addr' from a function pointer to an address.
1336 Because we pass tmp_bfd_target instead of the current
1337 target, this will always produce an unrelocated value. */
1cf3db46 1338 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
2bbe3cc1
DJ
1339 sym_addr,
1340 tmp_bfd_target);
1341
2f4950cd
AC
1342 /* We're done with both the temporary bfd and target. Remember,
1343 closing the target closes the underlying bfd. */
1344 target_close (tmp_bfd_target, 0);
13437d4b
KB
1345
1346 if (sym_addr != 0)
1347 {
1348 create_solib_event_breakpoint (load_addr + sym_addr);
97ec2c2f 1349 xfree (interp_name);
13437d4b
KB
1350 return 1;
1351 }
1352
1353 /* For whatever reason we couldn't set a breakpoint in the dynamic
1354 linker. Warn and drop into the old code. */
1355 bkpt_at_symbol:
97ec2c2f 1356 xfree (interp_name);
82d03102
PG
1357 warning (_("Unable to find dynamic linker breakpoint function.\n"
1358 "GDB will be unable to debug shared library initializers\n"
1359 "and track explicitly loaded dynamic code."));
13437d4b 1360 }
13437d4b 1361
e499d0f1
DJ
1362 /* Scan through the lists of symbols, trying to look up the symbol and
1363 set a breakpoint there. Terminate loop when we/if we succeed. */
1364
1365 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1366 {
1367 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1368 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1369 {
1370 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1371 return 1;
1372 }
1373 }
13437d4b 1374
13437d4b
KB
1375 for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
1376 {
1377 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1378 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1379 {
1380 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1381 return 1;
1382 }
1383 }
542c95c2 1384 return 0;
13437d4b
KB
1385}
1386
1387/*
1388
1389 LOCAL FUNCTION
1390
1391 special_symbol_handling -- additional shared library symbol handling
1392
1393 SYNOPSIS
1394
1395 void special_symbol_handling ()
1396
1397 DESCRIPTION
1398
1399 Once the symbols from a shared object have been loaded in the usual
1400 way, we are called to do any system specific symbol handling that
1401 is needed.
1402
ab31aa69 1403 For SunOS4, this consisted of grunging around in the dynamic
13437d4b
KB
1404 linkers structures to find symbol definitions for "common" symbols
1405 and adding them to the minimal symbol table for the runtime common
1406 objfile.
1407
ab31aa69
KB
1408 However, for SVR4, there's nothing to do.
1409
13437d4b
KB
1410 */
1411
1412static void
1413svr4_special_symbol_handling (void)
1414{
13437d4b
KB
1415}
1416
e2a44558
KB
1417/* Relocate the main executable. This function should be called upon
1418 stopping the inferior process at the entry point to the program.
1419 The entry point from BFD is compared to the PC and if they are
1420 different, the main executable is relocated by the proper amount.
1421
1422 As written it will only attempt to relocate executables which
1423 lack interpreter sections. It seems likely that only dynamic
1424 linker executables will get relocated, though it should work
1425 properly for a position-independent static executable as well. */
1426
1427static void
1428svr4_relocate_main_executable (void)
1429{
1430 asection *interp_sect;
fb14de7b
UW
1431 struct regcache *regcache = get_thread_regcache (inferior_ptid);
1432 CORE_ADDR pc = regcache_read_pc (regcache);
e2a44558
KB
1433
1434 /* Decide if the objfile needs to be relocated. As indicated above,
1435 we will only be here when execution is stopped at the beginning
1436 of the program. Relocation is necessary if the address at which
1437 we are presently stopped differs from the start address stored in
1438 the executable AND there's no interpreter section. The condition
1439 regarding the interpreter section is very important because if
1440 there *is* an interpreter section, execution will begin there
1441 instead. When there is an interpreter section, the start address
1442 is (presumably) used by the interpreter at some point to start
1443 execution of the program.
1444
1445 If there is an interpreter, it is normal for it to be set to an
1446 arbitrary address at the outset. The job of finding it is
1447 handled in enable_break().
1448
1449 So, to summarize, relocations are necessary when there is no
1450 interpreter section and the start address obtained from the
1451 executable is different from the address at which GDB is
1452 currently stopped.
1453
1454 [ The astute reader will note that we also test to make sure that
1455 the executable in question has the DYNAMIC flag set. It is my
1456 opinion that this test is unnecessary (undesirable even). It
1457 was added to avoid inadvertent relocation of an executable
1458 whose e_type member in the ELF header is not ET_DYN. There may
1459 be a time in the future when it is desirable to do relocations
1460 on other types of files as well in which case this condition
1461 should either be removed or modified to accomodate the new file
1462 type. (E.g, an ET_EXEC executable which has been built to be
1463 position-independent could safely be relocated by the OS if
1464 desired. It is true that this violates the ABI, but the ABI
1465 has been known to be bent from time to time.) - Kevin, Nov 2000. ]
1466 */
1467
1468 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
1469 if (interp_sect == NULL
1470 && (bfd_get_file_flags (exec_bfd) & DYNAMIC) != 0
2f4950cd 1471 && (exec_entry_point (exec_bfd, &exec_ops) != pc))
e2a44558
KB
1472 {
1473 struct cleanup *old_chain;
1474 struct section_offsets *new_offsets;
1475 int i, changed;
1476 CORE_ADDR displacement;
1477
1478 /* It is necessary to relocate the objfile. The amount to
1479 relocate by is simply the address at which we are stopped
1480 minus the starting address from the executable.
1481
1482 We relocate all of the sections by the same amount. This
1483 behavior is mandated by recent editions of the System V ABI.
1484 According to the System V Application Binary Interface,
1485 Edition 4.1, page 5-5:
1486
1487 ... Though the system chooses virtual addresses for
1488 individual processes, it maintains the segments' relative
1489 positions. Because position-independent code uses relative
1490 addressesing between segments, the difference between
1491 virtual addresses in memory must match the difference
1492 between virtual addresses in the file. The difference
1493 between the virtual address of any segment in memory and
1494 the corresponding virtual address in the file is thus a
1495 single constant value for any one executable or shared
1496 object in a given process. This difference is the base
1497 address. One use of the base address is to relocate the
1498 memory image of the program during dynamic linking.
1499
1500 The same language also appears in Edition 4.0 of the System V
1501 ABI and is left unspecified in some of the earlier editions. */
1502
2f4950cd 1503 displacement = pc - exec_entry_point (exec_bfd, &exec_ops);
e2a44558
KB
1504 changed = 0;
1505
13fc0c2f
KB
1506 new_offsets = xcalloc (symfile_objfile->num_sections,
1507 sizeof (struct section_offsets));
b8c9b27d 1508 old_chain = make_cleanup (xfree, new_offsets);
e2a44558
KB
1509
1510 for (i = 0; i < symfile_objfile->num_sections; i++)
1511 {
1512 if (displacement != ANOFFSET (symfile_objfile->section_offsets, i))
1513 changed = 1;
1514 new_offsets->offsets[i] = displacement;
1515 }
1516
1517 if (changed)
1518 objfile_relocate (symfile_objfile, new_offsets);
1519
1520 do_cleanups (old_chain);
1521 }
1522}
1523
13437d4b
KB
1524/*
1525
1526 GLOBAL FUNCTION
1527
1528 svr4_solib_create_inferior_hook -- shared library startup support
1529
1530 SYNOPSIS
1531
7095b863 1532 void svr4_solib_create_inferior_hook ()
13437d4b
KB
1533
1534 DESCRIPTION
1535
1536 When gdb starts up the inferior, it nurses it along (through the
1537 shell) until it is ready to execute it's first instruction. At this
1538 point, this function gets called via expansion of the macro
1539 SOLIB_CREATE_INFERIOR_HOOK.
1540
1541 For SunOS executables, this first instruction is typically the
1542 one at "_start", or a similar text label, regardless of whether
1543 the executable is statically or dynamically linked. The runtime
1544 startup code takes care of dynamically linking in any shared
1545 libraries, once gdb allows the inferior to continue.
1546
1547 For SVR4 executables, this first instruction is either the first
1548 instruction in the dynamic linker (for dynamically linked
1549 executables) or the instruction at "start" for statically linked
1550 executables. For dynamically linked executables, the system
1551 first exec's /lib/libc.so.N, which contains the dynamic linker,
1552 and starts it running. The dynamic linker maps in any needed
1553 shared libraries, maps in the actual user executable, and then
1554 jumps to "start" in the user executable.
1555
1556 For both SunOS shared libraries, and SVR4 shared libraries, we
1557 can arrange to cooperate with the dynamic linker to discover the
1558 names of shared libraries that are dynamically linked, and the
1559 base addresses to which they are linked.
1560
1561 This function is responsible for discovering those names and
1562 addresses, and saving sufficient information about them to allow
1563 their symbols to be read at a later time.
1564
1565 FIXME
1566
1567 Between enable_break() and disable_break(), this code does not
1568 properly handle hitting breakpoints which the user might have
1569 set in the startup code or in the dynamic linker itself. Proper
1570 handling will probably have to wait until the implementation is
1571 changed to use the "breakpoint handler function" method.
1572
1573 Also, what if child has exit()ed? Must exit loop somehow.
1574 */
1575
e2a44558 1576static void
13437d4b
KB
1577svr4_solib_create_inferior_hook (void)
1578{
d6b48e9c 1579 struct inferior *inf;
2020b7ab
PA
1580 struct thread_info *tp;
1581
e2a44558
KB
1582 /* Relocate the main executable if necessary. */
1583 svr4_relocate_main_executable ();
1584
d5a921c9 1585 if (!svr4_have_link_map_offsets ())
513f5903 1586 return;
d5a921c9 1587
13437d4b 1588 if (!enable_break ())
542c95c2 1589 return;
13437d4b 1590
ab31aa69
KB
1591#if defined(_SCO_DS)
1592 /* SCO needs the loop below, other systems should be using the
13437d4b
KB
1593 special shared library breakpoints and the shared library breakpoint
1594 service routine.
1595
1596 Now run the target. It will eventually hit the breakpoint, at
1597 which point all of the libraries will have been mapped in and we
1598 can go groveling around in the dynamic linker structures to find
1599 out what we need to know about them. */
1600
d6b48e9c 1601 inf = current_inferior ();
2020b7ab
PA
1602 tp = inferior_thread ();
1603
13437d4b 1604 clear_proceed_status ();
d6b48e9c 1605 inf->stop_soon = STOP_QUIETLY;
2020b7ab 1606 tp->stop_signal = TARGET_SIGNAL_0;
13437d4b
KB
1607 do
1608 {
2020b7ab 1609 target_resume (pid_to_ptid (-1), 0, tp->stop_signal);
ae123ec6 1610 wait_for_inferior (0);
13437d4b 1611 }
2020b7ab 1612 while (tp->stop_signal != TARGET_SIGNAL_TRAP);
d6b48e9c 1613 inf->stop_soon = NO_STOP_QUIETLY;
ab31aa69 1614#endif /* defined(_SCO_DS) */
13437d4b
KB
1615}
1616
1617static void
1618svr4_clear_solib (void)
1619{
1620 debug_base = 0;
34439770
DJ
1621 debug_loader_offset_p = 0;
1622 debug_loader_offset = 0;
1623 xfree (debug_loader_name);
1624 debug_loader_name = NULL;
93a57060 1625 main_lm_addr = 0;
13437d4b
KB
1626}
1627
1628static void
1629svr4_free_so (struct so_list *so)
1630{
b8c9b27d
KB
1631 xfree (so->lm_info->lm);
1632 xfree (so->lm_info);
13437d4b
KB
1633}
1634
6bb7be43
JB
1635
1636/* Clear any bits of ADDR that wouldn't fit in a target-format
1637 data pointer. "Data pointer" here refers to whatever sort of
1638 address the dynamic linker uses to manage its sections. At the
1639 moment, we don't support shared libraries on any processors where
1640 code and data pointers are different sizes.
1641
1642 This isn't really the right solution. What we really need here is
1643 a way to do arithmetic on CORE_ADDR values that respects the
1644 natural pointer/address correspondence. (For example, on the MIPS,
1645 converting a 32-bit pointer to a 64-bit CORE_ADDR requires you to
1646 sign-extend the value. There, simply truncating the bits above
819844ad 1647 gdbarch_ptr_bit, as we do below, is no good.) This should probably
6bb7be43
JB
1648 be a new gdbarch method or something. */
1649static CORE_ADDR
1650svr4_truncate_ptr (CORE_ADDR addr)
1651{
1cf3db46 1652 if (gdbarch_ptr_bit (target_gdbarch) == sizeof (CORE_ADDR) * 8)
6bb7be43
JB
1653 /* We don't need to truncate anything, and the bit twiddling below
1654 will fail due to overflow problems. */
1655 return addr;
1656 else
1cf3db46 1657 return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (target_gdbarch)) - 1);
6bb7be43
JB
1658}
1659
1660
749499cb
KB
1661static void
1662svr4_relocate_section_addresses (struct so_list *so,
1663 struct section_table *sec)
1664{
cc10cae3
AO
1665 sec->addr = svr4_truncate_ptr (sec->addr + LM_ADDR_CHECK (so,
1666 sec->bfd));
1667 sec->endaddr = svr4_truncate_ptr (sec->endaddr + LM_ADDR_CHECK (so,
1668 sec->bfd));
749499cb 1669}
4b188b9f 1670\f
749499cb 1671
4b188b9f 1672/* Architecture-specific operations. */
6bb7be43 1673
4b188b9f
MK
1674/* Per-architecture data key. */
1675static struct gdbarch_data *solib_svr4_data;
e5e2b9ff 1676
4b188b9f 1677struct solib_svr4_ops
e5e2b9ff 1678{
4b188b9f
MK
1679 /* Return a description of the layout of `struct link_map'. */
1680 struct link_map_offsets *(*fetch_link_map_offsets)(void);
1681};
e5e2b9ff 1682
4b188b9f 1683/* Return a default for the architecture-specific operations. */
e5e2b9ff 1684
4b188b9f
MK
1685static void *
1686solib_svr4_init (struct obstack *obstack)
e5e2b9ff 1687{
4b188b9f 1688 struct solib_svr4_ops *ops;
e5e2b9ff 1689
4b188b9f 1690 ops = OBSTACK_ZALLOC (obstack, struct solib_svr4_ops);
8d005789 1691 ops->fetch_link_map_offsets = NULL;
4b188b9f 1692 return ops;
e5e2b9ff
KB
1693}
1694
4b188b9f 1695/* Set the architecture-specific `struct link_map_offsets' fetcher for
7e3cb44c 1696 GDBARCH to FLMO. Also, install SVR4 solib_ops into GDBARCH. */
1c4dcb57 1697
21479ded 1698void
e5e2b9ff
KB
1699set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch,
1700 struct link_map_offsets *(*flmo) (void))
21479ded 1701{
4b188b9f
MK
1702 struct solib_svr4_ops *ops = gdbarch_data (gdbarch, solib_svr4_data);
1703
1704 ops->fetch_link_map_offsets = flmo;
7e3cb44c
UW
1705
1706 set_solib_ops (gdbarch, &svr4_so_ops);
21479ded
KB
1707}
1708
4b188b9f
MK
1709/* Fetch a link_map_offsets structure using the architecture-specific
1710 `struct link_map_offsets' fetcher. */
1c4dcb57 1711
4b188b9f
MK
1712static struct link_map_offsets *
1713svr4_fetch_link_map_offsets (void)
21479ded 1714{
1cf3db46 1715 struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
4b188b9f
MK
1716
1717 gdb_assert (ops->fetch_link_map_offsets);
1718 return ops->fetch_link_map_offsets ();
21479ded
KB
1719}
1720
4b188b9f
MK
1721/* Return 1 if a link map offset fetcher has been defined, 0 otherwise. */
1722
1723static int
1724svr4_have_link_map_offsets (void)
1725{
1cf3db46 1726 struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
4b188b9f
MK
1727 return (ops->fetch_link_map_offsets != NULL);
1728}
1729\f
1730
e4bbbda8
MK
1731/* Most OS'es that have SVR4-style ELF dynamic libraries define a
1732 `struct r_debug' and a `struct link_map' that are binary compatible
1733 with the origional SVR4 implementation. */
1734
1735/* Fetch (and possibly build) an appropriate `struct link_map_offsets'
1736 for an ILP32 SVR4 system. */
1737
1738struct link_map_offsets *
1739svr4_ilp32_fetch_link_map_offsets (void)
1740{
1741 static struct link_map_offsets lmo;
1742 static struct link_map_offsets *lmp = NULL;
1743
1744 if (lmp == NULL)
1745 {
1746 lmp = &lmo;
1747
e4cd0d6a
MK
1748 lmo.r_version_offset = 0;
1749 lmo.r_version_size = 4;
e4bbbda8 1750 lmo.r_map_offset = 4;
7cd25cfc 1751 lmo.r_brk_offset = 8;
e4cd0d6a 1752 lmo.r_ldsomap_offset = 20;
e4bbbda8
MK
1753
1754 /* Everything we need is in the first 20 bytes. */
1755 lmo.link_map_size = 20;
1756 lmo.l_addr_offset = 0;
e4bbbda8 1757 lmo.l_name_offset = 4;
cc10cae3 1758 lmo.l_ld_offset = 8;
e4bbbda8 1759 lmo.l_next_offset = 12;
e4bbbda8 1760 lmo.l_prev_offset = 16;
e4bbbda8
MK
1761 }
1762
1763 return lmp;
1764}
1765
1766/* Fetch (and possibly build) an appropriate `struct link_map_offsets'
1767 for an LP64 SVR4 system. */
1768
1769struct link_map_offsets *
1770svr4_lp64_fetch_link_map_offsets (void)
1771{
1772 static struct link_map_offsets lmo;
1773 static struct link_map_offsets *lmp = NULL;
1774
1775 if (lmp == NULL)
1776 {
1777 lmp = &lmo;
1778
e4cd0d6a
MK
1779 lmo.r_version_offset = 0;
1780 lmo.r_version_size = 4;
e4bbbda8 1781 lmo.r_map_offset = 8;
7cd25cfc 1782 lmo.r_brk_offset = 16;
e4cd0d6a 1783 lmo.r_ldsomap_offset = 40;
e4bbbda8
MK
1784
1785 /* Everything we need is in the first 40 bytes. */
1786 lmo.link_map_size = 40;
1787 lmo.l_addr_offset = 0;
e4bbbda8 1788 lmo.l_name_offset = 8;
cc10cae3 1789 lmo.l_ld_offset = 16;
e4bbbda8 1790 lmo.l_next_offset = 24;
e4bbbda8 1791 lmo.l_prev_offset = 32;
e4bbbda8
MK
1792 }
1793
1794 return lmp;
1795}
1796\f
1797
7d522c90 1798struct target_so_ops svr4_so_ops;
13437d4b 1799
3a40aaa0
UW
1800/* Lookup global symbol for ELF DSOs linked with -Bsymbolic. Those DSOs have a
1801 different rule for symbol lookup. The lookup begins here in the DSO, not in
1802 the main executable. */
1803
1804static struct symbol *
1805elf_lookup_lib_symbol (const struct objfile *objfile,
1806 const char *name,
1807 const char *linkage_name,
21b556f4 1808 const domain_enum domain)
3a40aaa0
UW
1809{
1810 if (objfile->obfd == NULL
1811 || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
1812 return NULL;
1813
65728c26 1814 return lookup_global_symbol_from_objfile
21b556f4 1815 (objfile, name, linkage_name, domain);
3a40aaa0
UW
1816}
1817
a78f21af
AC
1818extern initialize_file_ftype _initialize_svr4_solib; /* -Wmissing-prototypes */
1819
13437d4b
KB
1820void
1821_initialize_svr4_solib (void)
1822{
4b188b9f
MK
1823 solib_svr4_data = gdbarch_data_register_pre_init (solib_svr4_init);
1824
749499cb 1825 svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses;
13437d4b
KB
1826 svr4_so_ops.free_so = svr4_free_so;
1827 svr4_so_ops.clear_solib = svr4_clear_solib;
1828 svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook;
1829 svr4_so_ops.special_symbol_handling = svr4_special_symbol_handling;
1830 svr4_so_ops.current_sos = svr4_current_sos;
1831 svr4_so_ops.open_symbol_file_object = open_symbol_file_object;
d7fa2ae2 1832 svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code;
3a40aaa0 1833 svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
a7c02bc8 1834 svr4_so_ops.same = svr4_same;
13437d4b 1835}
This page took 1.114833 seconds and 4 git commands to generate.