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 long sunos_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **));
33 static long sunos_get_dynamic_reloc_upper_bound PARAMS ((bfd *));
34 static long sunos_canonicalize_dynamic_reloc
35 PARAMS ((bfd *, arelent **, asymbol **));
36 static struct bfd_hash_entry *sunos_link_hash_newfunc
37 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
38 static struct bfd_link_hash_table *sunos_link_hash_table_create
40 static boolean sunos_create_dynamic_sections
41 PARAMS ((bfd *, struct bfd_link_info *, boolean));
42 static boolean sunos_add_dynamic_symbols
43 PARAMS ((bfd *, struct bfd_link_info *));
44 static boolean sunos_add_one_symbol
45 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
46 bfd_vma, const char *, boolean, boolean,
47 struct bfd_link_hash_entry **));
48 static boolean sunos_scan_relocs
49 PARAMS ((struct bfd_link_info *, bfd *, asection *, bfd_size_type));
50 static boolean sunos_scan_std_relocs
51 PARAMS ((struct bfd_link_info *, bfd *, asection *,
52 const struct reloc_std_external *, bfd_size_type));
53 static boolean sunos_scan_ext_relocs
54 PARAMS ((struct bfd_link_info *, bfd *, asection *,
55 const struct reloc_ext_external *, bfd_size_type));
56 static boolean sunos_link_dynamic_object
57 PARAMS ((struct bfd_link_info *, bfd *));
58 static boolean sunos_write_dynamic_symbol
59 PARAMS ((bfd *, struct bfd_link_info *, struct aout_link_hash_entry *));
60 static boolean sunos_check_dynamic_reloc
61 PARAMS ((struct bfd_link_info *, bfd *, asection *,
62 struct aout_link_hash_entry *, PTR, bfd_byte *, boolean *,
64 static boolean sunos_finish_dynamic_link
65 PARAMS ((bfd *, struct bfd_link_info *));
67 #define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound
68 #define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab
69 #define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound
70 #define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc
71 #define MY_bfd_link_hash_table_create sunos_link_hash_table_create
72 #define MY_add_dynamic_symbols sunos_add_dynamic_symbols
73 #define MY_add_one_symbol sunos_add_one_symbol
74 #define MY_link_dynamic_object sunos_link_dynamic_object
75 #define MY_write_dynamic_symbol sunos_write_dynamic_symbol
76 #define MY_check_dynamic_reloc sunos_check_dynamic_reloc
77 #define MY_finish_dynamic_link sunos_finish_dynamic_link
79 /* Include the usual a.out support. */
82 /* SunOS shared library support. We store a pointer to this structure
83 in obj_aout_dynamic_info (abfd). */
85 struct sunos_dynamic_info
87 /* Whether we found any dynamic information. */
89 /* Dynamic information. */
90 struct internal_sun4_dynamic_link dyninfo;
91 /* Number of dynamic symbols. */
92 unsigned long dynsym_count;
93 /* Read in nlists for dynamic symbols. */
94 struct external_nlist *dynsym;
95 /* asymbol structures for dynamic symbols. */
96 aout_symbol_type *canonical_dynsym;
97 /* Read in dynamic string table. */
99 /* Number of dynamic relocs. */
100 unsigned long dynrel_count;
101 /* Read in dynamic relocs. This may be reloc_std_external or
102 reloc_ext_external. */
104 /* arelent structures for dynamic relocs. */
105 arelent *canonical_dynrel;
108 /* The hash table of dynamic symbols is composed of two word entries.
109 See include/aout/sun4.h for details. */
111 #define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
113 /* Read in the basic dynamic information. This locates the __DYNAMIC
114 structure and uses it to find the dynamic_link structure. It
115 creates and saves a sunos_dynamic_info structure. If it can't find
116 __DYNAMIC, it sets the valid field of the sunos_dynamic_info
117 structure to false to avoid doing this work again. */
120 sunos_read_dynamic_info (abfd)
123 struct sunos_dynamic_info *info;
126 struct external_sun4_dynamic dyninfo;
127 unsigned long dynver;
128 struct external_sun4_dynamic_link linkinfo;
130 if (obj_aout_dynamic_info (abfd) != (PTR) NULL)
133 if ((abfd->flags & DYNAMIC) == 0)
135 bfd_set_error (bfd_error_invalid_operation);
139 info = ((struct sunos_dynamic_info *)
140 bfd_zalloc (abfd, sizeof (struct sunos_dynamic_info)));
143 bfd_set_error (bfd_error_no_memory);
149 info->canonical_dynsym = NULL;
151 info->canonical_dynrel = NULL;
152 obj_aout_dynamic_info (abfd) = (PTR) info;
154 /* This code used to look for the __DYNAMIC symbol to locate the dynamic
156 However this inhibits recovering the dynamic symbols from a
157 stripped object file, so blindly assume that the dynamic linking
158 information is located at the start of the data section.
159 We could verify this assumption later by looking through the dynamic
160 symbols for the __DYNAMIC symbol. */
161 if ((abfd->flags & DYNAMIC) == 0)
163 if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (PTR) &dyninfo,
164 (file_ptr) 0, sizeof dyninfo))
167 dynver = GET_WORD (abfd, dyninfo.ld_version);
168 if (dynver != 2 && dynver != 3)
171 dynoff = GET_WORD (abfd, dyninfo.ld);
173 /* dynoff is a virtual address. It is probably always in the .data
174 section, but this code should work even if it moves. */
175 if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
176 dynsec = obj_textsec (abfd);
178 dynsec = obj_datasec (abfd);
179 dynoff -= bfd_get_section_vma (abfd, dynsec);
180 if (dynoff > bfd_section_size (abfd, dynsec))
183 /* This executable appears to be dynamically linked in a way that we
185 if (! bfd_get_section_contents (abfd, dynsec, (PTR) &linkinfo, dynoff,
186 (bfd_size_type) sizeof linkinfo))
189 /* Swap in the dynamic link information. */
190 info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
191 info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
192 info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
193 info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
194 info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
195 info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
196 info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
197 info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
198 info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
199 info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
200 info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
201 info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
202 info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
203 info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
205 /* The only way to get the size of the symbol information appears to
206 be to determine the distance between it and the string table. */
207 info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
208 / EXTERNAL_NLIST_SIZE);
209 BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
210 == (unsigned long) (info->dyninfo.ld_symbols
211 - info->dyninfo.ld_stab));
213 /* Similarly, the relocs end at the hash table. */
214 info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
215 / obj_reloc_entry_size (abfd));
216 BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
217 == (unsigned long) (info->dyninfo.ld_hash
218 - info->dyninfo.ld_rel));
225 /* Return the amount of memory required for the dynamic symbols. */
228 sunos_get_dynamic_symtab_upper_bound (abfd)
231 struct sunos_dynamic_info *info;
233 if (! sunos_read_dynamic_info (abfd))
236 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
239 bfd_set_error (bfd_error_no_symbols);
243 return (info->dynsym_count + 1) * sizeof (asymbol *);
246 /* Read in the dynamic symbols. */
249 sunos_canonicalize_dynamic_symtab (abfd, storage)
253 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);
319 #ifdef CHECK_DYNAMIC_HASH
320 /* Check my understanding of the dynamic hash table by making sure
321 that each symbol can be located in the hash table. */
323 bfd_size_type table_size;
327 if (info->dyninfo.ld_buckets > info->dynsym_count)
329 table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
330 table = (bfd_byte *) malloc (table_size);
331 if (table == NULL && table_size != 0)
333 if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
334 || bfd_read ((PTR) table, 1, table_size, abfd) != table_size)
336 for (i = 0; i < info->dynsym_count; i++)
341 name = ((unsigned char *) info->dynstr
342 + GET_WORD (abfd, info->dynsym[i].e_strx));
344 while (*name != '\0')
345 hash = (hash << 1) + *name++;
347 hash %= info->dyninfo.ld_buckets;
348 while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
350 hash = GET_WORD (abfd,
351 table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
352 if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
358 #endif /* CHECK_DYNAMIC_HASH */
360 /* Get the asymbol structures corresponding to the dynamic nlist
362 if (info->canonical_dynsym == (aout_symbol_type *) NULL)
364 info->canonical_dynsym = ((aout_symbol_type *)
367 * sizeof (aout_symbol_type))));
368 if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
370 bfd_set_error (bfd_error_no_memory);
374 if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
375 info->dynsym, info->dynsym_count,
377 info->dyninfo.ld_symb_size,
380 if (info->canonical_dynsym != NULL)
382 bfd_release (abfd, info->canonical_dynsym);
383 info->canonical_dynsym = NULL;
389 /* Return pointers to the dynamic asymbol structures. */
390 for (i = 0; i < info->dynsym_count; i++)
391 *storage++ = (asymbol *) (info->canonical_dynsym + i);
394 return info->dynsym_count;
397 /* Return the amount of memory required for the dynamic relocs. */
400 sunos_get_dynamic_reloc_upper_bound (abfd)
403 struct sunos_dynamic_info *info;
405 if (! sunos_read_dynamic_info (abfd))
408 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
411 bfd_set_error (bfd_error_no_symbols);
415 return (info->dynrel_count + 1) * sizeof (arelent *);
418 /* Read in the dynamic relocs. */
421 sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
426 struct sunos_dynamic_info *info;
429 /* Get the general dynamic information. */
430 if (obj_aout_dynamic_info (abfd) == (PTR) NULL)
432 if (! sunos_read_dynamic_info (abfd))
436 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
439 bfd_set_error (bfd_error_no_symbols);
443 /* Get the dynamic reloc information. */
444 if (info->dynrel == NULL)
446 info->dynrel = (PTR) bfd_alloc (abfd,
448 * obj_reloc_entry_size (abfd)));
449 if (info->dynrel == NULL && info->dynrel_count != 0)
451 bfd_set_error (bfd_error_no_memory);
454 if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
455 || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
456 obj_reloc_entry_size (abfd), abfd)
457 != info->dynrel_count * obj_reloc_entry_size (abfd)))
459 if (info->dynrel != NULL)
461 bfd_release (abfd, info->dynrel);
468 /* Get the arelent structures corresponding to the dynamic reloc
470 if (info->canonical_dynrel == (arelent *) NULL)
474 info->canonical_dynrel = ((arelent *)
477 * sizeof (arelent))));
478 if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
480 bfd_set_error (bfd_error_no_memory);
484 to = info->canonical_dynrel;
486 if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
488 register struct reloc_ext_external *p;
489 struct reloc_ext_external *pend;
491 p = (struct reloc_ext_external *) info->dynrel;
492 pend = p + info->dynrel_count;
493 for (; p < pend; p++, to++)
494 NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms,
499 register struct reloc_std_external *p;
500 struct reloc_std_external *pend;
502 p = (struct reloc_std_external *) info->dynrel;
503 pend = p + info->dynrel_count;
504 for (; p < pend; p++, to++)
505 NAME(aout,swap_std_reloc_in) (abfd, p, to, syms,
510 /* Return pointers to the dynamic arelent structures. */
511 for (i = 0; i < info->dynrel_count; i++)
512 *storage++ = info->canonical_dynrel + i;
515 return info->dynrel_count;
518 /* Code to handle linking of SunOS shared libraries. */
520 /* A SPARC procedure linkage table entry is 12 bytes. The first entry
521 in the table is a jump which is filled in by the runtime linker.
522 The remaining entries are branches back to the first entry,
523 followed by an index into the relocation table encoded to look like
526 #define SPARC_PLT_ENTRY_SIZE (12)
528 static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
530 /* sethi %hi(0),%g1; address filled in by runtime linker. */
532 /* jmp %g1; offset filled in by runtime linker. */
538 /* save %sp, -96, %sp */
539 #define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0
540 /* call; address filled in later. */
541 #define SPARC_PLT_ENTRY_WORD1 0x40000000
542 /* sethi; reloc index filled in later. */
543 #define SPARC_PLT_ENTRY_WORD2 0x01000000
545 /* This sequence is used when for the jump table entry to a defined
546 symbol in a complete executable. It is used when linking PIC
547 compiled code which is not being put into a shared library. */
548 /* sethi <address to be filled in later>, %g1 */
549 #define SPARC_PLT_PIC_WORD0 0x03000000
550 /* jmp %g1 + <address to be filled in later> */
551 #define SPARC_PLT_PIC_WORD1 0x81c06000
553 #define SPARC_PLT_PIC_WORD2 0x01000000
555 /* An m68k procedure linkage table entry is 8 bytes. The first entry
556 in the table is a jump which is filled in the by the runtime
557 linker. The remaining entries are branches back to the first
558 entry, followed by a two byte index into the relocation table. */
560 #define M68K_PLT_ENTRY_SIZE (8)
562 static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
566 /* Filled in by runtime linker with a magic address. */
573 #define M68K_PLT_ENTRY_WORD0 (0x61ff)
574 /* Remaining words filled in later. */
576 /* An entry in the SunOS linker hash table. */
578 struct sunos_link_hash_entry
580 struct aout_link_hash_entry root;
582 /* If this is a dynamic symbol, this is its index into the dynamic
583 symbol table. This is initialized to -1. As the linker looks at
584 the input files, it changes this to -2 if it will be added to the
585 dynamic symbol table. After all the input files have been seen,
586 the linker will know whether to build a dynamic symbol table; if
587 it does build one, this becomes the index into the table. */
590 /* If this is a dynamic symbol, this is the index of the name in the
591 dynamic symbol string table. */
594 /* The offset into the global offset table used for this symbol. If
595 the symbol does not require a GOT entry, this is 0. */
598 /* The offset into the procedure linkage table used for this symbol.
599 If the symbol does not require a PLT entry, this is 0. */
602 /* Some linker flags. */
604 /* Symbol is referenced by a regular object. */
605 #define SUNOS_REF_REGULAR 01
606 /* Symbol is defined by a regular object. */
607 #define SUNOS_DEF_REGULAR 02
608 /* Symbol is referenced by a dynamic object. */
609 #define SUNOS_REF_DYNAMIC 010
610 /* Symbol is defined by a dynamic object. */
611 #define SUNOS_DEF_DYNAMIC 020
614 /* The SunOS linker hash table. */
616 struct sunos_link_hash_table
618 struct aout_link_hash_table root;
620 /* The object which holds the dynamic sections. */
623 /* Whether we have created the dynamic sections. */
624 boolean dynamic_sections_created;
626 /* Whether we need the dynamic sections. */
627 boolean dynamic_sections_needed;
629 /* The number of dynamic symbols. */
632 /* The number of buckets in the hash table. */
636 /* Routine to create an entry in an SunOS link hash table. */
638 static struct bfd_hash_entry *
639 sunos_link_hash_newfunc (entry, table, string)
640 struct bfd_hash_entry *entry;
641 struct bfd_hash_table *table;
644 struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
646 /* Allocate the structure if it has not already been allocated by a
648 if (ret == (struct sunos_link_hash_entry *) NULL)
649 ret = ((struct sunos_link_hash_entry *)
650 bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry)));
651 if (ret == (struct sunos_link_hash_entry *) NULL)
653 bfd_set_error (bfd_error_no_memory);
654 return (struct bfd_hash_entry *) ret;
657 /* Call the allocation method of the superclass. */
658 ret = ((struct sunos_link_hash_entry *)
659 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
663 /* Set local fields. */
665 ret->dynstr_index = -1;
671 return (struct bfd_hash_entry *) ret;
674 /* Create a SunOS link hash table. */
676 static struct bfd_link_hash_table *
677 sunos_link_hash_table_create (abfd)
680 struct sunos_link_hash_table *ret;
682 ret = ((struct sunos_link_hash_table *)
683 bfd_alloc (abfd, sizeof (struct sunos_link_hash_table)));
684 if (ret == (struct sunos_link_hash_table *) NULL)
686 bfd_set_error (bfd_error_no_memory);
687 return (struct bfd_link_hash_table *) NULL;
689 if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
690 sunos_link_hash_newfunc))
693 return (struct bfd_link_hash_table *) NULL;
697 ret->dynamic_sections_created = false;
698 ret->dynamic_sections_needed = false;
699 ret->dynsymcount = 0;
700 ret->bucketcount = 0;
702 return &ret->root.root;
705 /* Look up an entry in an SunOS link hash table. */
707 #define sunos_link_hash_lookup(table, string, create, copy, follow) \
708 ((struct sunos_link_hash_entry *) \
709 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
712 /* Traverse a SunOS link hash table. */
714 #define sunos_link_hash_traverse(table, func, info) \
715 (aout_link_hash_traverse \
717 (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
720 /* Get the SunOS link hash table from the info structure. This is
723 #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
725 static boolean sunos_scan_dynamic_symbol
726 PARAMS ((struct sunos_link_hash_entry *, PTR));
728 /* Create the dynamic sections needed if we are linking against a
729 dynamic object, or if we are linking PIC compiled code. ABFD is a
730 bfd we can attach the dynamic sections to. The linker script will
731 look for these special sections names and put them in the right
732 place in the output file. See include/aout/sun4.h for more details
733 of the dynamic linking information. */
736 sunos_create_dynamic_sections (abfd, info, needed)
738 struct bfd_link_info *info;
743 if (! sunos_hash_table (info)->dynamic_sections_created)
747 sunos_hash_table (info)->dynobj = abfd;
749 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
751 /* The .dynamic section holds the basic dynamic information: the
752 sun4_dynamic structure, the dynamic debugger information, and
753 the sun4_dynamic_link structure. */
754 s = bfd_make_section (abfd, ".dynamic");
756 || ! bfd_set_section_flags (abfd, s, flags)
757 || ! bfd_set_section_alignment (abfd, s, 2))
760 /* The .got section holds the global offset table. The address
761 is put in the ld_got field. */
762 s = bfd_make_section (abfd, ".got");
764 || ! bfd_set_section_flags (abfd, s, flags)
765 || ! bfd_set_section_alignment (abfd, s, 2))
768 /* The .plt section holds the procedure linkage table. The
769 address is put in the ld_plt field. */
770 s = bfd_make_section (abfd, ".plt");
772 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
773 || ! bfd_set_section_alignment (abfd, s, 2))
776 /* The .dynrel section holds the dynamic relocs. The address is
777 put in the ld_rel field. */
778 s = bfd_make_section (abfd, ".dynrel");
780 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
781 || ! bfd_set_section_alignment (abfd, s, 2))
784 /* The .hash section holds the dynamic hash table. The address
785 is put in the ld_hash field. */
786 s = bfd_make_section (abfd, ".hash");
788 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
789 || ! bfd_set_section_alignment (abfd, s, 2))
792 /* The .dynsym section holds the dynamic symbols. The address
793 is put in the ld_stab field. */
794 s = bfd_make_section (abfd, ".dynsym");
796 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
797 || ! bfd_set_section_alignment (abfd, s, 2))
800 /* The .dynstr section holds the dynamic symbol string table.
801 The address is put in the ld_symbols field. */
802 s = bfd_make_section (abfd, ".dynstr");
804 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
805 || ! bfd_set_section_alignment (abfd, s, 2))
808 sunos_hash_table (info)->dynamic_sections_created = true;
811 if (needed && ! sunos_hash_table (info)->dynamic_sections_needed)
815 dynobj = sunos_hash_table (info)->dynobj;
817 s = bfd_get_section_by_name (dynobj, ".got");
818 s->_raw_size = BYTES_IN_WORD;
820 sunos_hash_table (info)->dynamic_sections_needed = true;
826 /* Add dynamic symbols during a link. This is called by the a.out
827 backend linker when it encounters an object with the DYNAMIC flag
831 sunos_add_dynamic_symbols (abfd, info)
833 struct bfd_link_info *info;
838 /* We do not want to include the sections in a dynamic object in the
839 output file. We hack by simply clobbering the list of sections
840 in the BFD. This could be handled more cleanly by, say, a new
841 section flag; the existing SEC_NEVER_LOAD flag is not the one we
842 want, because that one still implies that the section takes up
843 space in the output file. */
844 abfd->sections = NULL;
846 /* The native linker seems to just ignore dynamic objects when -r is
848 if (info->relocateable)
851 /* There's no hope of using a dynamic object which does not exactly
852 match the format of the output file. */
853 if (info->hash->creator != abfd->xvec)
855 bfd_set_error (bfd_error_invalid_operation);
859 /* Make sure we have all the required information. */
860 if (! sunos_create_dynamic_sections (abfd, info, true))
863 /* Make sure we have a .need and a .rules sections. These are only
864 needed if there really is a dynamic object in the link, so they
865 are not added by sunos_create_dynamic_sections. */
866 dynobj = sunos_hash_table (info)->dynobj;
867 if (bfd_get_section_by_name (dynobj, ".need") == NULL)
869 /* The .need section holds the list of names of shared objets
870 which must be included at runtime. The address of this
871 section is put in the ld_need field. */
872 s = bfd_make_section (dynobj, ".need");
874 || ! bfd_set_section_flags (dynobj, s,
880 || ! bfd_set_section_alignment (dynobj, s, 2))
884 if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
886 /* The .rules section holds the path to search for shared
887 objects. The address of this section is put in the ld_rules
889 s = bfd_make_section (dynobj, ".rules");
891 || ! bfd_set_section_flags (dynobj, s,
897 || ! bfd_set_section_alignment (dynobj, s, 2))
904 /* Function to add a single symbol to the linker hash table. This is
905 a wrapper around _bfd_generic_link_add_one_symbol which handles the
906 tweaking needed for dynamic linking support. */
909 sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
910 copy, collect, hashp)
911 struct bfd_link_info *info;
920 struct bfd_link_hash_entry **hashp;
922 struct sunos_link_hash_entry *h;
925 if (! sunos_hash_table (info)->dynamic_sections_created)
927 /* We must create the dynamic sections while reading the input
928 files, even though at this point we don't know if any of the
929 sections will be needed. This will ensure that the dynamic
930 sections are mapped to the right output section. It does no
931 harm to create these sections if they are not needed. */
932 if (! sunos_create_dynamic_sections (abfd, info, info->shared))
936 h = sunos_link_hash_lookup (sunos_hash_table (info), name, true, copy,
942 *hashp = (struct bfd_link_hash_entry *) h;
944 /* Treat a common symbol in a dynamic object as defined in the .bss
945 section of the dynamic object. We don't want to allocate space
946 for it in our process image. */
947 if ((abfd->flags & DYNAMIC) != 0
948 && bfd_is_com_section (section))
949 section = obj_bsssec (abfd);
951 if (! bfd_is_und_section (section)
952 && h->root.root.type != bfd_link_hash_new
953 && h->root.root.type != bfd_link_hash_undefined
954 && h->root.root.type != bfd_link_hash_defweak)
956 /* We are defining the symbol, and it is already defined. This
957 is a potential multiple definition error. */
958 if ((abfd->flags & DYNAMIC) != 0)
960 /* The definition we are adding is from a dynamic object.
961 We do not want this new definition to override the
962 existing definition, so we pretend it is just a
964 section = bfd_und_section_ptr;
966 else if ((h->root.root.type == bfd_link_hash_defined
967 && h->root.root.u.def.section->owner != NULL
968 && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
969 || (h->root.root.type == bfd_link_hash_common
970 && ((h->root.root.u.c.p->section->owner->flags & DYNAMIC)
973 /* The existing definition is from a dynamic object. We
974 want to override it with the definition we just found.
975 Clobber the existing definition. */
976 h->root.root.type = bfd_link_hash_new;
980 /* Do the usual procedure for adding a symbol. */
981 if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
982 value, string, copy, collect,
986 if (abfd->xvec == info->hash->creator)
988 /* Set a flag in the hash table entry indicating the type of
989 reference or definition we just found. Keep a count of the
990 number of dynamic symbols we find. A dynamic symbol is one
991 which is referenced or defined by both a regular object and a
993 if ((abfd->flags & DYNAMIC) == 0)
995 if (bfd_is_und_section (section))
996 new_flag = SUNOS_REF_REGULAR;
998 new_flag = SUNOS_DEF_REGULAR;
1002 if (bfd_is_und_section (section))
1003 new_flag = SUNOS_REF_DYNAMIC;
1005 new_flag = SUNOS_DEF_DYNAMIC;
1007 h->flags |= new_flag;
1009 if (h->dynindx == -1
1010 && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1012 ++sunos_hash_table (info)->dynsymcount;
1020 /* Record an assignment made to a symbol by a linker script. We need
1021 this in case some dynamic object refers to this symbol. */
1024 bfd_sunos_record_link_assignment (output_bfd, info, name)
1026 struct bfd_link_info *info;
1029 struct sunos_link_hash_entry *h;
1031 /* This is called after we have examined all the input objects. If
1032 the symbol does not exist, it merely means that no object refers
1033 to it, and we can just ignore it at this point. */
1034 h = sunos_link_hash_lookup (sunos_hash_table (info), name,
1035 false, false, false);
1039 h->flags |= SUNOS_DEF_REGULAR;
1041 if (h->dynindx == -1)
1043 ++sunos_hash_table (info)->dynsymcount;
1050 /* Set up the sizes and contents of the dynamic sections created in
1051 sunos_add_dynamic_symbols. This is called by the SunOS linker
1052 emulation before_allocation routine. We must set the sizes of the
1053 sections before the linker sets the addresses of the various
1054 sections. This unfortunately requires reading all the relocs so
1055 that we can work out which ones need to become dynamic relocs. If
1056 info->keep_memory is true, we keep the relocs in memory; otherwise,
1057 we discard them, and will read them again later. */
1060 bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
1063 struct bfd_link_info *info;
1065 asection **sneedptr;
1066 asection **srulesptr;
1070 struct sunos_link_hash_entry *h;
1081 /* Look through all the input BFD's and read their relocs. It would
1082 be better if we didn't have to do this, but there is no other way
1083 to determine the number of dynamic relocs we need, and, more
1084 importantly, there is no other way to know which symbols should
1085 get an entry in the procedure linkage table. */
1086 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
1088 if ((sub->flags & DYNAMIC) == 0)
1090 if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
1091 exec_hdr (sub)->a_trsize)
1092 || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
1093 exec_hdr (sub)->a_drsize))
1098 dynobj = sunos_hash_table (info)->dynobj;
1099 dynsymcount = sunos_hash_table (info)->dynsymcount;
1101 /* If there were no dynamic objects in the link, and we don't need
1102 to build a global offset table, there is nothing to do here. */
1103 if (! sunos_hash_table (info)->dynamic_sections_needed)
1106 /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it. */
1107 h = sunos_link_hash_lookup (sunos_hash_table (info),
1108 "__GLOBAL_OFFSET_TABLE_", false, false, false);
1109 if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
1111 h->flags |= SUNOS_DEF_REGULAR;
1112 if (h->dynindx == -1)
1114 ++sunos_hash_table (info)->dynsymcount;
1117 h->root.root.type = bfd_link_hash_defined;
1118 h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
1119 h->root.root.u.def.value = 0;
1122 /* The .dynamic section is always the same size. */
1123 s = bfd_get_section_by_name (dynobj, ".dynamic");
1124 BFD_ASSERT (s != NULL);
1125 s->_raw_size = (sizeof (struct external_sun4_dynamic)
1126 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
1127 + sizeof (struct external_sun4_dynamic_link));
1129 /* Set the size of the .dynsym and .hash sections. We counted the
1130 number of dynamic symbols as we read the input files. We will
1131 build the dynamic symbol table (.dynsym) and the hash table
1132 (.hash) when we build the final symbol table, because until then
1133 we do not know the correct value to give the symbols. We build
1134 the dynamic symbol string table (.dynstr) in a traversal of the
1135 symbol table using sunos_scan_dynamic_symbol. */
1136 s = bfd_get_section_by_name (dynobj, ".dynsym");
1137 BFD_ASSERT (s != NULL);
1138 s->_raw_size = dynsymcount * sizeof (struct external_nlist);
1139 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
1140 if (s->contents == NULL && s->_raw_size != 0)
1142 bfd_set_error (bfd_error_no_memory);
1146 /* The number of buckets is just the number of symbols divided by
1147 four. To compute the final size of the hash table, we must
1148 actually compute the hash table. Normally we need exactly as
1149 many entries in the hash table as there are dynamic symbols, but
1150 if some of the buckets are not used we will need additional
1151 entries. In the worst case, every symbol will hash to the same
1152 bucket, and we will need BUCKETCOUNT - 1 extra entries. */
1153 if (dynsymcount >= 4)
1154 bucketcount = dynsymcount / 4;
1155 else if (dynsymcount > 0)
1156 bucketcount = dynsymcount;
1159 s = bfd_get_section_by_name (dynobj, ".hash");
1160 BFD_ASSERT (s != NULL);
1161 hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
1162 s->contents = (bfd_byte *) bfd_alloc (dynobj, hashalloc);
1163 if (s->contents == NULL && dynsymcount > 0)
1165 bfd_set_error (bfd_error_no_memory);
1168 memset (s->contents, 0, hashalloc);
1169 for (i = 0; i < bucketcount; i++)
1170 PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
1171 s->_raw_size = bucketcount * HASH_ENTRY_SIZE;
1173 sunos_hash_table (info)->bucketcount = bucketcount;
1175 /* Scan all the symbols, place them in the dynamic symbol table, and
1176 build the dynamic hash table. We reuse dynsymcount as a counter
1177 for the number of symbols we have added so far. */
1178 sunos_hash_table (info)->dynsymcount = 0;
1179 sunos_link_hash_traverse (sunos_hash_table (info),
1180 sunos_scan_dynamic_symbol,
1182 BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
1184 /* The SunOS native linker seems to align the total size of the
1185 symbol strings to a multiple of 8. I don't know if this is
1186 important, but it can't hurt much. */
1187 s = bfd_get_section_by_name (dynobj, ".dynstr");
1188 BFD_ASSERT (s != NULL);
1189 if ((s->_raw_size & 7) != 0)
1194 add = 8 - (s->_raw_size & 7);
1195 contents = (bfd_byte *) realloc (s->contents,
1196 (size_t) (s->_raw_size + add));
1197 if (contents == NULL)
1199 bfd_set_error (bfd_error_no_memory);
1202 memset (contents + s->_raw_size, 0, (size_t) add);
1203 s->contents = contents;
1204 s->_raw_size += add;
1207 /* Now that we have worked out the sizes of the procedure linkage
1208 table and the dynamic relocs, allocate storage for them. */
1209 s = bfd_get_section_by_name (dynobj, ".plt");
1210 BFD_ASSERT (s != NULL);
1211 if (s->_raw_size != 0)
1213 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1214 if (s->contents == NULL)
1216 bfd_set_error (bfd_error_no_memory);
1220 /* Fill in the first entry in the table. */
1221 switch (bfd_get_arch (dynobj))
1223 case bfd_arch_sparc:
1224 memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
1228 memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
1236 s = bfd_get_section_by_name (dynobj, ".dynrel");
1237 if (s->_raw_size != 0)
1239 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1240 if (s->contents == NULL)
1242 bfd_set_error (bfd_error_no_memory);
1246 /* We use the reloc_count field to keep track of how many of the
1247 relocs we have output so far. */
1250 /* Make space for the global offset table. */
1251 s = bfd_get_section_by_name (dynobj, ".got");
1252 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1253 if (s->contents == NULL)
1255 bfd_set_error (bfd_error_no_memory);
1259 *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
1260 *sneedptr = bfd_get_section_by_name (dynobj, ".need");
1261 *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
1266 /* Scan the relocs for an input section. */
1269 sunos_scan_relocs (info, abfd, sec, rel_size)
1270 struct bfd_link_info *info;
1273 bfd_size_type rel_size;
1276 PTR free_relocs = NULL;
1281 if (! info->keep_memory)
1282 relocs = free_relocs = malloc ((size_t) rel_size);
1285 struct aout_section_data_struct *n;
1287 n = ((struct aout_section_data_struct *)
1288 bfd_alloc (abfd, sizeof (struct aout_section_data_struct)));
1293 set_aout_section_data (sec, n);
1294 relocs = malloc ((size_t) rel_size);
1295 aout_section_data (sec)->relocs = relocs;
1300 bfd_set_error (bfd_error_no_memory);
1304 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
1305 || bfd_read (relocs, 1, rel_size, abfd) != rel_size)
1308 if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
1310 if (! sunos_scan_std_relocs (info, abfd, sec,
1311 (struct reloc_std_external *) relocs,
1317 if (! sunos_scan_ext_relocs (info, abfd, sec,
1318 (struct reloc_ext_external *) relocs,
1323 if (free_relocs != NULL)
1329 if (free_relocs != NULL)
1334 /* Scan the relocs for an input section using standard relocs. We
1335 need to figure out what to do for each reloc against a dynamic
1336 symbol. If the symbol is in the .text section, an entry is made in
1337 the procedure linkage table. Note that this will do the wrong
1338 thing if the symbol is actually data; I don't think the Sun 3
1339 native linker handles this case correctly either. If the symbol is
1340 not in the .text section, we must preserve the reloc as a dynamic
1341 reloc. FIXME: We should also handle the PIC relocs here by
1342 building global offset table entries. */
1345 sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
1346 struct bfd_link_info *info;
1349 const struct reloc_std_external *relocs;
1350 bfd_size_type rel_size;
1353 asection *splt = NULL;
1354 asection *srel = NULL;
1355 struct sunos_link_hash_entry **sym_hashes;
1356 const struct reloc_std_external *rel, *relend;
1358 /* We only know how to handle m68k plt entries. */
1359 if (bfd_get_arch (abfd) != bfd_arch_m68k)
1361 bfd_set_error (bfd_error_invalid_target);
1367 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1369 relend = relocs + rel_size / RELOC_STD_SIZE;
1370 for (rel = relocs; rel < relend; rel++)
1373 struct sunos_link_hash_entry *h;
1375 /* We only want relocs against external symbols. */
1376 if (abfd->xvec->header_byteorder_big_p)
1378 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
1383 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
1387 /* Get the symbol index. */
1388 if (abfd->xvec->header_byteorder_big_p)
1389 r_index = ((rel->r_index[0] << 16)
1390 | (rel->r_index[1] << 8)
1393 r_index = ((rel->r_index[2] << 16)
1394 | (rel->r_index[1] << 8)
1397 /* Get the hash table entry. */
1398 h = sym_hashes[r_index];
1401 /* This should not normally happen, but it will in any case
1402 be caught in the relocation phase. */
1406 /* At this point common symbols have already been allocated, so
1407 we don't have to worry about them. We need to consider that
1408 we may have already seen this symbol and marked it undefined;
1409 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1411 if (h->root.root.type != bfd_link_hash_defined
1412 && h->root.root.type != bfd_link_hash_defweak
1413 && h->root.root.type != bfd_link_hash_undefined)
1416 if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1417 || (h->flags & SUNOS_DEF_REGULAR) != 0)
1422 if (! sunos_create_dynamic_sections (abfd, info, true))
1424 dynobj = sunos_hash_table (info)->dynobj;
1425 splt = bfd_get_section_by_name (dynobj, ".plt");
1426 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1427 BFD_ASSERT (splt != NULL && srel != NULL);
1430 BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
1431 BFD_ASSERT (h->plt_offset != 0
1432 || ((h->root.root.type == bfd_link_hash_defined
1433 || h->root.root.type == bfd_link_hash_defweak)
1434 ? (h->root.root.u.def.section->owner->flags
1436 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1438 /* This reloc is against a symbol defined only by a dynamic
1441 if (h->root.root.type == bfd_link_hash_undefined)
1443 /* Presumably this symbol was marked as being undefined by
1444 an earlier reloc. */
1445 srel->_raw_size += RELOC_STD_SIZE;
1447 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1451 /* This reloc is not in the .text section. It must be
1452 copied into the dynamic relocs. We mark the symbol as
1454 srel->_raw_size += RELOC_STD_SIZE;
1455 sub = h->root.root.u.def.section->owner;
1456 h->root.root.type = bfd_link_hash_undefined;
1457 h->root.root.u.undef.abfd = sub;
1461 /* This symbol is in the .text section. We must give it an
1462 entry in the procedure linkage table, if we have not
1463 already done so. We change the definition of the symbol
1464 to the .plt section; this will cause relocs against it to
1465 be handled correctly. */
1466 if (h->plt_offset == 0)
1468 if (splt->_raw_size == 0)
1469 splt->_raw_size = M68K_PLT_ENTRY_SIZE;
1470 h->plt_offset = splt->_raw_size;
1472 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1474 h->root.root.u.def.section = splt;
1475 h->root.root.u.def.value = splt->_raw_size;
1478 splt->_raw_size += M68K_PLT_ENTRY_SIZE;
1480 /* We may also need a dynamic reloc entry. */
1481 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1482 srel->_raw_size += RELOC_STD_SIZE;
1490 /* Scan the relocs for an input section using extended relocs. We
1491 need to figure out what to do for each reloc against a dynamic
1492 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1493 section, an entry is made in the procedure linkage table.
1494 Otherwise, we must preserve the reloc as a dynamic reloc. */
1497 sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
1498 struct bfd_link_info *info;
1501 const struct reloc_ext_external *relocs;
1502 bfd_size_type rel_size;
1505 struct sunos_link_hash_entry **sym_hashes;
1506 const struct reloc_ext_external *rel, *relend;
1507 asection *splt = NULL;
1508 asection *sgot = NULL;
1509 asection *srel = NULL;
1511 /* We only know how to handle SPARC plt entries. */
1512 if (bfd_get_arch (abfd) != bfd_arch_sparc)
1514 bfd_set_error (bfd_error_invalid_target);
1520 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1522 relend = relocs + rel_size / RELOC_EXT_SIZE;
1523 for (rel = relocs; rel < relend; rel++)
1525 unsigned int r_index;
1528 struct sunos_link_hash_entry *h = NULL;
1530 /* Swap in the reloc information. */
1531 if (abfd->xvec->header_byteorder_big_p)
1533 r_index = ((rel->r_index[0] << 16)
1534 | (rel->r_index[1] << 8)
1536 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1537 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1538 >> RELOC_EXT_BITS_TYPE_SH_BIG);
1542 r_index = ((rel->r_index[2] << 16)
1543 | (rel->r_index[1] << 8)
1545 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1546 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1547 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
1552 h = sym_hashes[r_index];
1555 /* This should not normally happen, but it will in any
1556 case be caught in the relocation phase. */
1562 if (r_index >= bfd_get_symcount (abfd))
1564 /* This is abnormal, but should be caught in the
1565 relocation phase. */
1570 /* If this is a base relative reloc, we need to make an entry in
1571 the .got section. */
1572 if (r_type == RELOC_BASE10
1573 || r_type == RELOC_BASE13
1574 || r_type == RELOC_BASE22)
1578 if (! sunos_create_dynamic_sections (abfd, info, true))
1580 dynobj = sunos_hash_table (info)->dynobj;
1581 splt = bfd_get_section_by_name (dynobj, ".plt");
1582 sgot = bfd_get_section_by_name (dynobj, ".got");
1583 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1584 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1589 if (h->got_offset != 0)
1592 h->got_offset = sgot->_raw_size;
1596 if (adata (abfd).local_got_offsets == NULL)
1598 adata (abfd).local_got_offsets =
1599 (bfd_vma *) bfd_zalloc (abfd,
1600 (bfd_get_symcount (abfd)
1601 * sizeof (bfd_vma)));
1602 if (adata (abfd).local_got_offsets == NULL)
1604 bfd_set_error (bfd_error_no_memory);
1609 if (adata (abfd).local_got_offsets[r_index] != 0)
1612 adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
1615 sgot->_raw_size += BYTES_IN_WORD;
1617 /* If we are making a shared library, or if the symbol is
1618 defined by a dynamic object, we will need a dynamic reloc
1622 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1623 && (h->flags & SUNOS_DEF_REGULAR) == 0))
1624 srel->_raw_size += RELOC_EXT_SIZE;
1629 /* Otherwise, we are only interested in relocs against symbols
1630 defined in dynamic objects but not in regular objects. We
1631 only need to consider relocs against external symbols. */
1635 /* At this point common symbols have already been allocated, so
1636 we don't have to worry about them. We need to consider that
1637 we may have already seen this symbol and marked it undefined;
1638 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1640 if (h->root.root.type != bfd_link_hash_defined
1641 && h->root.root.type != bfd_link_hash_defweak
1642 && h->root.root.type != bfd_link_hash_undefined)
1645 if (r_type != RELOC_JMP_TBL
1646 && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1647 || (h->flags & SUNOS_DEF_REGULAR) != 0))
1650 if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1655 if (! sunos_create_dynamic_sections (abfd, info, true))
1657 dynobj = sunos_hash_table (info)->dynobj;
1658 splt = bfd_get_section_by_name (dynobj, ".plt");
1659 sgot = bfd_get_section_by_name (dynobj, ".got");
1660 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1661 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1664 BFD_ASSERT (r_type == RELOC_JMP_TBL
1665 || (h->flags & SUNOS_REF_REGULAR) != 0);
1666 BFD_ASSERT (r_type == RELOC_JMP_TBL
1667 || h->plt_offset != 0
1668 || ((h->root.root.type == bfd_link_hash_defined
1669 || h->root.root.type == bfd_link_hash_defweak)
1670 ? (h->root.root.u.def.section->owner->flags
1672 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1674 /* This reloc is against a symbol defined only by a dynamic
1675 object, or it is a jump table reloc from PIC compiled code. */
1677 if (h->root.root.type == bfd_link_hash_undefined)
1679 /* Presumably this symbol was marked as being undefined by
1680 an earlier reloc. */
1681 srel->_raw_size += RELOC_EXT_SIZE;
1683 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1687 /* This reloc is not in the .text section. It must be
1688 copied into the dynamic relocs. We mark the symbol as
1690 BFD_ASSERT (r_type != RELOC_JMP_TBL);
1691 srel->_raw_size += RELOC_EXT_SIZE;
1692 sub = h->root.root.u.def.section->owner;
1693 h->root.root.type = bfd_link_hash_undefined;
1694 h->root.root.u.undef.abfd = sub;
1698 /* This symbol is in the .text section. We must give it an
1699 entry in the procedure linkage table, if we have not
1700 already done so. We change the definition of the symbol
1701 to the .plt section; this will cause relocs against it to
1702 be handled correctly. */
1703 if (h->plt_offset == 0)
1705 if (splt->_raw_size == 0)
1706 splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
1707 h->plt_offset = splt->_raw_size;
1709 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1711 h->root.root.u.def.section = splt;
1712 h->root.root.u.def.value = splt->_raw_size;
1715 splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
1717 /* We will also need a dynamic reloc entry, unless this
1718 is a JMP_TBL reloc produced by linking PIC compiled
1719 code, and we are not making a shared library. */
1720 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1721 srel->_raw_size += RELOC_EXT_SIZE;
1729 /* Build the hash table of dynamic symbols, and to mark as written all
1730 symbols from dynamic objects which we do not plan to write out. */
1733 sunos_scan_dynamic_symbol (h, data)
1734 struct sunos_link_hash_entry *h;
1737 struct bfd_link_info *info = (struct bfd_link_info *) data;
1739 /* Set the written flag for symbols we do not want to write out as
1740 part of the regular symbol table. This is all symbols which are
1741 not defined in a regular object file. For some reason symbols
1742 which are referenced by a regular object and defined by a dynamic
1743 object do not seem to show up in the regular symbol table. */
1744 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1745 h->root.written = true;
1747 /* If this symbol is defined by a dynamic object and referenced by a
1748 regular object, see whether we gave it a reasonable value while
1749 scanning the relocs. */
1751 if ((h->flags & SUNOS_DEF_REGULAR) == 0
1752 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1753 && (h->flags & SUNOS_REF_REGULAR) != 0)
1755 if ((h->root.root.type == bfd_link_hash_defined
1756 || h->root.root.type == bfd_link_hash_defweak)
1757 && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1758 && h->root.root.u.def.section->output_section == NULL)
1762 /* This symbol is currently defined in a dynamic section
1763 which is not being put into the output file. This
1764 implies that there is no reloc against the symbol. I'm
1765 not sure why this case would ever occur. In any case, we
1766 change the symbol to be undefined. */
1767 sub = h->root.root.u.def.section->owner;
1768 h->root.root.type = bfd_link_hash_undefined;
1769 h->root.root.u.undef.abfd = sub;
1773 /* If this symbol is defined or referenced by a regular file, add it
1774 to the dynamic symbols. */
1775 if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1780 unsigned char *name;
1784 BFD_ASSERT (h->dynindx == -2);
1786 dynobj = sunos_hash_table (info)->dynobj;
1788 h->dynindx = sunos_hash_table (info)->dynsymcount;
1789 ++sunos_hash_table (info)->dynsymcount;
1791 len = strlen (h->root.root.root.string);
1793 /* We don't bother to construct a BFD hash table for the strings
1794 which are the names of the dynamic symbols. Using a hash
1795 table for the regular symbols is beneficial, because the
1796 regular symbols includes the debugging symbols, which have
1797 long names and are often duplicated in several object files.
1798 There are no debugging symbols in the dynamic symbols. */
1799 s = bfd_get_section_by_name (dynobj, ".dynstr");
1800 BFD_ASSERT (s != NULL);
1801 if (s->contents == NULL)
1802 contents = (bfd_byte *) malloc (len + 1);
1804 contents = (bfd_byte *) realloc (s->contents,
1805 (size_t) (s->_raw_size + len + 1));
1806 if (contents == NULL)
1808 bfd_set_error (bfd_error_no_memory);
1811 s->contents = contents;
1813 h->dynstr_index = s->_raw_size;
1814 strcpy (contents + s->_raw_size, h->root.root.root.string);
1815 s->_raw_size += len + 1;
1817 /* Add it to the dynamic hash table. */
1818 name = (unsigned char *) h->root.root.root.string;
1820 while (*name != '\0')
1821 hash = (hash << 1) + *name++;
1823 hash %= sunos_hash_table (info)->bucketcount;
1825 s = bfd_get_section_by_name (dynobj, ".hash");
1826 BFD_ASSERT (s != NULL);
1828 if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
1829 PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
1834 next = GET_WORD (dynobj,
1836 + hash * HASH_ENTRY_SIZE
1838 PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
1839 s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
1840 PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
1841 PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
1842 s->_raw_size += HASH_ENTRY_SIZE;
1849 /* Link a dynamic object. We actually don't have anything to do at
1850 this point. This entry point exists to prevent the regular linker
1851 code from doing anything with the object. */
1855 sunos_link_dynamic_object (info, abfd)
1856 struct bfd_link_info *info;
1862 /* Write out a dynamic symbol. This is called by the final traversal
1863 over the symbol table. */
1866 sunos_write_dynamic_symbol (output_bfd, info, harg)
1868 struct bfd_link_info *info;
1869 struct aout_link_hash_entry *harg;
1871 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
1875 struct external_nlist *outsym;
1880 switch (h->root.root.type)
1883 case bfd_link_hash_new:
1885 /* Avoid variable not initialized warnings. */
1887 case bfd_link_hash_undefined:
1888 type = N_UNDF | N_EXT;
1891 case bfd_link_hash_defined:
1892 case bfd_link_hash_defweak:
1895 asection *output_section;
1897 sec = h->root.root.u.def.section;
1898 output_section = sec->output_section;
1899 BFD_ASSERT (bfd_is_abs_section (output_section)
1900 || output_section->owner == output_bfd);
1901 if (h->plt_offset != 0
1902 && (h->flags & SUNOS_DEF_REGULAR) == 0)
1904 type = N_UNDF | N_EXT;
1909 if (output_section == obj_textsec (output_bfd))
1910 type = (h->root.root.type == bfd_link_hash_defined
1913 else if (output_section == obj_datasec (output_bfd))
1914 type = (h->root.root.type == bfd_link_hash_defined
1917 else if (output_section == obj_bsssec (output_bfd))
1918 type = (h->root.root.type == bfd_link_hash_defined
1922 type = (h->root.root.type == bfd_link_hash_defined
1926 val = (h->root.root.u.def.value
1927 + output_section->vma
1928 + sec->output_offset);
1932 case bfd_link_hash_common:
1933 type = N_UNDF | N_EXT;
1934 val = h->root.root.u.c.size;
1936 case bfd_link_hash_undefweak:
1940 case bfd_link_hash_indirect:
1941 case bfd_link_hash_warning:
1942 /* FIXME: Ignore these for now. The circumstances under which
1943 they should be written out are not clear to me. */
1947 s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
1948 BFD_ASSERT (s != NULL);
1949 outsym = ((struct external_nlist *)
1950 (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
1952 bfd_h_put_8 (output_bfd, type, outsym->e_type);
1953 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
1955 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
1956 one less than the desc value in the shared library, although that
1958 bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
1960 PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
1961 PUT_WORD (output_bfd, val, outsym->e_value);
1963 /* If this symbol is in the procedure linkage table, fill in the
1965 if (h->plt_offset != 0)
1973 dynobj = sunos_hash_table (info)->dynobj;
1974 splt = bfd_get_section_by_name (dynobj, ".plt");
1975 p = splt->contents + h->plt_offset;
1977 s = bfd_get_section_by_name (dynobj, ".dynrel");
1979 r_address = (h->root.root.u.def.section->output_section->vma
1980 + h->root.root.u.def.section->output_offset
1981 + h->root.root.u.def.value);
1983 switch (bfd_get_arch (output_bfd))
1985 case bfd_arch_sparc:
1986 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1988 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
1989 bfd_put_32 (output_bfd,
1990 (SPARC_PLT_ENTRY_WORD1
1991 + (((- (h->plt_offset + 4) >> 2)
1994 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
2001 val = (h->root.root.u.def.section->output_section->vma
2002 + h->root.root.u.def.section->output_offset
2003 + h->root.root.u.def.value);
2004 bfd_put_32 (output_bfd,
2005 SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
2007 bfd_put_32 (output_bfd,
2008 SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
2010 bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
2015 if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
2017 bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
2018 bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
2019 bfd_put_16 (output_bfd, s->reloc_count, p + 6);
2027 /* We also need to add a jump table reloc, unless this is the
2028 result of a JMP_TBL reloc from PIC compiled code. */
2029 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2031 p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
2032 if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
2034 struct reloc_std_external *srel;
2036 srel = (struct reloc_std_external *) p;
2037 PUT_WORD (output_bfd, r_address, srel->r_address);
2038 if (output_bfd->xvec->header_byteorder_big_p)
2040 srel->r_index[0] = h->dynindx >> 16;
2041 srel->r_index[1] = h->dynindx >> 8;
2042 srel->r_index[2] = h->dynindx;
2043 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
2044 | RELOC_STD_BITS_JMPTABLE_BIG);
2048 srel->r_index[2] = h->dynindx >> 16;
2049 srel->r_index[1] = h->dynindx >> 8;
2050 srel->r_index[0] = h->dynindx;
2051 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2052 | RELOC_STD_BITS_JMPTABLE_LITTLE);
2057 struct reloc_ext_external *erel;
2059 erel = (struct reloc_ext_external *) p;
2060 PUT_WORD (output_bfd, r_address, erel->r_address);
2061 if (output_bfd->xvec->header_byteorder_big_p)
2063 erel->r_index[0] = h->dynindx >> 16;
2064 erel->r_index[1] = h->dynindx >> 8;
2065 erel->r_index[2] = h->dynindx;
2066 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_BIG
2067 | (22 << RELOC_EXT_BITS_TYPE_SH_BIG));
2071 erel->r_index[2] = h->dynindx >> 16;
2072 erel->r_index[1] = h->dynindx >> 8;
2073 erel->r_index[0] = h->dynindx;
2074 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_LITTLE
2075 | (22 << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2077 PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
2087 /* This is called for each reloc against an external symbol. If this
2088 is a reloc which are are going to copy as a dynamic reloc, then
2089 copy it over, and tell the caller to not bother processing this
2094 sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
2095 contents, skip, relocationp)
2096 struct bfd_link_info *info;
2098 asection *input_section;
2099 struct aout_link_hash_entry *harg;
2103 bfd_vma *relocationp;
2105 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
2113 dynobj = sunos_hash_table (info)->dynobj;
2115 if (h != NULL && h->plt_offset != 0)
2119 /* Redirect the relocation to the PLT entry. */
2120 splt = bfd_get_section_by_name (dynobj, ".plt");
2121 *relocationp = (splt->output_section->vma
2122 + splt->output_offset
2126 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2128 struct reloc_std_external *srel;
2130 srel = (struct reloc_std_external *) reloc;
2131 if (input_bfd->xvec->header_byteorder_big_p)
2132 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2134 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2138 struct reloc_ext_external *erel;
2141 erel = (struct reloc_ext_external *) reloc;
2142 if (input_bfd->xvec->header_byteorder_big_p)
2143 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2144 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2146 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2147 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2148 baserel = (r_type == RELOC_BASE10
2149 || r_type == RELOC_BASE13
2150 || r_type == RELOC_BASE22);
2155 bfd_vma *got_offsetp;
2159 got_offsetp = &h->got_offset;
2160 else if (adata (input_bfd).local_got_offsets == NULL)
2164 struct reloc_std_external *srel;
2167 srel = (struct reloc_std_external *) reloc;
2168 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2170 if (input_bfd->xvec->header_byteorder_big_p)
2171 r_index = ((srel->r_index[0] << 16)
2172 | (srel->r_index[1] << 8)
2173 | srel->r_index[2]);
2175 r_index = ((srel->r_index[2] << 16)
2176 | (srel->r_index[1] << 8)
2177 | srel->r_index[0]);
2181 struct reloc_ext_external *erel;
2183 erel = (struct reloc_ext_external *) reloc;
2184 if (input_bfd->xvec->header_byteorder_big_p)
2185 r_index = ((erel->r_index[0] << 16)
2186 | (erel->r_index[1] << 8)
2187 | erel->r_index[2]);
2189 r_index = ((erel->r_index[2] << 16)
2190 | (erel->r_index[1] << 8)
2191 | erel->r_index[0]);
2194 got_offsetp = adata (input_bfd).local_got_offsets + r_index;
2197 BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
2199 sgot = bfd_get_section_by_name (dynobj, ".got");
2201 /* We set the least significant bit to indicate whether we have
2202 already initialized the GOT entry. */
2203 if ((*got_offsetp & 1) == 0)
2205 PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
2208 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
2209 && (h->flags & SUNOS_DEF_REGULAR) == 0)
2211 /* We need to create a GLOB_DAT reloc to tell the
2212 dynamic linker to fill in this entry in the table. */
2214 s = bfd_get_section_by_name (dynobj, ".dynrel");
2215 BFD_ASSERT (s != NULL);
2218 + s->reloc_count * obj_reloc_entry_size (dynobj));
2220 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2222 struct reloc_std_external *srel;
2224 srel = (struct reloc_std_external *) p;
2227 + sgot->output_section->vma
2228 + sgot->output_offset),
2230 if (dynobj->xvec->header_byteorder_big_p)
2232 srel->r_index[0] = h->dynindx >> 16;
2233 srel->r_index[1] = h->dynindx >> 8;
2234 srel->r_index[2] = h->dynindx;
2236 (RELOC_STD_BITS_EXTERN_BIG
2237 | RELOC_STD_BITS_BASEREL_BIG
2238 | RELOC_STD_BITS_RELATIVE_BIG
2239 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
2243 srel->r_index[2] = h->dynindx >> 16;
2244 srel->r_index[1] = h->dynindx >> 8;
2245 srel->r_index[0] = h->dynindx;
2247 (RELOC_STD_BITS_EXTERN_LITTLE
2248 | RELOC_STD_BITS_BASEREL_LITTLE
2249 | RELOC_STD_BITS_RELATIVE_LITTLE
2250 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2255 struct reloc_ext_external *erel;
2257 erel = (struct reloc_ext_external *) p;
2260 + sgot->output_section->vma
2261 + sgot->output_offset),
2263 if (dynobj->xvec->header_byteorder_big_p)
2265 erel->r_index[0] = h->dynindx >> 16;
2266 erel->r_index[1] = h->dynindx >> 8;
2267 erel->r_index[2] = h->dynindx;
2269 (RELOC_EXT_BITS_EXTERN_BIG
2270 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
2274 erel->r_index[2] = h->dynindx >> 16;
2275 erel->r_index[1] = h->dynindx >> 8;
2276 erel->r_index[0] = h->dynindx;
2278 (RELOC_EXT_BITS_EXTERN_LITTLE
2279 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2281 PUT_WORD (dynobj, 0, erel->r_addend);
2290 *relocationp = sgot->vma + (*got_offsetp &~ 1);
2292 /* There is nothing else to do for a base relative reloc. */
2296 if (! sunos_hash_table (info)->dynamic_sections_needed
2299 || h->root.root.type != bfd_link_hash_undefined
2300 || (h->flags & SUNOS_DEF_REGULAR) != 0
2301 || (h->flags & SUNOS_DEF_DYNAMIC) == 0
2302 || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
2305 /* It looks like this is a reloc we are supposed to copy. */
2307 s = bfd_get_section_by_name (dynobj, ".dynrel");
2308 BFD_ASSERT (s != NULL);
2310 p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
2312 /* Copy the reloc over. */
2313 memcpy (p, reloc, obj_reloc_entry_size (dynobj));
2315 /* Adjust the address and symbol index. */
2316 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2318 struct reloc_std_external *srel;
2320 srel = (struct reloc_std_external *) p;
2322 (GET_WORD (dynobj, srel->r_address)
2323 + input_section->output_section->vma
2324 + input_section->output_offset),
2326 if (dynobj->xvec->header_byteorder_big_p)
2328 srel->r_index[0] = h->dynindx >> 16;
2329 srel->r_index[1] = h->dynindx >> 8;
2330 srel->r_index[2] = h->dynindx;
2334 srel->r_index[2] = h->dynindx >> 16;
2335 srel->r_index[1] = h->dynindx >> 8;
2336 srel->r_index[0] = h->dynindx;
2341 struct reloc_ext_external *erel;
2343 erel = (struct reloc_ext_external *) p;
2345 (GET_WORD (dynobj, erel->r_address)
2346 + input_section->output_section->vma
2347 + input_section->output_offset),
2349 if (dynobj->xvec->header_byteorder_big_p)
2351 erel->r_index[0] = h->dynindx >> 16;
2352 erel->r_index[1] = h->dynindx >> 8;
2353 erel->r_index[2] = h->dynindx;
2357 erel->r_index[2] = h->dynindx >> 16;
2358 erel->r_index[1] = h->dynindx >> 8;
2359 erel->r_index[0] = h->dynindx;
2370 /* Finish up the dynamic linking information. */
2373 sunos_finish_dynamic_link (abfd, info)
2375 struct bfd_link_info *info;
2381 struct external_sun4_dynamic esd;
2382 struct external_sun4_dynamic_link esdl;
2384 if (! sunos_hash_table (info)->dynamic_sections_needed)
2387 dynobj = sunos_hash_table (info)->dynobj;
2389 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2390 BFD_ASSERT (sdyn != NULL);
2392 /* Finish up the .need section. The linker emulation code filled it
2393 in, but with offsets from the start of the section instead of
2394 real addresses. Now that we know the section location, we can
2395 fill in the final values. */
2396 s = bfd_get_section_by_name (dynobj, ".need");
2397 if (s != NULL && s->_raw_size != 0)
2402 filepos = s->output_section->filepos + s->output_offset;
2408 PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
2409 val = GET_WORD (dynobj, p + 12);
2412 PUT_WORD (dynobj, val + filepos, p + 12);
2417 /* The first entry in the .got section is the address of the dynamic
2419 s = bfd_get_section_by_name (dynobj, ".got");
2420 BFD_ASSERT (s != NULL);
2421 PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
2424 for (o = dynobj->sections; o != NULL; o = o->next)
2426 if ((o->flags & SEC_HAS_CONTENTS) != 0
2427 && o->contents != NULL)
2429 BFD_ASSERT (o->output_section != NULL
2430 && o->output_section->owner == abfd);
2431 if (! bfd_set_section_contents (abfd, o->output_section,
2432 o->contents, o->output_offset,
2438 /* Finish up the dynamic link information. */
2439 PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
2441 sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
2444 (sdyn->output_section->vma
2445 + sdyn->output_offset
2447 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2450 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
2451 sdyn->output_offset, sizeof esd))
2455 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
2457 s = bfd_get_section_by_name (dynobj, ".need");
2458 if (s == NULL || s->_raw_size == 0)
2459 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
2461 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2464 s = bfd_get_section_by_name (dynobj, ".rules");
2465 if (s == NULL || s->_raw_size == 0)
2466 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
2468 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2471 s = bfd_get_section_by_name (dynobj, ".got");
2472 BFD_ASSERT (s != NULL);
2473 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
2475 s = bfd_get_section_by_name (dynobj, ".plt");
2476 BFD_ASSERT (s != NULL);
2477 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
2478 PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
2480 s = bfd_get_section_by_name (dynobj, ".dynrel");
2481 BFD_ASSERT (s != NULL);
2482 BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
2483 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2486 s = bfd_get_section_by_name (dynobj, ".hash");
2487 BFD_ASSERT (s != NULL);
2488 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2491 s = bfd_get_section_by_name (dynobj, ".dynsym");
2492 BFD_ASSERT (s != NULL);
2493 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2496 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
2498 PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
2501 s = bfd_get_section_by_name (dynobj, ".dynstr");
2502 BFD_ASSERT (s != NULL);
2503 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2505 PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
2507 /* The size of the text area is the size of the .text section
2508 rounded up to a page boundary. FIXME: Should the page size be
2509 conditional on something? */
2511 BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
2514 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
2515 (sdyn->output_offset
2517 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2521 abfd->flags |= DYNAMIC;