Code cleanup: Move variable.
[platform/upstream/binutils.git] / gdb / solib-sunos.c
1 /* Handle SunOS shared libraries for GDB, the GNU Debugger.
2
3    Copyright (C) 1990-2013 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21
22 #include <sys/types.h>
23 #include <signal.h>
24 #include "gdb_string.h"
25 #include <fcntl.h>
26
27 /* SunOS shared libs need the nlist structure.  */
28 #include <a.out.h>
29 #include <link.h>
30
31 #include "symtab.h"
32 #include "bfd.h"
33 #include "symfile.h"
34 #include "objfiles.h"
35 #include "gdbcore.h"
36 #include "inferior.h"
37 #include "gdbthread.h"
38 #include "solist.h"
39 #include "bcache.h"
40 #include "regcache.h"
41
42 /* The shared library implementation found on BSD a.out systems is
43    very similar to the SunOS implementation.  However, the data
44    structures defined in <link.h> are named very differently.  Make up
45    for those differences here.  */
46
47 #ifdef HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
48
49 /* FIXME: Temporary until the equivalent defines have been removed
50    from all nm-*bsd*.h files.  */
51 #ifndef link_dynamic
52
53 /* Map `struct link_map' and its members.  */
54 #define link_map        so_map
55 #define lm_addr         som_addr
56 #define lm_name         som_path
57 #define lm_next         som_next
58
59 /* Map `struct link_dynamic_2' and its members.  */
60 #define link_dynamic_2  section_dispatch_table
61 #define ld_loaded       sdt_loaded
62
63 /* Map `struct rtc_symb' and its members.  */
64 #define rtc_symb        rt_symbol
65 #define rtc_sp          rt_sp
66 #define rtc_next        rt_next
67
68 /* Map `struct ld_debug' and its members.  */
69 #define ld_debug        so_debug
70 #define ldd_in_debugger dd_in_debugger
71 #define ldd_bp_addr     dd_bpt_addr
72 #define ldd_bp_inst     dd_bpt_shadow
73 #define ldd_cp          dd_cc
74
75 /* Map `struct link_dynamic' and its members.  */
76 #define link_dynamic    _dynamic
77 #define ld_version      d_version
78 #define ldd             d_debug
79 #define ld_un           d_un
80 #define ld_2            d_sdt
81
82 #endif
83
84 #endif
85
86 /* Link map info to include in an allocated so_list entry.  */
87
88 struct lm_info
89   {
90     /* Pointer to copy of link map from inferior.  The type is char *
91        rather than void *, so that we may use byte offsets to find the
92        various fields without the need for a cast.  */
93     char *lm;
94   };
95
96
97 /* Symbols which are used to locate the base of the link map structures.  */
98
99 static char *debug_base_symbols[] =
100 {
101   "_DYNAMIC",
102   "_DYNAMIC__MGC",
103   NULL
104 };
105
106 static char *main_name_list[] =
107 {
108   "main_$main",
109   NULL
110 };
111
112 /* Macro to extract an address from a solib structure.  When GDB is
113    configured for some 32-bit targets (e.g. Solaris 2.7 sparc), BFD is
114    configured to handle 64-bit targets, so CORE_ADDR is 64 bits.  We
115    have to extract only the significant bits of addresses to get the
116    right address when accessing the core file BFD.
117
118    Assume that the address is unsigned.  */
119
120 #define SOLIB_EXTRACT_ADDRESS(MEMBER) \
121         extract_unsigned_integer (&(MEMBER), sizeof (MEMBER), \
122                                   gdbarch_byte_order (target_gdbarch ()))
123
124 /* local data declarations */
125
126 static struct link_dynamic dynamic_copy;
127 static struct link_dynamic_2 ld_2_copy;
128 static struct ld_debug debug_copy;
129 static CORE_ADDR debug_addr;
130 static CORE_ADDR flag_addr;
131
132 #ifndef offsetof
133 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
134 #endif
135 #define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
136
137 /* link map access functions */
138
139 static CORE_ADDR
140 lm_addr (struct so_list *so)
141 {
142   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
143   int lm_addr_offset = offsetof (struct link_map, lm_addr);
144   int lm_addr_size = fieldsize (struct link_map, lm_addr);
145
146   return (CORE_ADDR) extract_signed_integer (so->lm_info->lm + lm_addr_offset, 
147                                              lm_addr_size, byte_order);
148 }
149
150 static CORE_ADDR
151 lm_next (struct so_list *so)
152 {
153   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
154   int lm_next_offset = offsetof (struct link_map, lm_next);
155   int lm_next_size = fieldsize (struct link_map, lm_next);
156
157   /* Assume that the address is unsigned.  */
158   return extract_unsigned_integer (so->lm_info->lm + lm_next_offset,
159                                    lm_next_size, byte_order);
160 }
161
162 static CORE_ADDR
163 lm_name (struct so_list *so)
164 {
165   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
166   int lm_name_offset = offsetof (struct link_map, lm_name);
167   int lm_name_size = fieldsize (struct link_map, lm_name);
168
169   /* Assume that the address is unsigned.  */
170   return extract_unsigned_integer (so->lm_info->lm + lm_name_offset,
171                                    lm_name_size, byte_order);
172 }
173
174 static CORE_ADDR debug_base;    /* Base of dynamic linker structures.  */
175
176 /* Local function prototypes */
177
178 static int match_main (char *);
179
180 /* Allocate the runtime common object file.  */
181
182 static void
183 allocate_rt_common_objfile (void)
184 {
185   struct objfile *objfile;
186   struct objfile *last_one;
187
188   objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
189   memset (objfile, 0, sizeof (struct objfile));
190   objfile->psymbol_cache = psymbol_bcache_init ();
191   objfile->macro_cache = bcache_xmalloc (NULL, NULL);
192   objfile->filename_cache = bcache_xmalloc (NULL, NULL);
193   obstack_init (&objfile->objfile_obstack);
194   objfile->name = xstrdup ("rt_common");
195
196   /* Add this file onto the tail of the linked list of other such files.  */
197
198   objfile->next = NULL;
199   if (object_files == NULL)
200     object_files = objfile;
201   else
202     {
203       for (last_one = object_files;
204            last_one->next;
205            last_one = last_one->next);
206       last_one->next = objfile;
207     }
208
209   rt_common_objfile = objfile;
210 }
211
212 /* Read all dynamically loaded common symbol definitions from the inferior
213    and put them into the minimal symbol table for the runtime common
214    objfile.  */
215
216 static void
217 solib_add_common_symbols (CORE_ADDR rtc_symp)
218 {
219   struct rtc_symb inferior_rtc_symb;
220   struct nlist inferior_rtc_nlist;
221   int len;
222   char *name;
223
224   /* Remove any runtime common symbols from previous runs.  */
225
226   if (rt_common_objfile != NULL && rt_common_objfile->minimal_symbol_count)
227     {
228       obstack_free (&rt_common_objfile->objfile_obstack, 0);
229       obstack_init (&rt_common_objfile->objfile_obstack);
230       rt_common_objfile->minimal_symbol_count = 0;
231       rt_common_objfile->msymbols = NULL;
232       terminate_minimal_symbol_table (rt_common_objfile);
233     }
234
235   init_minimal_symbol_collection ();
236   make_cleanup_discard_minimal_symbols ();
237
238   while (rtc_symp)
239     {
240       read_memory (rtc_symp,
241                    (char *) &inferior_rtc_symb,
242                    sizeof (inferior_rtc_symb));
243       read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_sp),
244                    (char *) &inferior_rtc_nlist,
245                    sizeof (inferior_rtc_nlist));
246       if (inferior_rtc_nlist.n_type == N_COMM)
247         {
248           /* FIXME: The length of the symbol name is not available, but in the
249              current implementation the common symbol is allocated immediately
250              behind the name of the symbol.  */
251           len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
252
253           name = xmalloc (len);
254           read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist.n_un.n_name),
255                        name, len);
256
257           /* Allocate the runtime common objfile if necessary.  */
258           if (rt_common_objfile == NULL)
259             allocate_rt_common_objfile ();
260
261           prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
262                                       mst_bss, rt_common_objfile);
263           xfree (name);
264         }
265       rtc_symp = SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_next);
266     }
267
268   /* Install any minimal symbols that have been collected as the current
269      minimal symbols for the runtime common objfile.  */
270
271   install_minimal_symbols (rt_common_objfile);
272 }
273
274
275 /* Locate the base address of dynamic linker structs.
276
277    For both the SunOS and SVR4 shared library implementations, if the
278    inferior executable has been linked dynamically, there is a single
279    address somewhere in the inferior's data space which is the key to
280    locating all of the dynamic linker's runtime structures.  This
281    address is the value of the debug base symbol.  The job of this
282    function is to find and return that address, or to return 0 if there
283    is no such address (the executable is statically linked for example).
284
285    For SunOS, the job is almost trivial, since the dynamic linker and
286    all of it's structures are statically linked to the executable at
287    link time.  Thus the symbol for the address we are looking for has
288    already been added to the minimal symbol table for the executable's
289    objfile at the time the symbol file's symbols were read, and all we
290    have to do is look it up there.  Note that we explicitly do NOT want
291    to find the copies in the shared library.
292
293    The SVR4 version is a bit more complicated because the address
294    is contained somewhere in the dynamic info section.  We have to go
295    to a lot more work to discover the address of the debug base symbol.
296    Because of this complexity, we cache the value we find and return that
297    value on subsequent invocations.  Note there is no copy in the
298    executable symbol tables.  */
299
300 static CORE_ADDR
301 locate_base (void)
302 {
303   struct minimal_symbol *msymbol;
304   CORE_ADDR address = 0;
305   char **symbolp;
306
307   /* For SunOS, we want to limit the search for the debug base symbol to the
308      executable being debugged, since there is a duplicate named symbol in the
309      shared library.  We don't want the shared library versions.  */
310
311   for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
312     {
313       msymbol = lookup_minimal_symbol (*symbolp, NULL, symfile_objfile);
314       if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
315         {
316           address = SYMBOL_VALUE_ADDRESS (msymbol);
317           return (address);
318         }
319     }
320   return (0);
321 }
322
323 /* Locate first member in dynamic linker's map.
324
325    Find the first element in the inferior's dynamic link map, and
326    return its address in the inferior.  This function doesn't copy the
327    link map entry itself into our address space; current_sos actually
328    does the reading.  */
329
330 static CORE_ADDR
331 first_link_map_member (void)
332 {
333   CORE_ADDR lm = 0;
334
335   read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
336   if (dynamic_copy.ld_version >= 2)
337     {
338       /* It is a version that we can deal with, so read in the secondary
339          structure and find the address of the link map list from it.  */
340       read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy.ld_un.ld_2),
341                    (char *) &ld_2_copy, sizeof (struct link_dynamic_2));
342       lm = SOLIB_EXTRACT_ADDRESS (ld_2_copy.ld_loaded);
343     }
344   return (lm);
345 }
346
347 static int
348 open_symbol_file_object (void *from_ttyp)
349 {
350   return 1;
351 }
352
353
354 /* Implement the "current_sos" target_so_ops method.  */
355
356 static struct so_list *
357 sunos_current_sos (void)
358 {
359   CORE_ADDR lm;
360   struct so_list *head = 0;
361   struct so_list **link_ptr = &head;
362   int errcode;
363   char *buffer;
364
365   /* Make sure we've looked up the inferior's dynamic linker's base
366      structure.  */
367   if (! debug_base)
368     {
369       debug_base = locate_base ();
370
371       /* If we can't find the dynamic linker's base structure, this
372          must not be a dynamically linked executable.  Hmm.  */
373       if (! debug_base)
374         return 0;
375     }
376
377   /* Walk the inferior's link map list, and build our list of
378      `struct so_list' nodes.  */
379   lm = first_link_map_member ();  
380   while (lm)
381     {
382       struct so_list *new
383         = (struct so_list *) xmalloc (sizeof (struct so_list));
384       struct cleanup *old_chain = make_cleanup (xfree, new);
385
386       memset (new, 0, sizeof (*new));
387
388       new->lm_info = xmalloc (sizeof (struct lm_info));
389       make_cleanup (xfree, new->lm_info);
390
391       new->lm_info->lm = xmalloc (sizeof (struct link_map));
392       make_cleanup (xfree, new->lm_info->lm);
393       memset (new->lm_info->lm, 0, sizeof (struct link_map));
394
395       read_memory (lm, new->lm_info->lm, sizeof (struct link_map));
396
397       lm = lm_next (new);
398
399       /* Extract this shared object's name.  */
400       target_read_string (lm_name (new), &buffer,
401                           SO_NAME_MAX_PATH_SIZE - 1, &errcode);
402       if (errcode != 0)
403         warning (_("Can't read pathname for load map: %s."),
404                  safe_strerror (errcode));
405       else
406         {
407           strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
408           new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
409           xfree (buffer);
410           strcpy (new->so_original_name, new->so_name);
411         }
412
413       /* If this entry has no name, or its name matches the name
414          for the main executable, don't include it in the list.  */
415       if (! new->so_name[0]
416           || match_main (new->so_name))
417         free_so (new);
418       else
419         {
420           new->next = 0;
421           *link_ptr = new;
422           link_ptr = &new->next;
423         }
424
425       discard_cleanups (old_chain);
426     }
427
428   return head;
429 }
430
431
432 /* On some systems, the only way to recognize the link map entry for
433    the main executable file is by looking at its name.  Return
434    non-zero iff SONAME matches one of the known main executable names.  */
435
436 static int
437 match_main (char *soname)
438 {
439   char **mainp;
440
441   for (mainp = main_name_list; *mainp != NULL; mainp++)
442     {
443       if (strcmp (soname, *mainp) == 0)
444         return (1);
445     }
446
447   return (0);
448 }
449
450
451 static int
452 sunos_in_dynsym_resolve_code (CORE_ADDR pc)
453 {
454   return 0;
455 }
456
457 /* Remove the "mapping changed" breakpoint.
458
459    Removes the breakpoint that gets hit when the dynamic linker
460    completes a mapping change.  */
461
462 static int
463 disable_break (void)
464 {
465   CORE_ADDR breakpoint_addr;    /* Address where end bkpt is set.  */
466
467   int in_debugger = 0;
468
469   /* Read the debugger structure from the inferior to retrieve the
470      address of the breakpoint and the original contents of the
471      breakpoint address.  Remove the breakpoint by writing the original
472      contents back.  */
473
474   read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
475
476   /* Set `in_debugger' to zero now.  */
477
478   write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
479
480   breakpoint_addr = SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_bp_addr);
481   write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
482                 sizeof (debug_copy.ldd_bp_inst));
483
484   /* For the SVR4 version, we always know the breakpoint address.  For the
485      SunOS version we don't know it until the above code is executed.
486      Grumble if we are stopped anywhere besides the breakpoint address.  */
487
488   if (stop_pc != breakpoint_addr)
489     {
490       warning (_("stopped at unknown breakpoint "
491                  "while handling shared libraries"));
492     }
493
494   return 1;
495 }
496
497 /* Arrange for dynamic linker to hit breakpoint.
498
499    Both the SunOS and the SVR4 dynamic linkers have, as part of their
500    debugger interface, support for arranging for the inferior to hit
501    a breakpoint after mapping in the shared libraries.  This function
502    enables that breakpoint.
503
504    For SunOS, there is a special flag location (in_debugger) which we
505    set to 1.  When the dynamic linker sees this flag set, it will set
506    a breakpoint at a location known only to itself, after saving the
507    original contents of that place and the breakpoint address itself,
508    in it's own internal structures.  When we resume the inferior, it
509    will eventually take a SIGTRAP when it runs into the breakpoint.
510    We handle this (in a different place) by restoring the contents of
511    the breakpointed location (which is only known after it stops),
512    chasing around to locate the shared libraries that have been
513    loaded, then resuming.
514
515    For SVR4, the debugger interface structure contains a member (r_brk)
516    which is statically initialized at the time the shared library is
517    built, to the offset of a function (_r_debug_state) which is guaran-
518    teed to be called once before mapping in a library, and again when
519    the mapping is complete.  At the time we are examining this member,
520    it contains only the unrelocated offset of the function, so we have
521    to do our own relocation.  Later, when the dynamic linker actually
522    runs, it relocates r_brk to be the actual address of _r_debug_state().
523
524    The debugger interface structure also contains an enumeration which
525    is set to either RT_ADD or RT_DELETE prior to changing the mapping,
526    depending upon whether or not the library is being mapped or
527    unmapped, and then set to RT_CONSISTENT after the library is
528    mapped/unmapped.  */
529
530 static int
531 enable_break (void)
532 {
533   int success = 0;
534   int j;
535   int in_debugger;
536
537   /* Get link_dynamic structure.  */
538
539   j = target_read_memory (debug_base, (char *) &dynamic_copy,
540                           sizeof (dynamic_copy));
541   if (j)
542     {
543       /* unreadable */
544       return (0);
545     }
546
547   /* Calc address of debugger interface structure.  */
548
549   debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
550
551   /* Calc address of `in_debugger' member of debugger interface structure.  */
552
553   flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
554                                         (char *) &debug_copy);
555
556   /* Write a value of 1 to this member.  */
557
558   in_debugger = 1;
559   write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
560   success = 1;
561
562   return (success);
563 }
564
565 /* Implement the "special_symbol_handling" target_so_ops method.
566
567    For SunOS4, this consists of grunging around in the dynamic
568    linkers structures to find symbol definitions for "common" symbols
569    and adding them to the minimal symbol table for the runtime common
570    objfile.  */
571
572 static void
573 sunos_special_symbol_handling (void)
574 {
575   int j;
576
577   if (debug_addr == 0)
578     {
579       /* Get link_dynamic structure.  */
580
581       j = target_read_memory (debug_base, (char *) &dynamic_copy,
582                               sizeof (dynamic_copy));
583       if (j)
584         {
585           /* unreadable */
586           return;
587         }
588
589       /* Calc address of debugger interface structure.  */
590       /* FIXME, this needs work for cross-debugging of core files
591          (byteorder, size, alignment, etc).  */
592
593       debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
594     }
595
596   /* Read the debugger structure from the inferior, just to make sure
597      we have a current copy.  */
598
599   j = target_read_memory (debug_addr, (char *) &debug_copy,
600                           sizeof (debug_copy));
601   if (j)
602     return;                     /* unreadable */
603
604   /* Get common symbol definitions for the loaded object.  */
605
606   if (debug_copy.ldd_cp)
607     {
608       solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_cp));
609     }
610 }
611
612 /* Implement the "create_inferior_hook" target_solib_ops method.
613
614    For SunOS executables, this first instruction is typically the
615    one at "_start", or a similar text label, regardless of whether
616    the executable is statically or dynamically linked.  The runtime
617    startup code takes care of dynamically linking in any shared
618    libraries, once gdb allows the inferior to continue.
619
620    We can arrange to cooperate with the dynamic linker to discover the
621    names of shared libraries that are dynamically linked, and the base
622    addresses to which they are linked.
623
624    This function is responsible for discovering those names and
625    addresses, and saving sufficient information about them to allow
626    their symbols to be read at a later time.
627
628    FIXME
629
630    Between enable_break() and disable_break(), this code does not
631    properly handle hitting breakpoints which the user might have
632    set in the startup code or in the dynamic linker itself.  Proper
633    handling will probably have to wait until the implementation is
634    changed to use the "breakpoint handler function" method.
635
636    Also, what if child has exit()ed?  Must exit loop somehow.  */
637
638 static void
639 sunos_solib_create_inferior_hook (int from_tty)
640 {
641   struct thread_info *tp;
642   struct inferior *inf;
643
644   if ((debug_base = locate_base ()) == 0)
645     {
646       /* Can't find the symbol or the executable is statically linked.  */
647       return;
648     }
649
650   if (!enable_break ())
651     {
652       warning (_("shared library handler failed to enable breakpoint"));
653       return;
654     }
655
656   /* SCO and SunOS need the loop below, other systems should be using the
657      special shared library breakpoints and the shared library breakpoint
658      service routine.
659
660      Now run the target.  It will eventually hit the breakpoint, at
661      which point all of the libraries will have been mapped in and we
662      can go groveling around in the dynamic linker structures to find
663      out what we need to know about them.  */
664
665   inf = current_inferior ();
666   tp = inferior_thread ();
667
668   clear_proceed_status ();
669
670   inf->control.stop_soon = STOP_QUIETLY;
671   tp->suspend.stop_signal = GDB_SIGNAL_0;
672   do
673     {
674       target_resume (pid_to_ptid (-1), 0, tp->suspend.stop_signal);
675       wait_for_inferior ();
676     }
677   while (tp->suspend.stop_signal != GDB_SIGNAL_TRAP);
678   inf->control.stop_soon = NO_STOP_QUIETLY;
679
680   /* We are now either at the "mapping complete" breakpoint (or somewhere
681      else, a condition we aren't prepared to deal with anyway), so adjust
682      the PC as necessary after a breakpoint, disable the breakpoint, and
683      add any shared libraries that were mapped in.
684
685      Note that adjust_pc_after_break did not perform any PC adjustment,
686      as the breakpoint the inferior just hit was not inserted by GDB,
687      but by the dynamic loader itself, and is therefore not found on
688      the GDB software break point list.  Thus we have to adjust the
689      PC here.  */
690
691   if (gdbarch_decr_pc_after_break (target_gdbarch ()))
692     {
693       stop_pc -= gdbarch_decr_pc_after_break (target_gdbarch ());
694       regcache_write_pc (get_current_regcache (), stop_pc);
695     }
696
697   if (!disable_break ())
698     {
699       warning (_("shared library handler failed to disable breakpoint"));
700     }
701
702   solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add);
703 }
704
705 static void
706 sunos_clear_solib (void)
707 {
708   debug_base = 0;
709 }
710
711 static void
712 sunos_free_so (struct so_list *so)
713 {
714   xfree (so->lm_info->lm);
715   xfree (so->lm_info);
716 }
717
718 static void
719 sunos_relocate_section_addresses (struct so_list *so,
720                                   struct target_section *sec)
721 {
722   sec->addr += lm_addr (so);
723   sec->endaddr += lm_addr (so);
724 }
725
726 static struct target_so_ops sunos_so_ops;
727
728 void
729 _initialize_sunos_solib (void)
730 {
731   sunos_so_ops.relocate_section_addresses = sunos_relocate_section_addresses;
732   sunos_so_ops.free_so = sunos_free_so;
733   sunos_so_ops.clear_solib = sunos_clear_solib;
734   sunos_so_ops.solib_create_inferior_hook = sunos_solib_create_inferior_hook;
735   sunos_so_ops.special_symbol_handling = sunos_special_symbol_handling;
736   sunos_so_ops.current_sos = sunos_current_sos;
737   sunos_so_ops.open_symbol_file_object = open_symbol_file_object;
738   sunos_so_ops.in_dynsym_resolve_code = sunos_in_dynsym_resolve_code;
739   sunos_so_ops.bfd_open = solib_bfd_open;
740
741   /* FIXME: Don't do this here.  *_gdbarch_init() should set so_ops.  */
742   current_target_so_ops = &sunos_so_ops;
743 }