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 /* The only way to get the size of the symbol information appears to
208 be to determine the distance between it and the string table. */
209 info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
210 / EXTERNAL_NLIST_SIZE);
211 BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
212 == (unsigned long) (info->dyninfo.ld_symbols
213 - info->dyninfo.ld_stab));
215 /* Similarly, the relocs end at the hash table. */
216 info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
217 / obj_reloc_entry_size (abfd));
218 BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
219 == (unsigned long) (info->dyninfo.ld_hash
220 - info->dyninfo.ld_rel));
227 /* Return the amount of memory required for the dynamic symbols. */
230 sunos_get_dynamic_symtab_upper_bound (abfd)
233 struct sunos_dynamic_info *info;
235 if (! sunos_read_dynamic_info (abfd))
238 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
241 bfd_set_error (bfd_error_no_symbols);
245 return (info->dynsym_count + 1) * sizeof (asymbol *);
248 /* Read the external dynamic symbols. */
251 sunos_slurp_dynamic_symtab (abfd)
254 struct sunos_dynamic_info *info;
256 /* Get the general dynamic information. */
257 if (obj_aout_dynamic_info (abfd) == NULL)
259 if (! sunos_read_dynamic_info (abfd))
263 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
266 bfd_set_error (bfd_error_no_symbols);
270 /* Get the dynamic nlist structures. */
271 if (info->dynsym == (struct external_nlist *) NULL)
273 info->dynsym = ((struct external_nlist *)
276 * EXTERNAL_NLIST_SIZE)));
277 if (info->dynsym == NULL && info->dynsym_count != 0)
279 bfd_set_error (bfd_error_no_memory);
282 if (bfd_seek (abfd, info->dyninfo.ld_stab, SEEK_SET) != 0
283 || (bfd_read ((PTR) info->dynsym, info->dynsym_count,
284 EXTERNAL_NLIST_SIZE, abfd)
285 != info->dynsym_count * EXTERNAL_NLIST_SIZE))
287 if (info->dynsym != NULL)
289 bfd_release (abfd, info->dynsym);
296 /* Get the dynamic strings. */
297 if (info->dynstr == (char *) NULL)
299 info->dynstr = (char *) bfd_alloc (abfd, info->dyninfo.ld_symb_size);
300 if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
302 bfd_set_error (bfd_error_no_memory);
305 if (bfd_seek (abfd, info->dyninfo.ld_symbols, SEEK_SET) != 0
306 || (bfd_read ((PTR) info->dynstr, 1, info->dyninfo.ld_symb_size,
308 != info->dyninfo.ld_symb_size))
310 if (info->dynstr != NULL)
312 bfd_release (abfd, info->dynstr);
322 /* Read in the dynamic symbols. */
325 sunos_canonicalize_dynamic_symtab (abfd, storage)
329 struct sunos_dynamic_info *info;
332 if (! sunos_slurp_dynamic_symtab (abfd))
335 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
337 #ifdef CHECK_DYNAMIC_HASH
338 /* Check my understanding of the dynamic hash table by making sure
339 that each symbol can be located in the hash table. */
341 bfd_size_type table_size;
345 if (info->dyninfo.ld_buckets > info->dynsym_count)
347 table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
348 table = (bfd_byte *) malloc (table_size);
349 if (table == NULL && table_size != 0)
351 if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
352 || bfd_read ((PTR) table, 1, table_size, abfd) != table_size)
354 for (i = 0; i < info->dynsym_count; i++)
359 name = ((unsigned char *) info->dynstr
360 + GET_WORD (abfd, info->dynsym[i].e_strx));
362 while (*name != '\0')
363 hash = (hash << 1) + *name++;
365 hash %= info->dyninfo.ld_buckets;
366 while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
368 hash = GET_WORD (abfd,
369 table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
370 if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
376 #endif /* CHECK_DYNAMIC_HASH */
378 /* Get the asymbol structures corresponding to the dynamic nlist
380 if (info->canonical_dynsym == (aout_symbol_type *) NULL)
382 info->canonical_dynsym = ((aout_symbol_type *)
385 * sizeof (aout_symbol_type))));
386 if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
388 bfd_set_error (bfd_error_no_memory);
392 if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
393 info->dynsym, info->dynsym_count,
395 info->dyninfo.ld_symb_size,
398 if (info->canonical_dynsym != NULL)
400 bfd_release (abfd, info->canonical_dynsym);
401 info->canonical_dynsym = NULL;
407 /* Return pointers to the dynamic asymbol structures. */
408 for (i = 0; i < info->dynsym_count; i++)
409 *storage++ = (asymbol *) (info->canonical_dynsym + i);
412 return info->dynsym_count;
415 /* Return the amount of memory required for the dynamic relocs. */
418 sunos_get_dynamic_reloc_upper_bound (abfd)
421 struct sunos_dynamic_info *info;
423 if (! sunos_read_dynamic_info (abfd))
426 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
429 bfd_set_error (bfd_error_no_symbols);
433 return (info->dynrel_count + 1) * sizeof (arelent *);
436 /* Read in the dynamic relocs. */
439 sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
444 struct sunos_dynamic_info *info;
447 /* Get the general dynamic information. */
448 if (obj_aout_dynamic_info (abfd) == (PTR) NULL)
450 if (! sunos_read_dynamic_info (abfd))
454 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
457 bfd_set_error (bfd_error_no_symbols);
461 /* Get the dynamic reloc information. */
462 if (info->dynrel == NULL)
464 info->dynrel = (PTR) bfd_alloc (abfd,
466 * obj_reloc_entry_size (abfd)));
467 if (info->dynrel == NULL && info->dynrel_count != 0)
469 bfd_set_error (bfd_error_no_memory);
472 if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
473 || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
474 obj_reloc_entry_size (abfd), abfd)
475 != info->dynrel_count * obj_reloc_entry_size (abfd)))
477 if (info->dynrel != NULL)
479 bfd_release (abfd, info->dynrel);
486 /* Get the arelent structures corresponding to the dynamic reloc
488 if (info->canonical_dynrel == (arelent *) NULL)
492 info->canonical_dynrel = ((arelent *)
495 * sizeof (arelent))));
496 if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
498 bfd_set_error (bfd_error_no_memory);
502 to = info->canonical_dynrel;
504 if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
506 register struct reloc_ext_external *p;
507 struct reloc_ext_external *pend;
509 p = (struct reloc_ext_external *) info->dynrel;
510 pend = p + info->dynrel_count;
511 for (; p < pend; p++, to++)
512 NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms,
517 register struct reloc_std_external *p;
518 struct reloc_std_external *pend;
520 p = (struct reloc_std_external *) info->dynrel;
521 pend = p + info->dynrel_count;
522 for (; p < pend; p++, to++)
523 NAME(aout,swap_std_reloc_in) (abfd, p, to, syms,
528 /* Return pointers to the dynamic arelent structures. */
529 for (i = 0; i < info->dynrel_count; i++)
530 *storage++ = info->canonical_dynrel + i;
533 return info->dynrel_count;
536 /* Code to handle linking of SunOS shared libraries. */
538 /* A SPARC procedure linkage table entry is 12 bytes. The first entry
539 in the table is a jump which is filled in by the runtime linker.
540 The remaining entries are branches back to the first entry,
541 followed by an index into the relocation table encoded to look like
544 #define SPARC_PLT_ENTRY_SIZE (12)
546 static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
548 /* sethi %hi(0),%g1; address filled in by runtime linker. */
550 /* jmp %g1; offset filled in by runtime linker. */
556 /* save %sp, -96, %sp */
557 #define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0
558 /* call; address filled in later. */
559 #define SPARC_PLT_ENTRY_WORD1 0x40000000
560 /* sethi; reloc index filled in later. */
561 #define SPARC_PLT_ENTRY_WORD2 0x01000000
563 /* This sequence is used when for the jump table entry to a defined
564 symbol in a complete executable. It is used when linking PIC
565 compiled code which is not being put into a shared library. */
566 /* sethi <address to be filled in later>, %g1 */
567 #define SPARC_PLT_PIC_WORD0 0x03000000
568 /* jmp %g1 + <address to be filled in later> */
569 #define SPARC_PLT_PIC_WORD1 0x81c06000
571 #define SPARC_PLT_PIC_WORD2 0x01000000
573 /* An m68k procedure linkage table entry is 8 bytes. The first entry
574 in the table is a jump which is filled in the by the runtime
575 linker. The remaining entries are branches back to the first
576 entry, followed by a two byte index into the relocation table. */
578 #define M68K_PLT_ENTRY_SIZE (8)
580 static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
584 /* Filled in by runtime linker with a magic address. */
591 #define M68K_PLT_ENTRY_WORD0 (0x61ff)
592 /* Remaining words filled in later. */
594 /* An entry in the SunOS linker hash table. */
596 struct sunos_link_hash_entry
598 struct aout_link_hash_entry root;
600 /* If this is a dynamic symbol, this is its index into the dynamic
601 symbol table. This is initialized to -1. As the linker looks at
602 the input files, it changes this to -2 if it will be added to the
603 dynamic symbol table. After all the input files have been seen,
604 the linker will know whether to build a dynamic symbol table; if
605 it does build one, this becomes the index into the table. */
608 /* If this is a dynamic symbol, this is the index of the name in the
609 dynamic symbol string table. */
612 /* The offset into the global offset table used for this symbol. If
613 the symbol does not require a GOT entry, this is 0. */
616 /* The offset into the procedure linkage table used for this symbol.
617 If the symbol does not require a PLT entry, this is 0. */
620 /* Some linker flags. */
622 /* Symbol is referenced by a regular object. */
623 #define SUNOS_REF_REGULAR 01
624 /* Symbol is defined by a regular object. */
625 #define SUNOS_DEF_REGULAR 02
626 /* Symbol is referenced by a dynamic object. */
627 #define SUNOS_REF_DYNAMIC 010
628 /* Symbol is defined by a dynamic object. */
629 #define SUNOS_DEF_DYNAMIC 020
632 /* The SunOS linker hash table. */
634 struct sunos_link_hash_table
636 struct aout_link_hash_table root;
638 /* The object which holds the dynamic sections. */
641 /* Whether we have created the dynamic sections. */
642 boolean dynamic_sections_created;
644 /* Whether we need the dynamic sections. */
645 boolean dynamic_sections_needed;
647 /* The number of dynamic symbols. */
650 /* The number of buckets in the hash table. */
654 /* Routine to create an entry in an SunOS link hash table. */
656 static struct bfd_hash_entry *
657 sunos_link_hash_newfunc (entry, table, string)
658 struct bfd_hash_entry *entry;
659 struct bfd_hash_table *table;
662 struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
664 /* Allocate the structure if it has not already been allocated by a
666 if (ret == (struct sunos_link_hash_entry *) NULL)
667 ret = ((struct sunos_link_hash_entry *)
668 bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry)));
669 if (ret == (struct sunos_link_hash_entry *) NULL)
671 bfd_set_error (bfd_error_no_memory);
672 return (struct bfd_hash_entry *) ret;
675 /* Call the allocation method of the superclass. */
676 ret = ((struct sunos_link_hash_entry *)
677 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
681 /* Set local fields. */
683 ret->dynstr_index = -1;
689 return (struct bfd_hash_entry *) ret;
692 /* Create a SunOS link hash table. */
694 static struct bfd_link_hash_table *
695 sunos_link_hash_table_create (abfd)
698 struct sunos_link_hash_table *ret;
700 ret = ((struct sunos_link_hash_table *)
701 bfd_alloc (abfd, sizeof (struct sunos_link_hash_table)));
702 if (ret == (struct sunos_link_hash_table *) NULL)
704 bfd_set_error (bfd_error_no_memory);
705 return (struct bfd_link_hash_table *) NULL;
707 if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
708 sunos_link_hash_newfunc))
711 return (struct bfd_link_hash_table *) NULL;
715 ret->dynamic_sections_created = false;
716 ret->dynamic_sections_needed = false;
717 ret->dynsymcount = 0;
718 ret->bucketcount = 0;
720 return &ret->root.root;
723 /* Look up an entry in an SunOS link hash table. */
725 #define sunos_link_hash_lookup(table, string, create, copy, follow) \
726 ((struct sunos_link_hash_entry *) \
727 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
730 /* Traverse a SunOS link hash table. */
732 #define sunos_link_hash_traverse(table, func, info) \
733 (aout_link_hash_traverse \
735 (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
738 /* Get the SunOS link hash table from the info structure. This is
741 #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
743 static boolean sunos_scan_dynamic_symbol
744 PARAMS ((struct sunos_link_hash_entry *, PTR));
746 /* Create the dynamic sections needed if we are linking against a
747 dynamic object, or if we are linking PIC compiled code. ABFD is a
748 bfd we can attach the dynamic sections to. The linker script will
749 look for these special sections names and put them in the right
750 place in the output file. See include/aout/sun4.h for more details
751 of the dynamic linking information. */
754 sunos_create_dynamic_sections (abfd, info, needed)
756 struct bfd_link_info *info;
761 if (! sunos_hash_table (info)->dynamic_sections_created)
765 sunos_hash_table (info)->dynobj = abfd;
767 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
769 /* The .dynamic section holds the basic dynamic information: the
770 sun4_dynamic structure, the dynamic debugger information, and
771 the sun4_dynamic_link structure. */
772 s = bfd_make_section (abfd, ".dynamic");
774 || ! bfd_set_section_flags (abfd, s, flags)
775 || ! bfd_set_section_alignment (abfd, s, 2))
778 /* The .got section holds the global offset table. The address
779 is put in the ld_got field. */
780 s = bfd_make_section (abfd, ".got");
782 || ! bfd_set_section_flags (abfd, s, flags)
783 || ! bfd_set_section_alignment (abfd, s, 2))
786 /* The .plt section holds the procedure linkage table. The
787 address is put in the ld_plt field. */
788 s = bfd_make_section (abfd, ".plt");
790 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
791 || ! bfd_set_section_alignment (abfd, s, 2))
794 /* The .dynrel section holds the dynamic relocs. The address is
795 put in the ld_rel field. */
796 s = bfd_make_section (abfd, ".dynrel");
798 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
799 || ! bfd_set_section_alignment (abfd, s, 2))
802 /* The .hash section holds the dynamic hash table. The address
803 is put in the ld_hash field. */
804 s = bfd_make_section (abfd, ".hash");
806 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
807 || ! bfd_set_section_alignment (abfd, s, 2))
810 /* The .dynsym section holds the dynamic symbols. The address
811 is put in the ld_stab field. */
812 s = bfd_make_section (abfd, ".dynsym");
814 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
815 || ! bfd_set_section_alignment (abfd, s, 2))
818 /* The .dynstr section holds the dynamic symbol string table.
819 The address is put in the ld_symbols field. */
820 s = bfd_make_section (abfd, ".dynstr");
822 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
823 || ! bfd_set_section_alignment (abfd, s, 2))
826 sunos_hash_table (info)->dynamic_sections_created = true;
829 if (needed && ! sunos_hash_table (info)->dynamic_sections_needed)
833 dynobj = sunos_hash_table (info)->dynobj;
835 s = bfd_get_section_by_name (dynobj, ".got");
836 s->_raw_size = BYTES_IN_WORD;
838 sunos_hash_table (info)->dynamic_sections_needed = true;
844 /* Add dynamic symbols during a link. This is called by the a.out
845 backend linker when it encounters an object with the DYNAMIC flag
849 sunos_add_dynamic_symbols (abfd, info, symsp, sym_countp, stringsp)
851 struct bfd_link_info *info;
852 struct external_nlist **symsp;
853 bfd_size_type *sym_countp;
858 struct sunos_dynamic_info *dinfo;
860 /* We do not want to include the sections in a dynamic object in the
861 output file. We hack by simply clobbering the list of sections
862 in the BFD. This could be handled more cleanly by, say, a new
863 section flag; the existing SEC_NEVER_LOAD flag is not the one we
864 want, because that one still implies that the section takes up
865 space in the output file. */
866 abfd->sections = NULL;
868 /* The native linker seems to just ignore dynamic objects when -r is
870 if (info->relocateable)
873 /* There's no hope of using a dynamic object which does not exactly
874 match the format of the output file. */
875 if (info->hash->creator != abfd->xvec)
877 bfd_set_error (bfd_error_invalid_operation);
881 /* Make sure we have all the required information. */
882 if (! sunos_create_dynamic_sections (abfd, info, true))
885 /* Make sure we have a .need and a .rules sections. These are only
886 needed if there really is a dynamic object in the link, so they
887 are not added by sunos_create_dynamic_sections. */
888 dynobj = sunos_hash_table (info)->dynobj;
889 if (bfd_get_section_by_name (dynobj, ".need") == NULL)
891 /* The .need section holds the list of names of shared objets
892 which must be included at runtime. The address of this
893 section is put in the ld_need field. */
894 s = bfd_make_section (dynobj, ".need");
896 || ! bfd_set_section_flags (dynobj, s,
902 || ! bfd_set_section_alignment (dynobj, s, 2))
906 if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
908 /* The .rules section holds the path to search for shared
909 objects. The address of this section is put in the ld_rules
911 s = bfd_make_section (dynobj, ".rules");
913 || ! bfd_set_section_flags (dynobj, s,
919 || ! bfd_set_section_alignment (dynobj, s, 2))
923 /* Pick up the dynamic symbols and return them to the caller. */
924 if (! sunos_slurp_dynamic_symtab (abfd))
927 dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
928 *symsp = dinfo->dynsym;
929 *sym_countp = dinfo->dynsym_count;
930 *stringsp = dinfo->dynstr;
935 /* Function to add a single symbol to the linker hash table. This is
936 a wrapper around _bfd_generic_link_add_one_symbol which handles the
937 tweaking needed for dynamic linking support. */
940 sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
941 copy, collect, hashp)
942 struct bfd_link_info *info;
951 struct bfd_link_hash_entry **hashp;
953 struct sunos_link_hash_entry *h;
956 if (! sunos_hash_table (info)->dynamic_sections_created)
958 /* We must create the dynamic sections while reading the input
959 files, even though at this point we don't know if any of the
960 sections will be needed. This will ensure that the dynamic
961 sections are mapped to the right output section. It does no
962 harm to create these sections if they are not needed. */
963 if (! sunos_create_dynamic_sections (abfd, info, info->shared))
967 h = sunos_link_hash_lookup (sunos_hash_table (info), name, true, copy,
973 *hashp = (struct bfd_link_hash_entry *) h;
975 /* Treat a common symbol in a dynamic object as defined in the .bss
976 section of the dynamic object. We don't want to allocate space
977 for it in our process image. */
978 if ((abfd->flags & DYNAMIC) != 0
979 && bfd_is_com_section (section))
980 section = obj_bsssec (abfd);
982 if (! bfd_is_und_section (section)
983 && h->root.root.type != bfd_link_hash_new
984 && h->root.root.type != bfd_link_hash_undefined
985 && h->root.root.type != bfd_link_hash_defweak)
987 /* We are defining the symbol, and it is already defined. This
988 is a potential multiple definition error. */
989 if ((abfd->flags & DYNAMIC) != 0)
991 /* The definition we are adding is from a dynamic object.
992 We do not want this new definition to override the
993 existing definition, so we pretend it is just a
995 section = bfd_und_section_ptr;
997 else if ((h->root.root.type == bfd_link_hash_defined
998 && h->root.root.u.def.section->owner != NULL
999 && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1000 || (h->root.root.type == bfd_link_hash_common
1001 && ((h->root.root.u.c.p->section->owner->flags & DYNAMIC)
1004 /* The existing definition is from a dynamic object. We
1005 want to override it with the definition we just found.
1006 Clobber the existing definition. */
1007 h->root.root.type = bfd_link_hash_new;
1011 /* Do the usual procedure for adding a symbol. */
1012 if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
1013 value, string, copy, collect,
1017 if (abfd->xvec == info->hash->creator)
1019 /* Set a flag in the hash table entry indicating the type of
1020 reference or definition we just found. Keep a count of the
1021 number of dynamic symbols we find. A dynamic symbol is one
1022 which is referenced or defined by both a regular object and a
1024 if ((abfd->flags & DYNAMIC) == 0)
1026 if (bfd_is_und_section (section))
1027 new_flag = SUNOS_REF_REGULAR;
1029 new_flag = SUNOS_DEF_REGULAR;
1033 if (bfd_is_und_section (section))
1034 new_flag = SUNOS_REF_DYNAMIC;
1036 new_flag = SUNOS_DEF_DYNAMIC;
1038 h->flags |= new_flag;
1040 if (h->dynindx == -1
1041 && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1043 ++sunos_hash_table (info)->dynsymcount;
1051 /* Record an assignment made to a symbol by a linker script. We need
1052 this in case some dynamic object refers to this symbol. */
1055 bfd_sunos_record_link_assignment (output_bfd, info, name)
1057 struct bfd_link_info *info;
1060 struct sunos_link_hash_entry *h;
1062 /* This is called after we have examined all the input objects. If
1063 the symbol does not exist, it merely means that no object refers
1064 to it, and we can just ignore it at this point. */
1065 h = sunos_link_hash_lookup (sunos_hash_table (info), name,
1066 false, false, false);
1070 h->flags |= SUNOS_DEF_REGULAR;
1072 if (h->dynindx == -1)
1074 ++sunos_hash_table (info)->dynsymcount;
1081 /* Set up the sizes and contents of the dynamic sections created in
1082 sunos_add_dynamic_symbols. This is called by the SunOS linker
1083 emulation before_allocation routine. We must set the sizes of the
1084 sections before the linker sets the addresses of the various
1085 sections. This unfortunately requires reading all the relocs so
1086 that we can work out which ones need to become dynamic relocs. If
1087 info->keep_memory is true, we keep the relocs in memory; otherwise,
1088 we discard them, and will read them again later. */
1091 bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
1094 struct bfd_link_info *info;
1096 asection **sneedptr;
1097 asection **srulesptr;
1101 struct sunos_link_hash_entry *h;
1112 /* Look through all the input BFD's and read their relocs. It would
1113 be better if we didn't have to do this, but there is no other way
1114 to determine the number of dynamic relocs we need, and, more
1115 importantly, there is no other way to know which symbols should
1116 get an entry in the procedure linkage table. */
1117 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
1119 if ((sub->flags & DYNAMIC) == 0)
1121 if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
1122 exec_hdr (sub)->a_trsize)
1123 || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
1124 exec_hdr (sub)->a_drsize))
1129 dynobj = sunos_hash_table (info)->dynobj;
1130 dynsymcount = sunos_hash_table (info)->dynsymcount;
1132 /* If there were no dynamic objects in the link, and we don't need
1133 to build a global offset table, there is nothing to do here. */
1134 if (! sunos_hash_table (info)->dynamic_sections_needed)
1137 /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it. */
1138 h = sunos_link_hash_lookup (sunos_hash_table (info),
1139 "__GLOBAL_OFFSET_TABLE_", false, false, false);
1140 if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
1142 h->flags |= SUNOS_DEF_REGULAR;
1143 if (h->dynindx == -1)
1145 ++sunos_hash_table (info)->dynsymcount;
1148 h->root.root.type = bfd_link_hash_defined;
1149 h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
1150 h->root.root.u.def.value = 0;
1153 /* The .dynamic section is always the same size. */
1154 s = bfd_get_section_by_name (dynobj, ".dynamic");
1155 BFD_ASSERT (s != NULL);
1156 s->_raw_size = (sizeof (struct external_sun4_dynamic)
1157 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
1158 + sizeof (struct external_sun4_dynamic_link));
1160 /* Set the size of the .dynsym and .hash sections. We counted the
1161 number of dynamic symbols as we read the input files. We will
1162 build the dynamic symbol table (.dynsym) and the hash table
1163 (.hash) when we build the final symbol table, because until then
1164 we do not know the correct value to give the symbols. We build
1165 the dynamic symbol string table (.dynstr) in a traversal of the
1166 symbol table using sunos_scan_dynamic_symbol. */
1167 s = bfd_get_section_by_name (dynobj, ".dynsym");
1168 BFD_ASSERT (s != NULL);
1169 s->_raw_size = dynsymcount * sizeof (struct external_nlist);
1170 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
1171 if (s->contents == NULL && s->_raw_size != 0)
1173 bfd_set_error (bfd_error_no_memory);
1177 /* The number of buckets is just the number of symbols divided by
1178 four. To compute the final size of the hash table, we must
1179 actually compute the hash table. Normally we need exactly as
1180 many entries in the hash table as there are dynamic symbols, but
1181 if some of the buckets are not used we will need additional
1182 entries. In the worst case, every symbol will hash to the same
1183 bucket, and we will need BUCKETCOUNT - 1 extra entries. */
1184 if (dynsymcount >= 4)
1185 bucketcount = dynsymcount / 4;
1186 else if (dynsymcount > 0)
1187 bucketcount = dynsymcount;
1190 s = bfd_get_section_by_name (dynobj, ".hash");
1191 BFD_ASSERT (s != NULL);
1192 hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
1193 s->contents = (bfd_byte *) bfd_alloc (dynobj, hashalloc);
1194 if (s->contents == NULL && dynsymcount > 0)
1196 bfd_set_error (bfd_error_no_memory);
1199 memset (s->contents, 0, hashalloc);
1200 for (i = 0; i < bucketcount; i++)
1201 PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
1202 s->_raw_size = bucketcount * HASH_ENTRY_SIZE;
1204 sunos_hash_table (info)->bucketcount = bucketcount;
1206 /* Scan all the symbols, place them in the dynamic symbol table, and
1207 build the dynamic hash table. We reuse dynsymcount as a counter
1208 for the number of symbols we have added so far. */
1209 sunos_hash_table (info)->dynsymcount = 0;
1210 sunos_link_hash_traverse (sunos_hash_table (info),
1211 sunos_scan_dynamic_symbol,
1213 BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
1215 /* The SunOS native linker seems to align the total size of the
1216 symbol strings to a multiple of 8. I don't know if this is
1217 important, but it can't hurt much. */
1218 s = bfd_get_section_by_name (dynobj, ".dynstr");
1219 BFD_ASSERT (s != NULL);
1220 if ((s->_raw_size & 7) != 0)
1225 add = 8 - (s->_raw_size & 7);
1226 contents = (bfd_byte *) realloc (s->contents,
1227 (size_t) (s->_raw_size + add));
1228 if (contents == NULL)
1230 bfd_set_error (bfd_error_no_memory);
1233 memset (contents + s->_raw_size, 0, (size_t) add);
1234 s->contents = contents;
1235 s->_raw_size += add;
1238 /* Now that we have worked out the sizes of the procedure linkage
1239 table and the dynamic relocs, allocate storage for them. */
1240 s = bfd_get_section_by_name (dynobj, ".plt");
1241 BFD_ASSERT (s != NULL);
1242 if (s->_raw_size != 0)
1244 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1245 if (s->contents == NULL)
1247 bfd_set_error (bfd_error_no_memory);
1251 /* Fill in the first entry in the table. */
1252 switch (bfd_get_arch (dynobj))
1254 case bfd_arch_sparc:
1255 memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
1259 memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
1267 s = bfd_get_section_by_name (dynobj, ".dynrel");
1268 if (s->_raw_size != 0)
1270 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1271 if (s->contents == NULL)
1273 bfd_set_error (bfd_error_no_memory);
1277 /* We use the reloc_count field to keep track of how many of the
1278 relocs we have output so far. */
1281 /* Make space for the global offset table. */
1282 s = bfd_get_section_by_name (dynobj, ".got");
1283 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1284 if (s->contents == NULL)
1286 bfd_set_error (bfd_error_no_memory);
1290 *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
1291 *sneedptr = bfd_get_section_by_name (dynobj, ".need");
1292 *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
1297 /* Scan the relocs for an input section. */
1300 sunos_scan_relocs (info, abfd, sec, rel_size)
1301 struct bfd_link_info *info;
1304 bfd_size_type rel_size;
1307 PTR free_relocs = NULL;
1312 if (! info->keep_memory)
1313 relocs = free_relocs = malloc ((size_t) rel_size);
1316 struct aout_section_data_struct *n;
1318 n = ((struct aout_section_data_struct *)
1319 bfd_alloc (abfd, sizeof (struct aout_section_data_struct)));
1324 set_aout_section_data (sec, n);
1325 relocs = malloc ((size_t) rel_size);
1326 aout_section_data (sec)->relocs = relocs;
1331 bfd_set_error (bfd_error_no_memory);
1335 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
1336 || bfd_read (relocs, 1, rel_size, abfd) != rel_size)
1339 if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
1341 if (! sunos_scan_std_relocs (info, abfd, sec,
1342 (struct reloc_std_external *) relocs,
1348 if (! sunos_scan_ext_relocs (info, abfd, sec,
1349 (struct reloc_ext_external *) relocs,
1354 if (free_relocs != NULL)
1360 if (free_relocs != NULL)
1365 /* Scan the relocs for an input section using standard relocs. We
1366 need to figure out what to do for each reloc against a dynamic
1367 symbol. If the symbol is in the .text section, an entry is made in
1368 the procedure linkage table. Note that this will do the wrong
1369 thing if the symbol is actually data; I don't think the Sun 3
1370 native linker handles this case correctly either. If the symbol is
1371 not in the .text section, we must preserve the reloc as a dynamic
1372 reloc. FIXME: We should also handle the PIC relocs here by
1373 building global offset table entries. */
1376 sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
1377 struct bfd_link_info *info;
1380 const struct reloc_std_external *relocs;
1381 bfd_size_type rel_size;
1384 asection *splt = NULL;
1385 asection *srel = NULL;
1386 struct sunos_link_hash_entry **sym_hashes;
1387 const struct reloc_std_external *rel, *relend;
1389 /* We only know how to handle m68k plt entries. */
1390 if (bfd_get_arch (abfd) != bfd_arch_m68k)
1392 bfd_set_error (bfd_error_invalid_target);
1398 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1400 relend = relocs + rel_size / RELOC_STD_SIZE;
1401 for (rel = relocs; rel < relend; rel++)
1404 struct sunos_link_hash_entry *h;
1406 /* We only want relocs against external symbols. */
1407 if (abfd->xvec->header_byteorder_big_p)
1409 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
1414 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
1418 /* Get the symbol index. */
1419 if (abfd->xvec->header_byteorder_big_p)
1420 r_index = ((rel->r_index[0] << 16)
1421 | (rel->r_index[1] << 8)
1424 r_index = ((rel->r_index[2] << 16)
1425 | (rel->r_index[1] << 8)
1428 /* Get the hash table entry. */
1429 h = sym_hashes[r_index];
1432 /* This should not normally happen, but it will in any case
1433 be caught in the relocation phase. */
1437 /* At this point common symbols have already been allocated, so
1438 we don't have to worry about them. We need to consider that
1439 we may have already seen this symbol and marked it undefined;
1440 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1442 if (h->root.root.type != bfd_link_hash_defined
1443 && h->root.root.type != bfd_link_hash_defweak
1444 && h->root.root.type != bfd_link_hash_undefined)
1447 if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1448 || (h->flags & SUNOS_DEF_REGULAR) != 0)
1453 if (! sunos_create_dynamic_sections (abfd, info, true))
1455 dynobj = sunos_hash_table (info)->dynobj;
1456 splt = bfd_get_section_by_name (dynobj, ".plt");
1457 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1458 BFD_ASSERT (splt != NULL && srel != NULL);
1461 BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
1462 BFD_ASSERT (h->plt_offset != 0
1463 || ((h->root.root.type == bfd_link_hash_defined
1464 || h->root.root.type == bfd_link_hash_defweak)
1465 ? (h->root.root.u.def.section->owner->flags
1467 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1469 /* This reloc is against a symbol defined only by a dynamic
1472 if (h->root.root.type == bfd_link_hash_undefined)
1474 /* Presumably this symbol was marked as being undefined by
1475 an earlier reloc. */
1476 srel->_raw_size += RELOC_STD_SIZE;
1478 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1482 /* This reloc is not in the .text section. It must be
1483 copied into the dynamic relocs. We mark the symbol as
1485 srel->_raw_size += RELOC_STD_SIZE;
1486 sub = h->root.root.u.def.section->owner;
1487 h->root.root.type = bfd_link_hash_undefined;
1488 h->root.root.u.undef.abfd = sub;
1492 /* This symbol is in the .text section. We must give it an
1493 entry in the procedure linkage table, if we have not
1494 already done so. We change the definition of the symbol
1495 to the .plt section; this will cause relocs against it to
1496 be handled correctly. */
1497 if (h->plt_offset == 0)
1499 if (splt->_raw_size == 0)
1500 splt->_raw_size = M68K_PLT_ENTRY_SIZE;
1501 h->plt_offset = splt->_raw_size;
1503 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1505 h->root.root.u.def.section = splt;
1506 h->root.root.u.def.value = splt->_raw_size;
1509 splt->_raw_size += M68K_PLT_ENTRY_SIZE;
1511 /* We may also need a dynamic reloc entry. */
1512 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1513 srel->_raw_size += RELOC_STD_SIZE;
1521 /* Scan the relocs for an input section using extended relocs. We
1522 need to figure out what to do for each reloc against a dynamic
1523 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1524 section, an entry is made in the procedure linkage table.
1525 Otherwise, we must preserve the reloc as a dynamic reloc. */
1528 sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
1529 struct bfd_link_info *info;
1532 const struct reloc_ext_external *relocs;
1533 bfd_size_type rel_size;
1536 struct sunos_link_hash_entry **sym_hashes;
1537 const struct reloc_ext_external *rel, *relend;
1538 asection *splt = NULL;
1539 asection *sgot = NULL;
1540 asection *srel = NULL;
1542 /* We only know how to handle SPARC plt entries. */
1543 if (bfd_get_arch (abfd) != bfd_arch_sparc)
1545 bfd_set_error (bfd_error_invalid_target);
1551 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1553 relend = relocs + rel_size / RELOC_EXT_SIZE;
1554 for (rel = relocs; rel < relend; rel++)
1556 unsigned int r_index;
1559 struct sunos_link_hash_entry *h = NULL;
1561 /* Swap in the reloc information. */
1562 if (abfd->xvec->header_byteorder_big_p)
1564 r_index = ((rel->r_index[0] << 16)
1565 | (rel->r_index[1] << 8)
1567 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1568 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1569 >> RELOC_EXT_BITS_TYPE_SH_BIG);
1573 r_index = ((rel->r_index[2] << 16)
1574 | (rel->r_index[1] << 8)
1576 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1577 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1578 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
1583 h = sym_hashes[r_index];
1586 /* This should not normally happen, but it will in any
1587 case be caught in the relocation phase. */
1593 if (r_index >= bfd_get_symcount (abfd))
1595 /* This is abnormal, but should be caught in the
1596 relocation phase. */
1601 /* If this is a base relative reloc, we need to make an entry in
1602 the .got section. */
1603 if (r_type == RELOC_BASE10
1604 || r_type == RELOC_BASE13
1605 || r_type == RELOC_BASE22)
1609 if (! sunos_create_dynamic_sections (abfd, info, true))
1611 dynobj = sunos_hash_table (info)->dynobj;
1612 splt = bfd_get_section_by_name (dynobj, ".plt");
1613 sgot = bfd_get_section_by_name (dynobj, ".got");
1614 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1615 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1620 if (h->got_offset != 0)
1623 h->got_offset = sgot->_raw_size;
1627 if (adata (abfd).local_got_offsets == NULL)
1629 adata (abfd).local_got_offsets =
1630 (bfd_vma *) bfd_zalloc (abfd,
1631 (bfd_get_symcount (abfd)
1632 * sizeof (bfd_vma)));
1633 if (adata (abfd).local_got_offsets == NULL)
1635 bfd_set_error (bfd_error_no_memory);
1640 if (adata (abfd).local_got_offsets[r_index] != 0)
1643 adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
1646 sgot->_raw_size += BYTES_IN_WORD;
1648 /* If we are making a shared library, or if the symbol is
1649 defined by a dynamic object, we will need a dynamic reloc
1653 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1654 && (h->flags & SUNOS_DEF_REGULAR) == 0))
1655 srel->_raw_size += RELOC_EXT_SIZE;
1660 /* Otherwise, we are only interested in relocs against symbols
1661 defined in dynamic objects but not in regular objects. We
1662 only need to consider relocs against external symbols. */
1666 /* At this point common symbols have already been allocated, so
1667 we don't have to worry about them. We need to consider that
1668 we may have already seen this symbol and marked it undefined;
1669 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1671 if (h->root.root.type != bfd_link_hash_defined
1672 && h->root.root.type != bfd_link_hash_defweak
1673 && h->root.root.type != bfd_link_hash_undefined)
1676 if (r_type != RELOC_JMP_TBL
1677 && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1678 || (h->flags & SUNOS_DEF_REGULAR) != 0))
1681 if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1686 if (! sunos_create_dynamic_sections (abfd, info, true))
1688 dynobj = sunos_hash_table (info)->dynobj;
1689 splt = bfd_get_section_by_name (dynobj, ".plt");
1690 sgot = bfd_get_section_by_name (dynobj, ".got");
1691 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1692 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1695 BFD_ASSERT (r_type == RELOC_JMP_TBL
1696 || (h->flags & SUNOS_REF_REGULAR) != 0);
1697 BFD_ASSERT (r_type == RELOC_JMP_TBL
1698 || h->plt_offset != 0
1699 || ((h->root.root.type == bfd_link_hash_defined
1700 || h->root.root.type == bfd_link_hash_defweak)
1701 ? (h->root.root.u.def.section->owner->flags
1703 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1705 /* This reloc is against a symbol defined only by a dynamic
1706 object, or it is a jump table reloc from PIC compiled code. */
1708 if (h->root.root.type == bfd_link_hash_undefined)
1710 /* Presumably this symbol was marked as being undefined by
1711 an earlier reloc. */
1712 srel->_raw_size += RELOC_EXT_SIZE;
1714 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1718 /* This reloc is not in the .text section. It must be
1719 copied into the dynamic relocs. We mark the symbol as
1721 BFD_ASSERT (r_type != RELOC_JMP_TBL);
1722 srel->_raw_size += RELOC_EXT_SIZE;
1723 sub = h->root.root.u.def.section->owner;
1724 h->root.root.type = bfd_link_hash_undefined;
1725 h->root.root.u.undef.abfd = sub;
1729 /* This symbol is in the .text section. We must give it an
1730 entry in the procedure linkage table, if we have not
1731 already done so. We change the definition of the symbol
1732 to the .plt section; this will cause relocs against it to
1733 be handled correctly. */
1734 if (h->plt_offset == 0)
1736 if (splt->_raw_size == 0)
1737 splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
1738 h->plt_offset = splt->_raw_size;
1740 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1742 h->root.root.u.def.section = splt;
1743 h->root.root.u.def.value = splt->_raw_size;
1746 splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
1748 /* We will also need a dynamic reloc entry, unless this
1749 is a JMP_TBL reloc produced by linking PIC compiled
1750 code, and we are not making a shared library. */
1751 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1752 srel->_raw_size += RELOC_EXT_SIZE;
1760 /* Build the hash table of dynamic symbols, and to mark as written all
1761 symbols from dynamic objects which we do not plan to write out. */
1764 sunos_scan_dynamic_symbol (h, data)
1765 struct sunos_link_hash_entry *h;
1768 struct bfd_link_info *info = (struct bfd_link_info *) data;
1770 /* Set the written flag for symbols we do not want to write out as
1771 part of the regular symbol table. This is all symbols which are
1772 not defined in a regular object file. For some reason symbols
1773 which are referenced by a regular object and defined by a dynamic
1774 object do not seem to show up in the regular symbol table. */
1775 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1776 h->root.written = true;
1778 /* If this symbol is defined by a dynamic object and referenced by a
1779 regular object, see whether we gave it a reasonable value while
1780 scanning the relocs. */
1782 if ((h->flags & SUNOS_DEF_REGULAR) == 0
1783 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1784 && (h->flags & SUNOS_REF_REGULAR) != 0)
1786 if ((h->root.root.type == bfd_link_hash_defined
1787 || h->root.root.type == bfd_link_hash_defweak)
1788 && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1789 && h->root.root.u.def.section->output_section == NULL)
1793 /* This symbol is currently defined in a dynamic section
1794 which is not being put into the output file. This
1795 implies that there is no reloc against the symbol. I'm
1796 not sure why this case would ever occur. In any case, we
1797 change the symbol to be undefined. */
1798 sub = h->root.root.u.def.section->owner;
1799 h->root.root.type = bfd_link_hash_undefined;
1800 h->root.root.u.undef.abfd = sub;
1804 /* If this symbol is defined or referenced by a regular file, add it
1805 to the dynamic symbols. */
1806 if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1811 unsigned char *name;
1815 BFD_ASSERT (h->dynindx == -2);
1817 dynobj = sunos_hash_table (info)->dynobj;
1819 h->dynindx = sunos_hash_table (info)->dynsymcount;
1820 ++sunos_hash_table (info)->dynsymcount;
1822 len = strlen (h->root.root.root.string);
1824 /* We don't bother to construct a BFD hash table for the strings
1825 which are the names of the dynamic symbols. Using a hash
1826 table for the regular symbols is beneficial, because the
1827 regular symbols includes the debugging symbols, which have
1828 long names and are often duplicated in several object files.
1829 There are no debugging symbols in the dynamic symbols. */
1830 s = bfd_get_section_by_name (dynobj, ".dynstr");
1831 BFD_ASSERT (s != NULL);
1832 if (s->contents == NULL)
1833 contents = (bfd_byte *) malloc (len + 1);
1835 contents = (bfd_byte *) realloc (s->contents,
1836 (size_t) (s->_raw_size + len + 1));
1837 if (contents == NULL)
1839 bfd_set_error (bfd_error_no_memory);
1842 s->contents = contents;
1844 h->dynstr_index = s->_raw_size;
1845 strcpy (contents + s->_raw_size, h->root.root.root.string);
1846 s->_raw_size += len + 1;
1848 /* Add it to the dynamic hash table. */
1849 name = (unsigned char *) h->root.root.root.string;
1851 while (*name != '\0')
1852 hash = (hash << 1) + *name++;
1854 hash %= sunos_hash_table (info)->bucketcount;
1856 s = bfd_get_section_by_name (dynobj, ".hash");
1857 BFD_ASSERT (s != NULL);
1859 if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
1860 PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
1865 next = GET_WORD (dynobj,
1867 + hash * HASH_ENTRY_SIZE
1869 PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
1870 s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
1871 PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
1872 PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
1873 s->_raw_size += HASH_ENTRY_SIZE;
1880 /* Link a dynamic object. We actually don't have anything to do at
1881 this point. This entry point exists to prevent the regular linker
1882 code from doing anything with the object. */
1886 sunos_link_dynamic_object (info, abfd)
1887 struct bfd_link_info *info;
1893 /* Write out a dynamic symbol. This is called by the final traversal
1894 over the symbol table. */
1897 sunos_write_dynamic_symbol (output_bfd, info, harg)
1899 struct bfd_link_info *info;
1900 struct aout_link_hash_entry *harg;
1902 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
1906 struct external_nlist *outsym;
1911 switch (h->root.root.type)
1914 case bfd_link_hash_new:
1916 /* Avoid variable not initialized warnings. */
1918 case bfd_link_hash_undefined:
1919 type = N_UNDF | N_EXT;
1922 case bfd_link_hash_defined:
1923 case bfd_link_hash_defweak:
1926 asection *output_section;
1928 sec = h->root.root.u.def.section;
1929 output_section = sec->output_section;
1930 BFD_ASSERT (bfd_is_abs_section (output_section)
1931 || output_section->owner == output_bfd);
1932 if (h->plt_offset != 0
1933 && (h->flags & SUNOS_DEF_REGULAR) == 0)
1935 type = N_UNDF | N_EXT;
1940 if (output_section == obj_textsec (output_bfd))
1941 type = (h->root.root.type == bfd_link_hash_defined
1944 else if (output_section == obj_datasec (output_bfd))
1945 type = (h->root.root.type == bfd_link_hash_defined
1948 else if (output_section == obj_bsssec (output_bfd))
1949 type = (h->root.root.type == bfd_link_hash_defined
1953 type = (h->root.root.type == bfd_link_hash_defined
1957 val = (h->root.root.u.def.value
1958 + output_section->vma
1959 + sec->output_offset);
1963 case bfd_link_hash_common:
1964 type = N_UNDF | N_EXT;
1965 val = h->root.root.u.c.size;
1967 case bfd_link_hash_undefweak:
1971 case bfd_link_hash_indirect:
1972 case bfd_link_hash_warning:
1973 /* FIXME: Ignore these for now. The circumstances under which
1974 they should be written out are not clear to me. */
1978 s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
1979 BFD_ASSERT (s != NULL);
1980 outsym = ((struct external_nlist *)
1981 (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
1983 bfd_h_put_8 (output_bfd, type, outsym->e_type);
1984 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
1986 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
1987 one less than the desc value in the shared library, although that
1989 bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
1991 PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
1992 PUT_WORD (output_bfd, val, outsym->e_value);
1994 /* If this symbol is in the procedure linkage table, fill in the
1996 if (h->plt_offset != 0)
2004 dynobj = sunos_hash_table (info)->dynobj;
2005 splt = bfd_get_section_by_name (dynobj, ".plt");
2006 p = splt->contents + h->plt_offset;
2008 s = bfd_get_section_by_name (dynobj, ".dynrel");
2010 r_address = (h->root.root.u.def.section->output_section->vma
2011 + h->root.root.u.def.section->output_offset
2012 + h->root.root.u.def.value);
2014 switch (bfd_get_arch (output_bfd))
2016 case bfd_arch_sparc:
2017 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2019 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
2020 bfd_put_32 (output_bfd,
2021 (SPARC_PLT_ENTRY_WORD1
2022 + (((- (h->plt_offset + 4) >> 2)
2025 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
2032 val = (h->root.root.u.def.section->output_section->vma
2033 + h->root.root.u.def.section->output_offset
2034 + h->root.root.u.def.value);
2035 bfd_put_32 (output_bfd,
2036 SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
2038 bfd_put_32 (output_bfd,
2039 SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
2041 bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
2046 if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
2048 bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
2049 bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
2050 bfd_put_16 (output_bfd, s->reloc_count, p + 6);
2058 /* We also need to add a jump table reloc, unless this is the
2059 result of a JMP_TBL reloc from PIC compiled code. */
2060 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2062 p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
2063 if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
2065 struct reloc_std_external *srel;
2067 srel = (struct reloc_std_external *) p;
2068 PUT_WORD (output_bfd, r_address, srel->r_address);
2069 if (output_bfd->xvec->header_byteorder_big_p)
2071 srel->r_index[0] = h->dynindx >> 16;
2072 srel->r_index[1] = h->dynindx >> 8;
2073 srel->r_index[2] = h->dynindx;
2074 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
2075 | RELOC_STD_BITS_JMPTABLE_BIG);
2079 srel->r_index[2] = h->dynindx >> 16;
2080 srel->r_index[1] = h->dynindx >> 8;
2081 srel->r_index[0] = h->dynindx;
2082 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2083 | RELOC_STD_BITS_JMPTABLE_LITTLE);
2088 struct reloc_ext_external *erel;
2090 erel = (struct reloc_ext_external *) p;
2091 PUT_WORD (output_bfd, r_address, erel->r_address);
2092 if (output_bfd->xvec->header_byteorder_big_p)
2094 erel->r_index[0] = h->dynindx >> 16;
2095 erel->r_index[1] = h->dynindx >> 8;
2096 erel->r_index[2] = h->dynindx;
2097 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_BIG
2098 | (22 << RELOC_EXT_BITS_TYPE_SH_BIG));
2102 erel->r_index[2] = h->dynindx >> 16;
2103 erel->r_index[1] = h->dynindx >> 8;
2104 erel->r_index[0] = h->dynindx;
2105 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_LITTLE
2106 | (22 << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2108 PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
2118 /* This is called for each reloc against an external symbol. If this
2119 is a reloc which are are going to copy as a dynamic reloc, then
2120 copy it over, and tell the caller to not bother processing this
2125 sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
2126 contents, skip, relocationp)
2127 struct bfd_link_info *info;
2129 asection *input_section;
2130 struct aout_link_hash_entry *harg;
2134 bfd_vma *relocationp;
2136 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
2144 dynobj = sunos_hash_table (info)->dynobj;
2146 if (h != NULL && h->plt_offset != 0)
2150 /* Redirect the relocation to the PLT entry. */
2151 splt = bfd_get_section_by_name (dynobj, ".plt");
2152 *relocationp = (splt->output_section->vma
2153 + splt->output_offset
2157 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2159 struct reloc_std_external *srel;
2161 srel = (struct reloc_std_external *) reloc;
2162 if (input_bfd->xvec->header_byteorder_big_p)
2163 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2165 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2169 struct reloc_ext_external *erel;
2172 erel = (struct reloc_ext_external *) reloc;
2173 if (input_bfd->xvec->header_byteorder_big_p)
2174 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2175 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2177 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2178 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2179 baserel = (r_type == RELOC_BASE10
2180 || r_type == RELOC_BASE13
2181 || r_type == RELOC_BASE22);
2186 bfd_vma *got_offsetp;
2190 got_offsetp = &h->got_offset;
2191 else if (adata (input_bfd).local_got_offsets == NULL)
2195 struct reloc_std_external *srel;
2198 srel = (struct reloc_std_external *) reloc;
2199 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2201 if (input_bfd->xvec->header_byteorder_big_p)
2202 r_index = ((srel->r_index[0] << 16)
2203 | (srel->r_index[1] << 8)
2204 | srel->r_index[2]);
2206 r_index = ((srel->r_index[2] << 16)
2207 | (srel->r_index[1] << 8)
2208 | srel->r_index[0]);
2212 struct reloc_ext_external *erel;
2214 erel = (struct reloc_ext_external *) reloc;
2215 if (input_bfd->xvec->header_byteorder_big_p)
2216 r_index = ((erel->r_index[0] << 16)
2217 | (erel->r_index[1] << 8)
2218 | erel->r_index[2]);
2220 r_index = ((erel->r_index[2] << 16)
2221 | (erel->r_index[1] << 8)
2222 | erel->r_index[0]);
2225 got_offsetp = adata (input_bfd).local_got_offsets + r_index;
2228 BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
2230 sgot = bfd_get_section_by_name (dynobj, ".got");
2232 /* We set the least significant bit to indicate whether we have
2233 already initialized the GOT entry. */
2234 if ((*got_offsetp & 1) == 0)
2236 PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
2239 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
2240 && (h->flags & SUNOS_DEF_REGULAR) == 0)
2242 /* We need to create a GLOB_DAT reloc to tell the
2243 dynamic linker to fill in this entry in the table. */
2245 s = bfd_get_section_by_name (dynobj, ".dynrel");
2246 BFD_ASSERT (s != NULL);
2249 + s->reloc_count * obj_reloc_entry_size (dynobj));
2251 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2253 struct reloc_std_external *srel;
2255 srel = (struct reloc_std_external *) p;
2258 + sgot->output_section->vma
2259 + sgot->output_offset),
2261 if (dynobj->xvec->header_byteorder_big_p)
2263 srel->r_index[0] = h->dynindx >> 16;
2264 srel->r_index[1] = h->dynindx >> 8;
2265 srel->r_index[2] = h->dynindx;
2267 (RELOC_STD_BITS_EXTERN_BIG
2268 | RELOC_STD_BITS_BASEREL_BIG
2269 | RELOC_STD_BITS_RELATIVE_BIG
2270 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
2274 srel->r_index[2] = h->dynindx >> 16;
2275 srel->r_index[1] = h->dynindx >> 8;
2276 srel->r_index[0] = h->dynindx;
2278 (RELOC_STD_BITS_EXTERN_LITTLE
2279 | RELOC_STD_BITS_BASEREL_LITTLE
2280 | RELOC_STD_BITS_RELATIVE_LITTLE
2281 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2286 struct reloc_ext_external *erel;
2288 erel = (struct reloc_ext_external *) p;
2291 + sgot->output_section->vma
2292 + sgot->output_offset),
2294 if (dynobj->xvec->header_byteorder_big_p)
2296 erel->r_index[0] = h->dynindx >> 16;
2297 erel->r_index[1] = h->dynindx >> 8;
2298 erel->r_index[2] = h->dynindx;
2300 (RELOC_EXT_BITS_EXTERN_BIG
2301 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
2305 erel->r_index[2] = h->dynindx >> 16;
2306 erel->r_index[1] = h->dynindx >> 8;
2307 erel->r_index[0] = h->dynindx;
2309 (RELOC_EXT_BITS_EXTERN_LITTLE
2310 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2312 PUT_WORD (dynobj, 0, erel->r_addend);
2321 *relocationp = sgot->vma + (*got_offsetp &~ 1);
2323 /* There is nothing else to do for a base relative reloc. */
2327 if (! sunos_hash_table (info)->dynamic_sections_needed
2330 || h->root.root.type != bfd_link_hash_undefined
2331 || (h->flags & SUNOS_DEF_REGULAR) != 0
2332 || (h->flags & SUNOS_DEF_DYNAMIC) == 0
2333 || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
2336 /* It looks like this is a reloc we are supposed to copy. */
2338 s = bfd_get_section_by_name (dynobj, ".dynrel");
2339 BFD_ASSERT (s != NULL);
2341 p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
2343 /* Copy the reloc over. */
2344 memcpy (p, reloc, obj_reloc_entry_size (dynobj));
2346 /* Adjust the address and symbol index. */
2347 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2349 struct reloc_std_external *srel;
2351 srel = (struct reloc_std_external *) p;
2353 (GET_WORD (dynobj, srel->r_address)
2354 + input_section->output_section->vma
2355 + input_section->output_offset),
2357 if (dynobj->xvec->header_byteorder_big_p)
2359 srel->r_index[0] = h->dynindx >> 16;
2360 srel->r_index[1] = h->dynindx >> 8;
2361 srel->r_index[2] = h->dynindx;
2365 srel->r_index[2] = h->dynindx >> 16;
2366 srel->r_index[1] = h->dynindx >> 8;
2367 srel->r_index[0] = h->dynindx;
2372 struct reloc_ext_external *erel;
2374 erel = (struct reloc_ext_external *) p;
2376 (GET_WORD (dynobj, erel->r_address)
2377 + input_section->output_section->vma
2378 + input_section->output_offset),
2380 if (dynobj->xvec->header_byteorder_big_p)
2382 erel->r_index[0] = h->dynindx >> 16;
2383 erel->r_index[1] = h->dynindx >> 8;
2384 erel->r_index[2] = h->dynindx;
2388 erel->r_index[2] = h->dynindx >> 16;
2389 erel->r_index[1] = h->dynindx >> 8;
2390 erel->r_index[0] = h->dynindx;
2401 /* Finish up the dynamic linking information. */
2404 sunos_finish_dynamic_link (abfd, info)
2406 struct bfd_link_info *info;
2412 struct external_sun4_dynamic esd;
2413 struct external_sun4_dynamic_link esdl;
2415 if (! sunos_hash_table (info)->dynamic_sections_needed)
2418 dynobj = sunos_hash_table (info)->dynobj;
2420 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2421 BFD_ASSERT (sdyn != NULL);
2423 /* Finish up the .need section. The linker emulation code filled it
2424 in, but with offsets from the start of the section instead of
2425 real addresses. Now that we know the section location, we can
2426 fill in the final values. */
2427 s = bfd_get_section_by_name (dynobj, ".need");
2428 if (s != NULL && s->_raw_size != 0)
2433 filepos = s->output_section->filepos + s->output_offset;
2439 PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
2440 val = GET_WORD (dynobj, p + 12);
2443 PUT_WORD (dynobj, val + filepos, p + 12);
2448 /* The first entry in the .got section is the address of the dynamic
2450 s = bfd_get_section_by_name (dynobj, ".got");
2451 BFD_ASSERT (s != NULL);
2452 PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
2455 for (o = dynobj->sections; o != NULL; o = o->next)
2457 if ((o->flags & SEC_HAS_CONTENTS) != 0
2458 && o->contents != NULL)
2460 BFD_ASSERT (o->output_section != NULL
2461 && o->output_section->owner == abfd);
2462 if (! bfd_set_section_contents (abfd, o->output_section,
2463 o->contents, o->output_offset,
2469 /* Finish up the dynamic link information. */
2470 PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
2472 sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
2475 (sdyn->output_section->vma
2476 + sdyn->output_offset
2478 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2481 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
2482 sdyn->output_offset, sizeof esd))
2486 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
2488 s = bfd_get_section_by_name (dynobj, ".need");
2489 if (s == NULL || s->_raw_size == 0)
2490 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
2492 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2495 s = bfd_get_section_by_name (dynobj, ".rules");
2496 if (s == NULL || s->_raw_size == 0)
2497 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
2499 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2502 s = bfd_get_section_by_name (dynobj, ".got");
2503 BFD_ASSERT (s != NULL);
2504 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
2506 s = bfd_get_section_by_name (dynobj, ".plt");
2507 BFD_ASSERT (s != NULL);
2508 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
2509 PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
2511 s = bfd_get_section_by_name (dynobj, ".dynrel");
2512 BFD_ASSERT (s != NULL);
2513 BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
2514 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2517 s = bfd_get_section_by_name (dynobj, ".hash");
2518 BFD_ASSERT (s != NULL);
2519 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2522 s = bfd_get_section_by_name (dynobj, ".dynsym");
2523 BFD_ASSERT (s != NULL);
2524 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2527 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
2529 PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
2532 s = bfd_get_section_by_name (dynobj, ".dynstr");
2533 BFD_ASSERT (s != NULL);
2534 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2536 PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
2538 /* The size of the text area is the size of the .text section
2539 rounded up to a page boundary. FIXME: Should the page size be
2540 conditional on something? */
2542 BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
2545 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
2546 (sdyn->output_offset
2548 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2552 abfd->flags |= DYNAMIC;