1 /* BFD backend for SunOS binaries.
2 Copyright (C) 1990, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #define TARGETNAME "a.out-sunos-big"
22 #define MY(OP) CAT(sunos_big_,OP)
28 /* Static routines defined in this file. */
30 static boolean sunos_read_dynamic_info PARAMS ((bfd *));
31 static long sunos_get_dynamic_symtab_upper_bound PARAMS ((bfd *));
32 static boolean sunos_slurp_dynamic_symtab PARAMS ((bfd *));
33 static long sunos_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **));
34 static long sunos_get_dynamic_reloc_upper_bound PARAMS ((bfd *));
35 static long sunos_canonicalize_dynamic_reloc
36 PARAMS ((bfd *, arelent **, asymbol **));
37 static struct bfd_hash_entry *sunos_link_hash_newfunc
38 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
39 static struct bfd_link_hash_table *sunos_link_hash_table_create
41 static boolean sunos_create_dynamic_sections
42 PARAMS ((bfd *, struct bfd_link_info *, boolean));
43 static boolean sunos_add_dynamic_symbols
44 PARAMS ((bfd *, struct bfd_link_info *, struct external_nlist **,
45 bfd_size_type *, char **));
46 static boolean sunos_add_one_symbol
47 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
48 bfd_vma, const char *, boolean, boolean,
49 struct bfd_link_hash_entry **));
50 static boolean sunos_scan_relocs
51 PARAMS ((struct bfd_link_info *, bfd *, asection *, bfd_size_type));
52 static boolean sunos_scan_std_relocs
53 PARAMS ((struct bfd_link_info *, bfd *, asection *,
54 const struct reloc_std_external *, bfd_size_type));
55 static boolean sunos_scan_ext_relocs
56 PARAMS ((struct bfd_link_info *, bfd *, asection *,
57 const struct reloc_ext_external *, bfd_size_type));
58 static boolean sunos_link_dynamic_object
59 PARAMS ((struct bfd_link_info *, bfd *));
60 static boolean sunos_write_dynamic_symbol
61 PARAMS ((bfd *, struct bfd_link_info *, struct aout_link_hash_entry *));
62 static boolean sunos_check_dynamic_reloc
63 PARAMS ((struct bfd_link_info *, bfd *, asection *,
64 struct aout_link_hash_entry *, PTR, bfd_byte *, boolean *,
66 static boolean sunos_finish_dynamic_link
67 PARAMS ((bfd *, struct bfd_link_info *));
69 #define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound
70 #define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab
71 #define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound
72 #define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc
73 #define MY_bfd_link_hash_table_create sunos_link_hash_table_create
74 #define MY_add_dynamic_symbols sunos_add_dynamic_symbols
75 #define MY_add_one_symbol sunos_add_one_symbol
76 #define MY_link_dynamic_object sunos_link_dynamic_object
77 #define MY_write_dynamic_symbol sunos_write_dynamic_symbol
78 #define MY_check_dynamic_reloc sunos_check_dynamic_reloc
79 #define MY_finish_dynamic_link sunos_finish_dynamic_link
81 /* Include the usual a.out support. */
84 /* SunOS shared library support. We store a pointer to this structure
85 in obj_aout_dynamic_info (abfd). */
87 struct sunos_dynamic_info
89 /* Whether we found any dynamic information. */
91 /* Dynamic information. */
92 struct internal_sun4_dynamic_link dyninfo;
93 /* Number of dynamic symbols. */
94 unsigned long dynsym_count;
95 /* Read in nlists for dynamic symbols. */
96 struct external_nlist *dynsym;
97 /* asymbol structures for dynamic symbols. */
98 aout_symbol_type *canonical_dynsym;
99 /* Read in dynamic string table. */
101 /* Number of dynamic relocs. */
102 unsigned long dynrel_count;
103 /* Read in dynamic relocs. This may be reloc_std_external or
104 reloc_ext_external. */
106 /* arelent structures for dynamic relocs. */
107 arelent *canonical_dynrel;
110 /* The hash table of dynamic symbols is composed of two word entries.
111 See include/aout/sun4.h for details. */
113 #define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
115 /* Read in the basic dynamic information. This locates the __DYNAMIC
116 structure and uses it to find the dynamic_link structure. It
117 creates and saves a sunos_dynamic_info structure. If it can't find
118 __DYNAMIC, it sets the valid field of the sunos_dynamic_info
119 structure to false to avoid doing this work again. */
122 sunos_read_dynamic_info (abfd)
125 struct sunos_dynamic_info *info;
128 struct external_sun4_dynamic dyninfo;
129 unsigned long dynver;
130 struct external_sun4_dynamic_link linkinfo;
132 if (obj_aout_dynamic_info (abfd) != (PTR) NULL)
135 if ((abfd->flags & DYNAMIC) == 0)
137 bfd_set_error (bfd_error_invalid_operation);
141 info = ((struct sunos_dynamic_info *)
142 bfd_zalloc (abfd, sizeof (struct sunos_dynamic_info)));
145 bfd_set_error (bfd_error_no_memory);
151 info->canonical_dynsym = NULL;
153 info->canonical_dynrel = NULL;
154 obj_aout_dynamic_info (abfd) = (PTR) info;
156 /* This code used to look for the __DYNAMIC symbol to locate the dynamic
158 However this inhibits recovering the dynamic symbols from a
159 stripped object file, so blindly assume that the dynamic linking
160 information is located at the start of the data section.
161 We could verify this assumption later by looking through the dynamic
162 symbols for the __DYNAMIC symbol. */
163 if ((abfd->flags & DYNAMIC) == 0)
165 if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (PTR) &dyninfo,
166 (file_ptr) 0, sizeof dyninfo))
169 dynver = GET_WORD (abfd, dyninfo.ld_version);
170 if (dynver != 2 && dynver != 3)
173 dynoff = GET_WORD (abfd, dyninfo.ld);
175 /* dynoff is a virtual address. It is probably always in the .data
176 section, but this code should work even if it moves. */
177 if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
178 dynsec = obj_textsec (abfd);
180 dynsec = obj_datasec (abfd);
181 dynoff -= bfd_get_section_vma (abfd, dynsec);
182 if (dynoff > bfd_section_size (abfd, dynsec))
185 /* This executable appears to be dynamically linked in a way that we
187 if (! bfd_get_section_contents (abfd, dynsec, (PTR) &linkinfo, dynoff,
188 (bfd_size_type) sizeof linkinfo))
191 /* Swap in the dynamic link information. */
192 info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
193 info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
194 info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
195 info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
196 info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
197 info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
198 info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
199 info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
200 info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
201 info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
202 info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
203 info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
204 info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
205 info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
207 /* Reportedly the addresses need to be offset by the size of the
208 exec header in an NMAGIC file. */
209 if (adata (abfd).magic == n_magic)
211 unsigned long exec_bytes_size = adata (abfd).exec_bytes_size;
213 info->dyninfo.ld_need += exec_bytes_size;
214 info->dyninfo.ld_rules += exec_bytes_size;
215 info->dyninfo.ld_rel += exec_bytes_size;
216 info->dyninfo.ld_hash += exec_bytes_size;
217 info->dyninfo.ld_stab += exec_bytes_size;
218 info->dyninfo.ld_symbols += exec_bytes_size;
221 /* The only way to get the size of the symbol information appears to
222 be to determine the distance between it and the string table. */
223 info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
224 / EXTERNAL_NLIST_SIZE);
225 BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
226 == (unsigned long) (info->dyninfo.ld_symbols
227 - info->dyninfo.ld_stab));
229 /* Similarly, the relocs end at the hash table. */
230 info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
231 / obj_reloc_entry_size (abfd));
232 BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
233 == (unsigned long) (info->dyninfo.ld_hash
234 - info->dyninfo.ld_rel));
241 /* Return the amount of memory required for the dynamic symbols. */
244 sunos_get_dynamic_symtab_upper_bound (abfd)
247 struct sunos_dynamic_info *info;
249 if (! sunos_read_dynamic_info (abfd))
252 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
255 bfd_set_error (bfd_error_no_symbols);
259 return (info->dynsym_count + 1) * sizeof (asymbol *);
262 /* Read the external dynamic symbols. */
265 sunos_slurp_dynamic_symtab (abfd)
268 struct sunos_dynamic_info *info;
270 /* Get the general dynamic information. */
271 if (obj_aout_dynamic_info (abfd) == NULL)
273 if (! sunos_read_dynamic_info (abfd))
277 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
280 bfd_set_error (bfd_error_no_symbols);
284 /* Get the dynamic nlist structures. */
285 if (info->dynsym == (struct external_nlist *) NULL)
287 info->dynsym = ((struct external_nlist *)
290 * EXTERNAL_NLIST_SIZE)));
291 if (info->dynsym == NULL && info->dynsym_count != 0)
293 bfd_set_error (bfd_error_no_memory);
296 if (bfd_seek (abfd, info->dyninfo.ld_stab, SEEK_SET) != 0
297 || (bfd_read ((PTR) info->dynsym, info->dynsym_count,
298 EXTERNAL_NLIST_SIZE, abfd)
299 != info->dynsym_count * EXTERNAL_NLIST_SIZE))
301 if (info->dynsym != NULL)
303 bfd_release (abfd, info->dynsym);
310 /* Get the dynamic strings. */
311 if (info->dynstr == (char *) NULL)
313 info->dynstr = (char *) bfd_alloc (abfd, info->dyninfo.ld_symb_size);
314 if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
316 bfd_set_error (bfd_error_no_memory);
319 if (bfd_seek (abfd, info->dyninfo.ld_symbols, SEEK_SET) != 0
320 || (bfd_read ((PTR) info->dynstr, 1, info->dyninfo.ld_symb_size,
322 != info->dyninfo.ld_symb_size))
324 if (info->dynstr != NULL)
326 bfd_release (abfd, info->dynstr);
336 /* Read in the dynamic symbols. */
339 sunos_canonicalize_dynamic_symtab (abfd, storage)
343 struct sunos_dynamic_info *info;
346 if (! sunos_slurp_dynamic_symtab (abfd))
349 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
351 #ifdef CHECK_DYNAMIC_HASH
352 /* Check my understanding of the dynamic hash table by making sure
353 that each symbol can be located in the hash table. */
355 bfd_size_type table_size;
359 if (info->dyninfo.ld_buckets > info->dynsym_count)
361 table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
362 table = (bfd_byte *) malloc (table_size);
363 if (table == NULL && table_size != 0)
365 if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
366 || bfd_read ((PTR) table, 1, table_size, abfd) != table_size)
368 for (i = 0; i < info->dynsym_count; i++)
373 name = ((unsigned char *) info->dynstr
374 + GET_WORD (abfd, info->dynsym[i].e_strx));
376 while (*name != '\0')
377 hash = (hash << 1) + *name++;
379 hash %= info->dyninfo.ld_buckets;
380 while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
382 hash = GET_WORD (abfd,
383 table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
384 if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
390 #endif /* CHECK_DYNAMIC_HASH */
392 /* Get the asymbol structures corresponding to the dynamic nlist
394 if (info->canonical_dynsym == (aout_symbol_type *) NULL)
396 info->canonical_dynsym = ((aout_symbol_type *)
399 * sizeof (aout_symbol_type))));
400 if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
402 bfd_set_error (bfd_error_no_memory);
406 if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
407 info->dynsym, info->dynsym_count,
409 info->dyninfo.ld_symb_size,
412 if (info->canonical_dynsym != NULL)
414 bfd_release (abfd, info->canonical_dynsym);
415 info->canonical_dynsym = NULL;
421 /* Return pointers to the dynamic asymbol structures. */
422 for (i = 0; i < info->dynsym_count; i++)
423 *storage++ = (asymbol *) (info->canonical_dynsym + i);
426 return info->dynsym_count;
429 /* Return the amount of memory required for the dynamic relocs. */
432 sunos_get_dynamic_reloc_upper_bound (abfd)
435 struct sunos_dynamic_info *info;
437 if (! sunos_read_dynamic_info (abfd))
440 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
443 bfd_set_error (bfd_error_no_symbols);
447 return (info->dynrel_count + 1) * sizeof (arelent *);
450 /* Read in the dynamic relocs. */
453 sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
458 struct sunos_dynamic_info *info;
461 /* Get the general dynamic information. */
462 if (obj_aout_dynamic_info (abfd) == (PTR) NULL)
464 if (! sunos_read_dynamic_info (abfd))
468 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
471 bfd_set_error (bfd_error_no_symbols);
475 /* Get the dynamic reloc information. */
476 if (info->dynrel == NULL)
478 info->dynrel = (PTR) bfd_alloc (abfd,
480 * obj_reloc_entry_size (abfd)));
481 if (info->dynrel == NULL && info->dynrel_count != 0)
483 bfd_set_error (bfd_error_no_memory);
486 if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
487 || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
488 obj_reloc_entry_size (abfd), abfd)
489 != info->dynrel_count * obj_reloc_entry_size (abfd)))
491 if (info->dynrel != NULL)
493 bfd_release (abfd, info->dynrel);
500 /* Get the arelent structures corresponding to the dynamic reloc
502 if (info->canonical_dynrel == (arelent *) NULL)
506 info->canonical_dynrel = ((arelent *)
509 * sizeof (arelent))));
510 if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
512 bfd_set_error (bfd_error_no_memory);
516 to = info->canonical_dynrel;
518 if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
520 register struct reloc_ext_external *p;
521 struct reloc_ext_external *pend;
523 p = (struct reloc_ext_external *) info->dynrel;
524 pend = p + info->dynrel_count;
525 for (; p < pend; p++, to++)
526 NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms,
531 register struct reloc_std_external *p;
532 struct reloc_std_external *pend;
534 p = (struct reloc_std_external *) info->dynrel;
535 pend = p + info->dynrel_count;
536 for (; p < pend; p++, to++)
537 NAME(aout,swap_std_reloc_in) (abfd, p, to, syms,
542 /* Return pointers to the dynamic arelent structures. */
543 for (i = 0; i < info->dynrel_count; i++)
544 *storage++ = info->canonical_dynrel + i;
547 return info->dynrel_count;
550 /* Code to handle linking of SunOS shared libraries. */
552 /* A SPARC procedure linkage table entry is 12 bytes. The first entry
553 in the table is a jump which is filled in by the runtime linker.
554 The remaining entries are branches back to the first entry,
555 followed by an index into the relocation table encoded to look like
558 #define SPARC_PLT_ENTRY_SIZE (12)
560 static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
562 /* sethi %hi(0),%g1; address filled in by runtime linker. */
564 /* jmp %g1; offset filled in by runtime linker. */
570 /* save %sp, -96, %sp */
571 #define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0
572 /* call; address filled in later. */
573 #define SPARC_PLT_ENTRY_WORD1 0x40000000
574 /* sethi; reloc index filled in later. */
575 #define SPARC_PLT_ENTRY_WORD2 0x01000000
577 /* This sequence is used when for the jump table entry to a defined
578 symbol in a complete executable. It is used when linking PIC
579 compiled code which is not being put into a shared library. */
580 /* sethi <address to be filled in later>, %g1 */
581 #define SPARC_PLT_PIC_WORD0 0x03000000
582 /* jmp %g1 + <address to be filled in later> */
583 #define SPARC_PLT_PIC_WORD1 0x81c06000
585 #define SPARC_PLT_PIC_WORD2 0x01000000
587 /* An m68k procedure linkage table entry is 8 bytes. The first entry
588 in the table is a jump which is filled in the by the runtime
589 linker. The remaining entries are branches back to the first
590 entry, followed by a two byte index into the relocation table. */
592 #define M68K_PLT_ENTRY_SIZE (8)
594 static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
598 /* Filled in by runtime linker with a magic address. */
605 #define M68K_PLT_ENTRY_WORD0 (0x61ff)
606 /* Remaining words filled in later. */
608 /* An entry in the SunOS linker hash table. */
610 struct sunos_link_hash_entry
612 struct aout_link_hash_entry root;
614 /* If this is a dynamic symbol, this is its index into the dynamic
615 symbol table. This is initialized to -1. As the linker looks at
616 the input files, it changes this to -2 if it will be added to the
617 dynamic symbol table. After all the input files have been seen,
618 the linker will know whether to build a dynamic symbol table; if
619 it does build one, this becomes the index into the table. */
622 /* If this is a dynamic symbol, this is the index of the name in the
623 dynamic symbol string table. */
626 /* The offset into the global offset table used for this symbol. If
627 the symbol does not require a GOT entry, this is 0. */
630 /* The offset into the procedure linkage table used for this symbol.
631 If the symbol does not require a PLT entry, this is 0. */
634 /* Some linker flags. */
636 /* Symbol is referenced by a regular object. */
637 #define SUNOS_REF_REGULAR 01
638 /* Symbol is defined by a regular object. */
639 #define SUNOS_DEF_REGULAR 02
640 /* Symbol is referenced by a dynamic object. */
641 #define SUNOS_REF_DYNAMIC 010
642 /* Symbol is defined by a dynamic object. */
643 #define SUNOS_DEF_DYNAMIC 020
646 /* The SunOS linker hash table. */
648 struct sunos_link_hash_table
650 struct aout_link_hash_table root;
652 /* The object which holds the dynamic sections. */
655 /* Whether we have created the dynamic sections. */
656 boolean dynamic_sections_created;
658 /* Whether we need the dynamic sections. */
659 boolean dynamic_sections_needed;
661 /* The number of dynamic symbols. */
664 /* The number of buckets in the hash table. */
668 /* Routine to create an entry in an SunOS link hash table. */
670 static struct bfd_hash_entry *
671 sunos_link_hash_newfunc (entry, table, string)
672 struct bfd_hash_entry *entry;
673 struct bfd_hash_table *table;
676 struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
678 /* Allocate the structure if it has not already been allocated by a
680 if (ret == (struct sunos_link_hash_entry *) NULL)
681 ret = ((struct sunos_link_hash_entry *)
682 bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry)));
683 if (ret == (struct sunos_link_hash_entry *) NULL)
685 bfd_set_error (bfd_error_no_memory);
686 return (struct bfd_hash_entry *) ret;
689 /* Call the allocation method of the superclass. */
690 ret = ((struct sunos_link_hash_entry *)
691 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
695 /* Set local fields. */
697 ret->dynstr_index = -1;
703 return (struct bfd_hash_entry *) ret;
706 /* Create a SunOS link hash table. */
708 static struct bfd_link_hash_table *
709 sunos_link_hash_table_create (abfd)
712 struct sunos_link_hash_table *ret;
714 ret = ((struct sunos_link_hash_table *)
715 bfd_alloc (abfd, sizeof (struct sunos_link_hash_table)));
716 if (ret == (struct sunos_link_hash_table *) NULL)
718 bfd_set_error (bfd_error_no_memory);
719 return (struct bfd_link_hash_table *) NULL;
721 if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
722 sunos_link_hash_newfunc))
725 return (struct bfd_link_hash_table *) NULL;
729 ret->dynamic_sections_created = false;
730 ret->dynamic_sections_needed = false;
731 ret->dynsymcount = 0;
732 ret->bucketcount = 0;
734 return &ret->root.root;
737 /* Look up an entry in an SunOS link hash table. */
739 #define sunos_link_hash_lookup(table, string, create, copy, follow) \
740 ((struct sunos_link_hash_entry *) \
741 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
744 /* Traverse a SunOS link hash table. */
746 #define sunos_link_hash_traverse(table, func, info) \
747 (aout_link_hash_traverse \
749 (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
752 /* Get the SunOS link hash table from the info structure. This is
755 #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
757 static boolean sunos_scan_dynamic_symbol
758 PARAMS ((struct sunos_link_hash_entry *, PTR));
760 /* Create the dynamic sections needed if we are linking against a
761 dynamic object, or if we are linking PIC compiled code. ABFD is a
762 bfd we can attach the dynamic sections to. The linker script will
763 look for these special sections names and put them in the right
764 place in the output file. See include/aout/sun4.h for more details
765 of the dynamic linking information. */
768 sunos_create_dynamic_sections (abfd, info, needed)
770 struct bfd_link_info *info;
775 if (! sunos_hash_table (info)->dynamic_sections_created)
779 sunos_hash_table (info)->dynobj = abfd;
781 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
783 /* The .dynamic section holds the basic dynamic information: the
784 sun4_dynamic structure, the dynamic debugger information, and
785 the sun4_dynamic_link structure. */
786 s = bfd_make_section (abfd, ".dynamic");
788 || ! bfd_set_section_flags (abfd, s, flags)
789 || ! bfd_set_section_alignment (abfd, s, 2))
792 /* The .got section holds the global offset table. The address
793 is put in the ld_got field. */
794 s = bfd_make_section (abfd, ".got");
796 || ! bfd_set_section_flags (abfd, s, flags)
797 || ! bfd_set_section_alignment (abfd, s, 2))
800 /* The .plt section holds the procedure linkage table. The
801 address is put in the ld_plt field. */
802 s = bfd_make_section (abfd, ".plt");
804 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
805 || ! bfd_set_section_alignment (abfd, s, 2))
808 /* The .dynrel section holds the dynamic relocs. The address is
809 put in the ld_rel field. */
810 s = bfd_make_section (abfd, ".dynrel");
812 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
813 || ! bfd_set_section_alignment (abfd, s, 2))
816 /* The .hash section holds the dynamic hash table. The address
817 is put in the ld_hash field. */
818 s = bfd_make_section (abfd, ".hash");
820 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
821 || ! bfd_set_section_alignment (abfd, s, 2))
824 /* The .dynsym section holds the dynamic symbols. The address
825 is put in the ld_stab field. */
826 s = bfd_make_section (abfd, ".dynsym");
828 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
829 || ! bfd_set_section_alignment (abfd, s, 2))
832 /* The .dynstr section holds the dynamic symbol string table.
833 The address is put in the ld_symbols field. */
834 s = bfd_make_section (abfd, ".dynstr");
836 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
837 || ! bfd_set_section_alignment (abfd, s, 2))
840 sunos_hash_table (info)->dynamic_sections_created = true;
843 if (needed && ! sunos_hash_table (info)->dynamic_sections_needed)
847 dynobj = sunos_hash_table (info)->dynobj;
849 s = bfd_get_section_by_name (dynobj, ".got");
850 s->_raw_size = BYTES_IN_WORD;
852 sunos_hash_table (info)->dynamic_sections_needed = true;
858 /* Add dynamic symbols during a link. This is called by the a.out
859 backend linker when it encounters an object with the DYNAMIC flag
863 sunos_add_dynamic_symbols (abfd, info, symsp, sym_countp, stringsp)
865 struct bfd_link_info *info;
866 struct external_nlist **symsp;
867 bfd_size_type *sym_countp;
872 struct sunos_dynamic_info *dinfo;
874 /* We do not want to include the sections in a dynamic object in the
875 output file. We hack by simply clobbering the list of sections
876 in the BFD. This could be handled more cleanly by, say, a new
877 section flag; the existing SEC_NEVER_LOAD flag is not the one we
878 want, because that one still implies that the section takes up
879 space in the output file. */
880 abfd->sections = NULL;
882 /* The native linker seems to just ignore dynamic objects when -r is
884 if (info->relocateable)
887 /* There's no hope of using a dynamic object which does not exactly
888 match the format of the output file. */
889 if (info->hash->creator != abfd->xvec)
891 bfd_set_error (bfd_error_invalid_operation);
895 /* Make sure we have all the required information. */
896 if (! sunos_create_dynamic_sections (abfd, info, true))
899 /* Make sure we have a .need and a .rules sections. These are only
900 needed if there really is a dynamic object in the link, so they
901 are not added by sunos_create_dynamic_sections. */
902 dynobj = sunos_hash_table (info)->dynobj;
903 if (bfd_get_section_by_name (dynobj, ".need") == NULL)
905 /* The .need section holds the list of names of shared objets
906 which must be included at runtime. The address of this
907 section is put in the ld_need field. */
908 s = bfd_make_section (dynobj, ".need");
910 || ! bfd_set_section_flags (dynobj, s,
916 || ! bfd_set_section_alignment (dynobj, s, 2))
920 if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
922 /* The .rules section holds the path to search for shared
923 objects. The address of this section is put in the ld_rules
925 s = bfd_make_section (dynobj, ".rules");
927 || ! bfd_set_section_flags (dynobj, s,
933 || ! bfd_set_section_alignment (dynobj, s, 2))
937 /* Pick up the dynamic symbols and return them to the caller. */
938 if (! sunos_slurp_dynamic_symtab (abfd))
941 dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
942 *symsp = dinfo->dynsym;
943 *sym_countp = dinfo->dynsym_count;
944 *stringsp = dinfo->dynstr;
949 /* Function to add a single symbol to the linker hash table. This is
950 a wrapper around _bfd_generic_link_add_one_symbol which handles the
951 tweaking needed for dynamic linking support. */
954 sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
955 copy, collect, hashp)
956 struct bfd_link_info *info;
965 struct bfd_link_hash_entry **hashp;
967 struct sunos_link_hash_entry *h;
970 if (! sunos_hash_table (info)->dynamic_sections_created)
972 /* We must create the dynamic sections while reading the input
973 files, even though at this point we don't know if any of the
974 sections will be needed. This will ensure that the dynamic
975 sections are mapped to the right output section. It does no
976 harm to create these sections if they are not needed. */
977 if (! sunos_create_dynamic_sections (abfd, info, info->shared))
981 h = sunos_link_hash_lookup (sunos_hash_table (info), name, true, copy,
987 *hashp = (struct bfd_link_hash_entry *) h;
989 /* Treat a common symbol in a dynamic object as defined in the .bss
990 section of the dynamic object. We don't want to allocate space
991 for it in our process image. */
992 if ((abfd->flags & DYNAMIC) != 0
993 && bfd_is_com_section (section))
994 section = obj_bsssec (abfd);
996 if (! bfd_is_und_section (section)
997 && h->root.root.type != bfd_link_hash_new
998 && h->root.root.type != bfd_link_hash_undefined
999 && h->root.root.type != bfd_link_hash_defweak)
1001 /* We are defining the symbol, and it is already defined. This
1002 is a potential multiple definition error. */
1003 if ((abfd->flags & DYNAMIC) != 0)
1005 /* The definition we are adding is from a dynamic object.
1006 We do not want this new definition to override the
1007 existing definition, so we pretend it is just a
1009 section = bfd_und_section_ptr;
1011 else if ((h->root.root.type == bfd_link_hash_defined
1012 && h->root.root.u.def.section->owner != NULL
1013 && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1014 || (h->root.root.type == bfd_link_hash_common
1015 && ((h->root.root.u.c.p->section->owner->flags & DYNAMIC)
1018 /* The existing definition is from a dynamic object. We
1019 want to override it with the definition we just found.
1020 Clobber the existing definition. */
1021 h->root.root.type = bfd_link_hash_new;
1025 /* Do the usual procedure for adding a symbol. */
1026 if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
1027 value, string, copy, collect,
1031 if (abfd->xvec == info->hash->creator)
1033 /* Set a flag in the hash table entry indicating the type of
1034 reference or definition we just found. Keep a count of the
1035 number of dynamic symbols we find. A dynamic symbol is one
1036 which is referenced or defined by both a regular object and a
1038 if ((abfd->flags & DYNAMIC) == 0)
1040 if (bfd_is_und_section (section))
1041 new_flag = SUNOS_REF_REGULAR;
1043 new_flag = SUNOS_DEF_REGULAR;
1047 if (bfd_is_und_section (section))
1048 new_flag = SUNOS_REF_DYNAMIC;
1050 new_flag = SUNOS_DEF_DYNAMIC;
1052 h->flags |= new_flag;
1054 if (h->dynindx == -1
1055 && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1057 ++sunos_hash_table (info)->dynsymcount;
1065 /* Record an assignment made to a symbol by a linker script. We need
1066 this in case some dynamic object refers to this symbol. */
1069 bfd_sunos_record_link_assignment (output_bfd, info, name)
1071 struct bfd_link_info *info;
1074 struct sunos_link_hash_entry *h;
1076 /* This is called after we have examined all the input objects. If
1077 the symbol does not exist, it merely means that no object refers
1078 to it, and we can just ignore it at this point. */
1079 h = sunos_link_hash_lookup (sunos_hash_table (info), name,
1080 false, false, false);
1084 h->flags |= SUNOS_DEF_REGULAR;
1086 if (h->dynindx == -1)
1088 ++sunos_hash_table (info)->dynsymcount;
1095 /* Set up the sizes and contents of the dynamic sections created in
1096 sunos_add_dynamic_symbols. This is called by the SunOS linker
1097 emulation before_allocation routine. We must set the sizes of the
1098 sections before the linker sets the addresses of the various
1099 sections. This unfortunately requires reading all the relocs so
1100 that we can work out which ones need to become dynamic relocs. If
1101 info->keep_memory is true, we keep the relocs in memory; otherwise,
1102 we discard them, and will read them again later. */
1105 bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
1108 struct bfd_link_info *info;
1110 asection **sneedptr;
1111 asection **srulesptr;
1115 struct sunos_link_hash_entry *h;
1126 /* Look through all the input BFD's and read their relocs. It would
1127 be better if we didn't have to do this, but there is no other way
1128 to determine the number of dynamic relocs we need, and, more
1129 importantly, there is no other way to know which symbols should
1130 get an entry in the procedure linkage table. */
1131 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
1133 if ((sub->flags & DYNAMIC) == 0)
1135 if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
1136 exec_hdr (sub)->a_trsize)
1137 || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
1138 exec_hdr (sub)->a_drsize))
1143 dynobj = sunos_hash_table (info)->dynobj;
1144 dynsymcount = sunos_hash_table (info)->dynsymcount;
1146 /* If there were no dynamic objects in the link, and we don't need
1147 to build a global offset table, there is nothing to do here. */
1148 if (! sunos_hash_table (info)->dynamic_sections_needed)
1151 /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it. */
1152 h = sunos_link_hash_lookup (sunos_hash_table (info),
1153 "__GLOBAL_OFFSET_TABLE_", false, false, false);
1154 if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
1156 h->flags |= SUNOS_DEF_REGULAR;
1157 if (h->dynindx == -1)
1159 ++sunos_hash_table (info)->dynsymcount;
1162 h->root.root.type = bfd_link_hash_defined;
1163 h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
1164 h->root.root.u.def.value = 0;
1167 /* The .dynamic section is always the same size. */
1168 s = bfd_get_section_by_name (dynobj, ".dynamic");
1169 BFD_ASSERT (s != NULL);
1170 s->_raw_size = (sizeof (struct external_sun4_dynamic)
1171 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
1172 + sizeof (struct external_sun4_dynamic_link));
1174 /* Set the size of the .dynsym and .hash sections. We counted the
1175 number of dynamic symbols as we read the input files. We will
1176 build the dynamic symbol table (.dynsym) and the hash table
1177 (.hash) when we build the final symbol table, because until then
1178 we do not know the correct value to give the symbols. We build
1179 the dynamic symbol string table (.dynstr) in a traversal of the
1180 symbol table using sunos_scan_dynamic_symbol. */
1181 s = bfd_get_section_by_name (dynobj, ".dynsym");
1182 BFD_ASSERT (s != NULL);
1183 s->_raw_size = dynsymcount * sizeof (struct external_nlist);
1184 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
1185 if (s->contents == NULL && s->_raw_size != 0)
1187 bfd_set_error (bfd_error_no_memory);
1191 /* The number of buckets is just the number of symbols divided by
1192 four. To compute the final size of the hash table, we must
1193 actually compute the hash table. Normally we need exactly as
1194 many entries in the hash table as there are dynamic symbols, but
1195 if some of the buckets are not used we will need additional
1196 entries. In the worst case, every symbol will hash to the same
1197 bucket, and we will need BUCKETCOUNT - 1 extra entries. */
1198 if (dynsymcount >= 4)
1199 bucketcount = dynsymcount / 4;
1200 else if (dynsymcount > 0)
1201 bucketcount = dynsymcount;
1204 s = bfd_get_section_by_name (dynobj, ".hash");
1205 BFD_ASSERT (s != NULL);
1206 hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
1207 s->contents = (bfd_byte *) bfd_alloc (dynobj, hashalloc);
1208 if (s->contents == NULL && dynsymcount > 0)
1210 bfd_set_error (bfd_error_no_memory);
1213 memset (s->contents, 0, hashalloc);
1214 for (i = 0; i < bucketcount; i++)
1215 PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
1216 s->_raw_size = bucketcount * HASH_ENTRY_SIZE;
1218 sunos_hash_table (info)->bucketcount = bucketcount;
1220 /* Scan all the symbols, place them in the dynamic symbol table, and
1221 build the dynamic hash table. We reuse dynsymcount as a counter
1222 for the number of symbols we have added so far. */
1223 sunos_hash_table (info)->dynsymcount = 0;
1224 sunos_link_hash_traverse (sunos_hash_table (info),
1225 sunos_scan_dynamic_symbol,
1227 BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
1229 /* The SunOS native linker seems to align the total size of the
1230 symbol strings to a multiple of 8. I don't know if this is
1231 important, but it can't hurt much. */
1232 s = bfd_get_section_by_name (dynobj, ".dynstr");
1233 BFD_ASSERT (s != NULL);
1234 if ((s->_raw_size & 7) != 0)
1239 add = 8 - (s->_raw_size & 7);
1240 contents = (bfd_byte *) realloc (s->contents,
1241 (size_t) (s->_raw_size + add));
1242 if (contents == NULL)
1244 bfd_set_error (bfd_error_no_memory);
1247 memset (contents + s->_raw_size, 0, (size_t) add);
1248 s->contents = contents;
1249 s->_raw_size += add;
1252 /* Now that we have worked out the sizes of the procedure linkage
1253 table and the dynamic relocs, allocate storage for them. */
1254 s = bfd_get_section_by_name (dynobj, ".plt");
1255 BFD_ASSERT (s != NULL);
1256 if (s->_raw_size != 0)
1258 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1259 if (s->contents == NULL)
1261 bfd_set_error (bfd_error_no_memory);
1265 /* Fill in the first entry in the table. */
1266 switch (bfd_get_arch (dynobj))
1268 case bfd_arch_sparc:
1269 memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
1273 memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
1281 s = bfd_get_section_by_name (dynobj, ".dynrel");
1282 if (s->_raw_size != 0)
1284 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1285 if (s->contents == NULL)
1287 bfd_set_error (bfd_error_no_memory);
1291 /* We use the reloc_count field to keep track of how many of the
1292 relocs we have output so far. */
1295 /* Make space for the global offset table. */
1296 s = bfd_get_section_by_name (dynobj, ".got");
1297 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1298 if (s->contents == NULL)
1300 bfd_set_error (bfd_error_no_memory);
1304 *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
1305 *sneedptr = bfd_get_section_by_name (dynobj, ".need");
1306 *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
1311 /* Scan the relocs for an input section. */
1314 sunos_scan_relocs (info, abfd, sec, rel_size)
1315 struct bfd_link_info *info;
1318 bfd_size_type rel_size;
1321 PTR free_relocs = NULL;
1326 if (! info->keep_memory)
1327 relocs = free_relocs = malloc ((size_t) rel_size);
1330 struct aout_section_data_struct *n;
1332 n = ((struct aout_section_data_struct *)
1333 bfd_alloc (abfd, sizeof (struct aout_section_data_struct)));
1338 set_aout_section_data (sec, n);
1339 relocs = malloc ((size_t) rel_size);
1340 aout_section_data (sec)->relocs = relocs;
1345 bfd_set_error (bfd_error_no_memory);
1349 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
1350 || bfd_read (relocs, 1, rel_size, abfd) != rel_size)
1353 if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
1355 if (! sunos_scan_std_relocs (info, abfd, sec,
1356 (struct reloc_std_external *) relocs,
1362 if (! sunos_scan_ext_relocs (info, abfd, sec,
1363 (struct reloc_ext_external *) relocs,
1368 if (free_relocs != NULL)
1374 if (free_relocs != NULL)
1379 /* Scan the relocs for an input section using standard relocs. We
1380 need to figure out what to do for each reloc against a dynamic
1381 symbol. If the symbol is in the .text section, an entry is made in
1382 the procedure linkage table. Note that this will do the wrong
1383 thing if the symbol is actually data; I don't think the Sun 3
1384 native linker handles this case correctly either. If the symbol is
1385 not in the .text section, we must preserve the reloc as a dynamic
1386 reloc. FIXME: We should also handle the PIC relocs here by
1387 building global offset table entries. */
1390 sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
1391 struct bfd_link_info *info;
1394 const struct reloc_std_external *relocs;
1395 bfd_size_type rel_size;
1398 asection *splt = NULL;
1399 asection *srel = NULL;
1400 struct sunos_link_hash_entry **sym_hashes;
1401 const struct reloc_std_external *rel, *relend;
1403 /* We only know how to handle m68k plt entries. */
1404 if (bfd_get_arch (abfd) != bfd_arch_m68k)
1406 bfd_set_error (bfd_error_invalid_target);
1412 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1414 relend = relocs + rel_size / RELOC_STD_SIZE;
1415 for (rel = relocs; rel < relend; rel++)
1418 struct sunos_link_hash_entry *h;
1420 /* We only want relocs against external symbols. */
1421 if (abfd->xvec->header_byteorder_big_p)
1423 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
1428 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
1432 /* Get the symbol index. */
1433 if (abfd->xvec->header_byteorder_big_p)
1434 r_index = ((rel->r_index[0] << 16)
1435 | (rel->r_index[1] << 8)
1438 r_index = ((rel->r_index[2] << 16)
1439 | (rel->r_index[1] << 8)
1442 /* Get the hash table entry. */
1443 h = sym_hashes[r_index];
1446 /* This should not normally happen, but it will in any case
1447 be caught in the relocation phase. */
1451 /* At this point common symbols have already been allocated, so
1452 we don't have to worry about them. We need to consider that
1453 we may have already seen this symbol and marked it undefined;
1454 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1456 if (h->root.root.type != bfd_link_hash_defined
1457 && h->root.root.type != bfd_link_hash_defweak
1458 && h->root.root.type != bfd_link_hash_undefined)
1461 if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1462 || (h->flags & SUNOS_DEF_REGULAR) != 0)
1467 if (! sunos_create_dynamic_sections (abfd, info, true))
1469 dynobj = sunos_hash_table (info)->dynobj;
1470 splt = bfd_get_section_by_name (dynobj, ".plt");
1471 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1472 BFD_ASSERT (splt != NULL && srel != NULL);
1475 BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
1476 BFD_ASSERT (h->plt_offset != 0
1477 || ((h->root.root.type == bfd_link_hash_defined
1478 || h->root.root.type == bfd_link_hash_defweak)
1479 ? (h->root.root.u.def.section->owner->flags
1481 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1483 /* This reloc is against a symbol defined only by a dynamic
1486 if (h->root.root.type == bfd_link_hash_undefined)
1488 /* Presumably this symbol was marked as being undefined by
1489 an earlier reloc. */
1490 srel->_raw_size += RELOC_STD_SIZE;
1492 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1496 /* This reloc is not in the .text section. It must be
1497 copied into the dynamic relocs. We mark the symbol as
1499 srel->_raw_size += RELOC_STD_SIZE;
1500 sub = h->root.root.u.def.section->owner;
1501 h->root.root.type = bfd_link_hash_undefined;
1502 h->root.root.u.undef.abfd = sub;
1506 /* This symbol is in the .text section. We must give it an
1507 entry in the procedure linkage table, if we have not
1508 already done so. We change the definition of the symbol
1509 to the .plt section; this will cause relocs against it to
1510 be handled correctly. */
1511 if (h->plt_offset == 0)
1513 if (splt->_raw_size == 0)
1514 splt->_raw_size = M68K_PLT_ENTRY_SIZE;
1515 h->plt_offset = splt->_raw_size;
1517 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1519 h->root.root.u.def.section = splt;
1520 h->root.root.u.def.value = splt->_raw_size;
1523 splt->_raw_size += M68K_PLT_ENTRY_SIZE;
1525 /* We may also need a dynamic reloc entry. */
1526 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1527 srel->_raw_size += RELOC_STD_SIZE;
1535 /* Scan the relocs for an input section using extended relocs. We
1536 need to figure out what to do for each reloc against a dynamic
1537 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1538 section, an entry is made in the procedure linkage table.
1539 Otherwise, we must preserve the reloc as a dynamic reloc. */
1542 sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
1543 struct bfd_link_info *info;
1546 const struct reloc_ext_external *relocs;
1547 bfd_size_type rel_size;
1550 struct sunos_link_hash_entry **sym_hashes;
1551 const struct reloc_ext_external *rel, *relend;
1552 asection *splt = NULL;
1553 asection *sgot = NULL;
1554 asection *srel = NULL;
1556 /* We only know how to handle SPARC plt entries. */
1557 if (bfd_get_arch (abfd) != bfd_arch_sparc)
1559 bfd_set_error (bfd_error_invalid_target);
1565 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1567 relend = relocs + rel_size / RELOC_EXT_SIZE;
1568 for (rel = relocs; rel < relend; rel++)
1570 unsigned int r_index;
1573 struct sunos_link_hash_entry *h = NULL;
1575 /* Swap in the reloc information. */
1576 if (abfd->xvec->header_byteorder_big_p)
1578 r_index = ((rel->r_index[0] << 16)
1579 | (rel->r_index[1] << 8)
1581 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1582 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1583 >> RELOC_EXT_BITS_TYPE_SH_BIG);
1587 r_index = ((rel->r_index[2] << 16)
1588 | (rel->r_index[1] << 8)
1590 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1591 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1592 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
1597 h = sym_hashes[r_index];
1600 /* This should not normally happen, but it will in any
1601 case be caught in the relocation phase. */
1607 if (r_index >= bfd_get_symcount (abfd))
1609 /* This is abnormal, but should be caught in the
1610 relocation phase. */
1615 /* If this is a base relative reloc, we need to make an entry in
1616 the .got section. */
1617 if (r_type == RELOC_BASE10
1618 || r_type == RELOC_BASE13
1619 || r_type == RELOC_BASE22)
1623 if (! sunos_create_dynamic_sections (abfd, info, true))
1625 dynobj = sunos_hash_table (info)->dynobj;
1626 splt = bfd_get_section_by_name (dynobj, ".plt");
1627 sgot = bfd_get_section_by_name (dynobj, ".got");
1628 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1629 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1634 if (h->got_offset != 0)
1637 h->got_offset = sgot->_raw_size;
1641 if (adata (abfd).local_got_offsets == NULL)
1643 adata (abfd).local_got_offsets =
1644 (bfd_vma *) bfd_zalloc (abfd,
1645 (bfd_get_symcount (abfd)
1646 * sizeof (bfd_vma)));
1647 if (adata (abfd).local_got_offsets == NULL)
1649 bfd_set_error (bfd_error_no_memory);
1654 if (adata (abfd).local_got_offsets[r_index] != 0)
1657 adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
1660 sgot->_raw_size += BYTES_IN_WORD;
1662 /* If we are making a shared library, or if the symbol is
1663 defined by a dynamic object, we will need a dynamic reloc
1667 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1668 && (h->flags & SUNOS_DEF_REGULAR) == 0))
1669 srel->_raw_size += RELOC_EXT_SIZE;
1674 /* Otherwise, we are only interested in relocs against symbols
1675 defined in dynamic objects but not in regular objects. We
1676 only need to consider relocs against external symbols. */
1680 /* At this point common symbols have already been allocated, so
1681 we don't have to worry about them. We need to consider that
1682 we may have already seen this symbol and marked it undefined;
1683 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1685 if (h->root.root.type != bfd_link_hash_defined
1686 && h->root.root.type != bfd_link_hash_defweak
1687 && h->root.root.type != bfd_link_hash_undefined)
1690 if (r_type != RELOC_JMP_TBL
1691 && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1692 || (h->flags & SUNOS_DEF_REGULAR) != 0))
1695 if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1700 if (! sunos_create_dynamic_sections (abfd, info, true))
1702 dynobj = sunos_hash_table (info)->dynobj;
1703 splt = bfd_get_section_by_name (dynobj, ".plt");
1704 sgot = bfd_get_section_by_name (dynobj, ".got");
1705 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1706 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1709 BFD_ASSERT (r_type == RELOC_JMP_TBL
1710 || (h->flags & SUNOS_REF_REGULAR) != 0);
1711 BFD_ASSERT (r_type == RELOC_JMP_TBL
1712 || h->plt_offset != 0
1713 || ((h->root.root.type == bfd_link_hash_defined
1714 || h->root.root.type == bfd_link_hash_defweak)
1715 ? (h->root.root.u.def.section->owner->flags
1717 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1719 /* This reloc is against a symbol defined only by a dynamic
1720 object, or it is a jump table reloc from PIC compiled code. */
1722 if (h->root.root.type == bfd_link_hash_undefined)
1724 /* Presumably this symbol was marked as being undefined by
1725 an earlier reloc. */
1726 srel->_raw_size += RELOC_EXT_SIZE;
1728 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1732 /* This reloc is not in the .text section. It must be
1733 copied into the dynamic relocs. We mark the symbol as
1735 BFD_ASSERT (r_type != RELOC_JMP_TBL);
1736 srel->_raw_size += RELOC_EXT_SIZE;
1737 sub = h->root.root.u.def.section->owner;
1738 h->root.root.type = bfd_link_hash_undefined;
1739 h->root.root.u.undef.abfd = sub;
1743 /* This symbol is in the .text section. We must give it an
1744 entry in the procedure linkage table, if we have not
1745 already done so. We change the definition of the symbol
1746 to the .plt section; this will cause relocs against it to
1747 be handled correctly. */
1748 if (h->plt_offset == 0)
1750 if (splt->_raw_size == 0)
1751 splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
1752 h->plt_offset = splt->_raw_size;
1754 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1756 h->root.root.u.def.section = splt;
1757 h->root.root.u.def.value = splt->_raw_size;
1760 splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
1762 /* We will also need a dynamic reloc entry, unless this
1763 is a JMP_TBL reloc produced by linking PIC compiled
1764 code, and we are not making a shared library. */
1765 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1766 srel->_raw_size += RELOC_EXT_SIZE;
1774 /* Build the hash table of dynamic symbols, and to mark as written all
1775 symbols from dynamic objects which we do not plan to write out. */
1778 sunos_scan_dynamic_symbol (h, data)
1779 struct sunos_link_hash_entry *h;
1782 struct bfd_link_info *info = (struct bfd_link_info *) data;
1784 /* Set the written flag for symbols we do not want to write out as
1785 part of the regular symbol table. This is all symbols which are
1786 not defined in a regular object file. For some reason symbols
1787 which are referenced by a regular object and defined by a dynamic
1788 object do not seem to show up in the regular symbol table. */
1789 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1790 h->root.written = true;
1792 /* If this symbol is defined by a dynamic object and referenced by a
1793 regular object, see whether we gave it a reasonable value while
1794 scanning the relocs. */
1796 if ((h->flags & SUNOS_DEF_REGULAR) == 0
1797 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1798 && (h->flags & SUNOS_REF_REGULAR) != 0)
1800 if ((h->root.root.type == bfd_link_hash_defined
1801 || h->root.root.type == bfd_link_hash_defweak)
1802 && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1803 && h->root.root.u.def.section->output_section == NULL)
1807 /* This symbol is currently defined in a dynamic section
1808 which is not being put into the output file. This
1809 implies that there is no reloc against the symbol. I'm
1810 not sure why this case would ever occur. In any case, we
1811 change the symbol to be undefined. */
1812 sub = h->root.root.u.def.section->owner;
1813 h->root.root.type = bfd_link_hash_undefined;
1814 h->root.root.u.undef.abfd = sub;
1818 /* If this symbol is defined or referenced by a regular file, add it
1819 to the dynamic symbols. */
1820 if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1825 unsigned char *name;
1829 BFD_ASSERT (h->dynindx == -2);
1831 dynobj = sunos_hash_table (info)->dynobj;
1833 h->dynindx = sunos_hash_table (info)->dynsymcount;
1834 ++sunos_hash_table (info)->dynsymcount;
1836 len = strlen (h->root.root.root.string);
1838 /* We don't bother to construct a BFD hash table for the strings
1839 which are the names of the dynamic symbols. Using a hash
1840 table for the regular symbols is beneficial, because the
1841 regular symbols includes the debugging symbols, which have
1842 long names and are often duplicated in several object files.
1843 There are no debugging symbols in the dynamic symbols. */
1844 s = bfd_get_section_by_name (dynobj, ".dynstr");
1845 BFD_ASSERT (s != NULL);
1846 if (s->contents == NULL)
1847 contents = (bfd_byte *) malloc (len + 1);
1849 contents = (bfd_byte *) realloc (s->contents,
1850 (size_t) (s->_raw_size + len + 1));
1851 if (contents == NULL)
1853 bfd_set_error (bfd_error_no_memory);
1856 s->contents = contents;
1858 h->dynstr_index = s->_raw_size;
1859 strcpy (contents + s->_raw_size, h->root.root.root.string);
1860 s->_raw_size += len + 1;
1862 /* Add it to the dynamic hash table. */
1863 name = (unsigned char *) h->root.root.root.string;
1865 while (*name != '\0')
1866 hash = (hash << 1) + *name++;
1868 hash %= sunos_hash_table (info)->bucketcount;
1870 s = bfd_get_section_by_name (dynobj, ".hash");
1871 BFD_ASSERT (s != NULL);
1873 if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
1874 PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
1879 next = GET_WORD (dynobj,
1881 + hash * HASH_ENTRY_SIZE
1883 PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
1884 s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
1885 PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
1886 PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
1887 s->_raw_size += HASH_ENTRY_SIZE;
1894 /* Link a dynamic object. We actually don't have anything to do at
1895 this point. This entry point exists to prevent the regular linker
1896 code from doing anything with the object. */
1900 sunos_link_dynamic_object (info, abfd)
1901 struct bfd_link_info *info;
1907 /* Write out a dynamic symbol. This is called by the final traversal
1908 over the symbol table. */
1911 sunos_write_dynamic_symbol (output_bfd, info, harg)
1913 struct bfd_link_info *info;
1914 struct aout_link_hash_entry *harg;
1916 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
1920 struct external_nlist *outsym;
1925 switch (h->root.root.type)
1928 case bfd_link_hash_new:
1930 /* Avoid variable not initialized warnings. */
1932 case bfd_link_hash_undefined:
1933 type = N_UNDF | N_EXT;
1936 case bfd_link_hash_defined:
1937 case bfd_link_hash_defweak:
1940 asection *output_section;
1942 sec = h->root.root.u.def.section;
1943 output_section = sec->output_section;
1944 BFD_ASSERT (bfd_is_abs_section (output_section)
1945 || output_section->owner == output_bfd);
1946 if (h->plt_offset != 0
1947 && (h->flags & SUNOS_DEF_REGULAR) == 0)
1949 type = N_UNDF | N_EXT;
1954 if (output_section == obj_textsec (output_bfd))
1955 type = (h->root.root.type == bfd_link_hash_defined
1958 else if (output_section == obj_datasec (output_bfd))
1959 type = (h->root.root.type == bfd_link_hash_defined
1962 else if (output_section == obj_bsssec (output_bfd))
1963 type = (h->root.root.type == bfd_link_hash_defined
1967 type = (h->root.root.type == bfd_link_hash_defined
1971 val = (h->root.root.u.def.value
1972 + output_section->vma
1973 + sec->output_offset);
1977 case bfd_link_hash_common:
1978 type = N_UNDF | N_EXT;
1979 val = h->root.root.u.c.size;
1981 case bfd_link_hash_undefweak:
1985 case bfd_link_hash_indirect:
1986 case bfd_link_hash_warning:
1987 /* FIXME: Ignore these for now. The circumstances under which
1988 they should be written out are not clear to me. */
1992 s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
1993 BFD_ASSERT (s != NULL);
1994 outsym = ((struct external_nlist *)
1995 (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
1997 bfd_h_put_8 (output_bfd, type, outsym->e_type);
1998 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
2000 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
2001 one less than the desc value in the shared library, although that
2003 bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
2005 PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
2006 PUT_WORD (output_bfd, val, outsym->e_value);
2008 /* If this symbol is in the procedure linkage table, fill in the
2010 if (h->plt_offset != 0)
2018 dynobj = sunos_hash_table (info)->dynobj;
2019 splt = bfd_get_section_by_name (dynobj, ".plt");
2020 p = splt->contents + h->plt_offset;
2022 s = bfd_get_section_by_name (dynobj, ".dynrel");
2024 r_address = (h->root.root.u.def.section->output_section->vma
2025 + h->root.root.u.def.section->output_offset
2026 + h->root.root.u.def.value);
2028 switch (bfd_get_arch (output_bfd))
2030 case bfd_arch_sparc:
2031 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2033 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
2034 bfd_put_32 (output_bfd,
2035 (SPARC_PLT_ENTRY_WORD1
2036 + (((- (h->plt_offset + 4) >> 2)
2039 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
2046 val = (h->root.root.u.def.section->output_section->vma
2047 + h->root.root.u.def.section->output_offset
2048 + h->root.root.u.def.value);
2049 bfd_put_32 (output_bfd,
2050 SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
2052 bfd_put_32 (output_bfd,
2053 SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
2055 bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
2060 if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
2062 bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
2063 bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
2064 bfd_put_16 (output_bfd, s->reloc_count, p + 6);
2072 /* We also need to add a jump table reloc, unless this is the
2073 result of a JMP_TBL reloc from PIC compiled code. */
2074 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2076 p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
2077 if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
2079 struct reloc_std_external *srel;
2081 srel = (struct reloc_std_external *) p;
2082 PUT_WORD (output_bfd, r_address, srel->r_address);
2083 if (output_bfd->xvec->header_byteorder_big_p)
2085 srel->r_index[0] = h->dynindx >> 16;
2086 srel->r_index[1] = h->dynindx >> 8;
2087 srel->r_index[2] = h->dynindx;
2088 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
2089 | RELOC_STD_BITS_JMPTABLE_BIG);
2093 srel->r_index[2] = h->dynindx >> 16;
2094 srel->r_index[1] = h->dynindx >> 8;
2095 srel->r_index[0] = h->dynindx;
2096 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2097 | RELOC_STD_BITS_JMPTABLE_LITTLE);
2102 struct reloc_ext_external *erel;
2104 erel = (struct reloc_ext_external *) p;
2105 PUT_WORD (output_bfd, r_address, erel->r_address);
2106 if (output_bfd->xvec->header_byteorder_big_p)
2108 erel->r_index[0] = h->dynindx >> 16;
2109 erel->r_index[1] = h->dynindx >> 8;
2110 erel->r_index[2] = h->dynindx;
2111 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_BIG
2112 | (22 << RELOC_EXT_BITS_TYPE_SH_BIG));
2116 erel->r_index[2] = h->dynindx >> 16;
2117 erel->r_index[1] = h->dynindx >> 8;
2118 erel->r_index[0] = h->dynindx;
2119 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_LITTLE
2120 | (22 << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2122 PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
2132 /* This is called for each reloc against an external symbol. If this
2133 is a reloc which are are going to copy as a dynamic reloc, then
2134 copy it over, and tell the caller to not bother processing this
2139 sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
2140 contents, skip, relocationp)
2141 struct bfd_link_info *info;
2143 asection *input_section;
2144 struct aout_link_hash_entry *harg;
2148 bfd_vma *relocationp;
2150 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
2158 dynobj = sunos_hash_table (info)->dynobj;
2160 if (h != NULL && h->plt_offset != 0)
2164 /* Redirect the relocation to the PLT entry. */
2165 splt = bfd_get_section_by_name (dynobj, ".plt");
2166 *relocationp = (splt->output_section->vma
2167 + splt->output_offset
2171 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2173 struct reloc_std_external *srel;
2175 srel = (struct reloc_std_external *) reloc;
2176 if (input_bfd->xvec->header_byteorder_big_p)
2177 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2179 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2183 struct reloc_ext_external *erel;
2186 erel = (struct reloc_ext_external *) reloc;
2187 if (input_bfd->xvec->header_byteorder_big_p)
2188 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2189 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2191 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2192 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2193 baserel = (r_type == RELOC_BASE10
2194 || r_type == RELOC_BASE13
2195 || r_type == RELOC_BASE22);
2200 bfd_vma *got_offsetp;
2204 got_offsetp = &h->got_offset;
2205 else if (adata (input_bfd).local_got_offsets == NULL)
2209 struct reloc_std_external *srel;
2212 srel = (struct reloc_std_external *) reloc;
2213 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2215 if (input_bfd->xvec->header_byteorder_big_p)
2216 r_index = ((srel->r_index[0] << 16)
2217 | (srel->r_index[1] << 8)
2218 | srel->r_index[2]);
2220 r_index = ((srel->r_index[2] << 16)
2221 | (srel->r_index[1] << 8)
2222 | srel->r_index[0]);
2226 struct reloc_ext_external *erel;
2228 erel = (struct reloc_ext_external *) reloc;
2229 if (input_bfd->xvec->header_byteorder_big_p)
2230 r_index = ((erel->r_index[0] << 16)
2231 | (erel->r_index[1] << 8)
2232 | erel->r_index[2]);
2234 r_index = ((erel->r_index[2] << 16)
2235 | (erel->r_index[1] << 8)
2236 | erel->r_index[0]);
2239 got_offsetp = adata (input_bfd).local_got_offsets + r_index;
2242 BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
2244 sgot = bfd_get_section_by_name (dynobj, ".got");
2246 /* We set the least significant bit to indicate whether we have
2247 already initialized the GOT entry. */
2248 if ((*got_offsetp & 1) == 0)
2250 PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
2253 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
2254 && (h->flags & SUNOS_DEF_REGULAR) == 0)
2256 /* We need to create a GLOB_DAT reloc to tell the
2257 dynamic linker to fill in this entry in the table. */
2259 s = bfd_get_section_by_name (dynobj, ".dynrel");
2260 BFD_ASSERT (s != NULL);
2263 + s->reloc_count * obj_reloc_entry_size (dynobj));
2265 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2267 struct reloc_std_external *srel;
2269 srel = (struct reloc_std_external *) p;
2272 + sgot->output_section->vma
2273 + sgot->output_offset),
2275 if (dynobj->xvec->header_byteorder_big_p)
2277 srel->r_index[0] = h->dynindx >> 16;
2278 srel->r_index[1] = h->dynindx >> 8;
2279 srel->r_index[2] = h->dynindx;
2281 (RELOC_STD_BITS_EXTERN_BIG
2282 | RELOC_STD_BITS_BASEREL_BIG
2283 | RELOC_STD_BITS_RELATIVE_BIG
2284 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
2288 srel->r_index[2] = h->dynindx >> 16;
2289 srel->r_index[1] = h->dynindx >> 8;
2290 srel->r_index[0] = h->dynindx;
2292 (RELOC_STD_BITS_EXTERN_LITTLE
2293 | RELOC_STD_BITS_BASEREL_LITTLE
2294 | RELOC_STD_BITS_RELATIVE_LITTLE
2295 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2300 struct reloc_ext_external *erel;
2302 erel = (struct reloc_ext_external *) p;
2305 + sgot->output_section->vma
2306 + sgot->output_offset),
2308 if (dynobj->xvec->header_byteorder_big_p)
2310 erel->r_index[0] = h->dynindx >> 16;
2311 erel->r_index[1] = h->dynindx >> 8;
2312 erel->r_index[2] = h->dynindx;
2314 (RELOC_EXT_BITS_EXTERN_BIG
2315 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
2319 erel->r_index[2] = h->dynindx >> 16;
2320 erel->r_index[1] = h->dynindx >> 8;
2321 erel->r_index[0] = h->dynindx;
2323 (RELOC_EXT_BITS_EXTERN_LITTLE
2324 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2326 PUT_WORD (dynobj, 0, erel->r_addend);
2335 *relocationp = sgot->vma + (*got_offsetp &~ 1);
2337 /* There is nothing else to do for a base relative reloc. */
2341 if (! sunos_hash_table (info)->dynamic_sections_needed
2344 || h->root.root.type != bfd_link_hash_undefined
2345 || (h->flags & SUNOS_DEF_REGULAR) != 0
2346 || (h->flags & SUNOS_DEF_DYNAMIC) == 0
2347 || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
2350 /* It looks like this is a reloc we are supposed to copy. */
2352 s = bfd_get_section_by_name (dynobj, ".dynrel");
2353 BFD_ASSERT (s != NULL);
2355 p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
2357 /* Copy the reloc over. */
2358 memcpy (p, reloc, obj_reloc_entry_size (dynobj));
2360 /* Adjust the address and symbol index. */
2361 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2363 struct reloc_std_external *srel;
2365 srel = (struct reloc_std_external *) p;
2367 (GET_WORD (dynobj, srel->r_address)
2368 + input_section->output_section->vma
2369 + input_section->output_offset),
2371 if (dynobj->xvec->header_byteorder_big_p)
2373 srel->r_index[0] = h->dynindx >> 16;
2374 srel->r_index[1] = h->dynindx >> 8;
2375 srel->r_index[2] = h->dynindx;
2379 srel->r_index[2] = h->dynindx >> 16;
2380 srel->r_index[1] = h->dynindx >> 8;
2381 srel->r_index[0] = h->dynindx;
2386 struct reloc_ext_external *erel;
2388 erel = (struct reloc_ext_external *) p;
2390 (GET_WORD (dynobj, erel->r_address)
2391 + input_section->output_section->vma
2392 + input_section->output_offset),
2394 if (dynobj->xvec->header_byteorder_big_p)
2396 erel->r_index[0] = h->dynindx >> 16;
2397 erel->r_index[1] = h->dynindx >> 8;
2398 erel->r_index[2] = h->dynindx;
2402 erel->r_index[2] = h->dynindx >> 16;
2403 erel->r_index[1] = h->dynindx >> 8;
2404 erel->r_index[0] = h->dynindx;
2415 /* Finish up the dynamic linking information. */
2418 sunos_finish_dynamic_link (abfd, info)
2420 struct bfd_link_info *info;
2426 struct external_sun4_dynamic esd;
2427 struct external_sun4_dynamic_link esdl;
2429 if (! sunos_hash_table (info)->dynamic_sections_needed)
2432 dynobj = sunos_hash_table (info)->dynobj;
2434 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2435 BFD_ASSERT (sdyn != NULL);
2437 /* Finish up the .need section. The linker emulation code filled it
2438 in, but with offsets from the start of the section instead of
2439 real addresses. Now that we know the section location, we can
2440 fill in the final values. */
2441 s = bfd_get_section_by_name (dynobj, ".need");
2442 if (s != NULL && s->_raw_size != 0)
2447 filepos = s->output_section->filepos + s->output_offset;
2453 PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
2454 val = GET_WORD (dynobj, p + 12);
2457 PUT_WORD (dynobj, val + filepos, p + 12);
2462 /* The first entry in the .got section is the address of the dynamic
2464 s = bfd_get_section_by_name (dynobj, ".got");
2465 BFD_ASSERT (s != NULL);
2466 PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
2469 for (o = dynobj->sections; o != NULL; o = o->next)
2471 if ((o->flags & SEC_HAS_CONTENTS) != 0
2472 && o->contents != NULL)
2474 BFD_ASSERT (o->output_section != NULL
2475 && o->output_section->owner == abfd);
2476 if (! bfd_set_section_contents (abfd, o->output_section,
2477 o->contents, o->output_offset,
2483 /* Finish up the dynamic link information. */
2484 PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
2486 sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
2489 (sdyn->output_section->vma
2490 + sdyn->output_offset
2492 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2495 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
2496 sdyn->output_offset, sizeof esd))
2500 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
2502 s = bfd_get_section_by_name (dynobj, ".need");
2503 if (s == NULL || s->_raw_size == 0)
2504 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
2506 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2509 s = bfd_get_section_by_name (dynobj, ".rules");
2510 if (s == NULL || s->_raw_size == 0)
2511 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
2513 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2516 s = bfd_get_section_by_name (dynobj, ".got");
2517 BFD_ASSERT (s != NULL);
2518 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
2520 s = bfd_get_section_by_name (dynobj, ".plt");
2521 BFD_ASSERT (s != NULL);
2522 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
2523 PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
2525 s = bfd_get_section_by_name (dynobj, ".dynrel");
2526 BFD_ASSERT (s != NULL);
2527 BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
2528 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2531 s = bfd_get_section_by_name (dynobj, ".hash");
2532 BFD_ASSERT (s != NULL);
2533 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2536 s = bfd_get_section_by_name (dynobj, ".dynsym");
2537 BFD_ASSERT (s != NULL);
2538 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2541 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
2543 PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
2546 s = bfd_get_section_by_name (dynobj, ".dynstr");
2547 BFD_ASSERT (s != NULL);
2548 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2550 PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
2552 /* The size of the text area is the size of the .text section
2553 rounded up to a page boundary. FIXME: Should the page size be
2554 conditional on something? */
2556 BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
2559 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
2560 (sdyn->output_offset
2562 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2566 abfd->flags |= DYNAMIC;