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. */
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. */
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 < 0 || 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 == info->dyninfo.ld_symbols - info->dyninfo.ld_stab);
212 /* Similarly, the relocs end at the hash table. */
213 info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
214 / obj_reloc_entry_size (abfd));
215 BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
216 == info->dyninfo.ld_hash - info->dyninfo.ld_rel);
223 /* Return the amount of memory required for the dynamic symbols. */
226 sunos_get_dynamic_symtab_upper_bound (abfd)
229 struct sunos_dynamic_info *info;
231 if (! sunos_read_dynamic_info (abfd))
234 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
237 bfd_set_error (bfd_error_no_symbols);
241 return (info->dynsym_count + 1) * sizeof (asymbol *);
244 /* Read in the dynamic symbols. */
247 sunos_canonicalize_dynamic_symtab (abfd, storage)
251 struct sunos_dynamic_info *info;
254 /* Get the general dynamic information. */
255 if (obj_aout_dynamic_info (abfd) == NULL)
257 if (! sunos_read_dynamic_info (abfd))
261 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
264 bfd_set_error (bfd_error_no_symbols);
268 /* Get the dynamic nlist structures. */
269 if (info->dynsym == (struct external_nlist *) NULL)
271 info->dynsym = ((struct external_nlist *)
274 * EXTERNAL_NLIST_SIZE)));
275 if (info->dynsym == NULL && info->dynsym_count != 0)
277 bfd_set_error (bfd_error_no_memory);
280 if (bfd_seek (abfd, info->dyninfo.ld_stab, SEEK_SET) != 0
281 || (bfd_read ((PTR) info->dynsym, info->dynsym_count,
282 EXTERNAL_NLIST_SIZE, abfd)
283 != info->dynsym_count * EXTERNAL_NLIST_SIZE))
285 if (info->dynsym != NULL)
287 bfd_release (abfd, info->dynsym);
294 /* Get the dynamic strings. */
295 if (info->dynstr == (char *) NULL)
297 info->dynstr = (char *) bfd_alloc (abfd, info->dyninfo.ld_symb_size);
298 if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
300 bfd_set_error (bfd_error_no_memory);
303 if (bfd_seek (abfd, info->dyninfo.ld_symbols, SEEK_SET) != 0
304 || (bfd_read ((PTR) info->dynstr, 1, info->dyninfo.ld_symb_size,
306 != info->dyninfo.ld_symb_size))
308 if (info->dynstr != NULL)
310 bfd_release (abfd, info->dynstr);
317 #ifdef CHECK_DYNAMIC_HASH
318 /* Check my understanding of the dynamic hash table by making sure
319 that each symbol can be located in the hash table. */
321 bfd_size_type table_size;
325 if (info->dyninfo.ld_buckets > info->dynsym_count)
327 table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
328 table = (bfd_byte *) malloc (table_size);
329 if (table == NULL && table_size != 0)
331 if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
332 || bfd_read ((PTR) table, 1, table_size, abfd) != table_size)
334 for (i = 0; i < info->dynsym_count; i++)
339 name = ((unsigned char *) info->dynstr
340 + GET_WORD (abfd, info->dynsym[i].e_strx));
342 while (*name != '\0')
343 hash = (hash << 1) + *name++;
345 hash %= info->dyninfo.ld_buckets;
346 while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
348 hash = GET_WORD (abfd,
349 table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
350 if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
356 #endif /* CHECK_DYNAMIC_HASH */
358 /* Get the asymbol structures corresponding to the dynamic nlist
360 if (info->canonical_dynsym == (aout_symbol_type *) NULL)
362 info->canonical_dynsym = ((aout_symbol_type *)
365 * sizeof (aout_symbol_type))));
366 if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
368 bfd_set_error (bfd_error_no_memory);
372 if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
373 info->dynsym, info->dynsym_count,
375 info->dyninfo.ld_symb_size,
378 if (info->canonical_dynsym != NULL)
380 bfd_release (abfd, info->canonical_dynsym);
381 info->canonical_dynsym = NULL;
387 /* Return pointers to the dynamic asymbol structures. */
388 for (i = 0; i < info->dynsym_count; i++)
389 *storage++ = (asymbol *) (info->canonical_dynsym + i);
392 return info->dynsym_count;
395 /* Return the amount of memory required for the dynamic relocs. */
398 sunos_get_dynamic_reloc_upper_bound (abfd)
401 struct sunos_dynamic_info *info;
403 if (! sunos_read_dynamic_info (abfd))
406 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
409 bfd_set_error (bfd_error_no_symbols);
413 return (info->dynrel_count + 1) * sizeof (arelent *);
416 /* Read in the dynamic relocs. */
419 sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
424 struct sunos_dynamic_info *info;
427 /* Get the general dynamic information. */
428 if (obj_aout_dynamic_info (abfd) == (PTR) NULL)
430 if (! sunos_read_dynamic_info (abfd))
434 info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
437 bfd_set_error (bfd_error_no_symbols);
441 /* Get the dynamic reloc information. */
442 if (info->dynrel == NULL)
444 info->dynrel = (PTR) bfd_alloc (abfd,
446 * obj_reloc_entry_size (abfd)));
447 if (info->dynrel == NULL && info->dynrel_count != 0)
449 bfd_set_error (bfd_error_no_memory);
452 if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
453 || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
454 obj_reloc_entry_size (abfd), abfd)
455 != info->dynrel_count * obj_reloc_entry_size (abfd)))
457 if (info->dynrel != NULL)
459 bfd_release (abfd, info->dynrel);
466 /* Get the arelent structures corresponding to the dynamic reloc
468 if (info->canonical_dynrel == (arelent *) NULL)
472 info->canonical_dynrel = ((arelent *)
475 * sizeof (arelent))));
476 if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
478 bfd_set_error (bfd_error_no_memory);
482 to = info->canonical_dynrel;
484 if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
486 register struct reloc_ext_external *p;
487 struct reloc_ext_external *pend;
489 p = (struct reloc_ext_external *) info->dynrel;
490 pend = p + info->dynrel_count;
491 for (; p < pend; p++, to++)
492 NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms,
497 register struct reloc_std_external *p;
498 struct reloc_std_external *pend;
500 p = (struct reloc_std_external *) info->dynrel;
501 pend = p + info->dynrel_count;
502 for (; p < pend; p++, to++)
503 NAME(aout,swap_std_reloc_in) (abfd, p, to, syms,
508 /* Return pointers to the dynamic arelent structures. */
509 for (i = 0; i < info->dynrel_count; i++)
510 *storage++ = info->canonical_dynrel + i;
513 return info->dynrel_count;
516 /* Code to handle linking of SunOS shared libraries. */
518 /* A SPARC procedure linkage table entry is 12 bytes. The first entry
519 in the table is a jump which is filled in by the runtime linker.
520 The remaining entries are branches back to the first entry,
521 followed by an index into the relocation table encoded to look like
524 #define SPARC_PLT_ENTRY_SIZE (12)
526 static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
528 /* sethi %hi(0),%g1; address filled in by runtime linker. */
530 /* jmp %g1; offset filled in by runtime linker. */
536 /* save %sp, -96, %sp */
537 #define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0
538 /* call; address filled in later. */
539 #define SPARC_PLT_ENTRY_WORD1 0x40000000
540 /* sethi; reloc index filled in later. */
541 #define SPARC_PLT_ENTRY_WORD2 0x01000000
543 /* This sequence is used when for the jump table entry to a defined
544 symbol in a complete executable. It is used when linking PIC
545 compiled code which is not being put into a shared library. */
546 /* sethi <address to be filled in later>, %g1 */
547 #define SPARC_PLT_PIC_WORD0 0x03000000
548 /* jmp %g1 + <address to be filled in later> */
549 #define SPARC_PLT_PIC_WORD1 0x81c06000
551 #define SPARC_PLT_PIC_WORD2 0x01000000
553 /* An m68k procedure linkage table entry is 8 bytes. The first entry
554 in the table is a jump which is filled in the by the runtime
555 linker. The remaining entries are branches back to the first
556 entry, followed by a two byte index into the relocation table. */
558 #define M68K_PLT_ENTRY_SIZE (8)
560 static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
564 /* Filled in by runtime linker with a magic address. */
571 #define M68K_PLT_ENTRY_WORD0 (0x61ff)
572 /* Remaining words filled in later. */
574 /* An entry in the SunOS linker hash table. */
576 struct sunos_link_hash_entry
578 struct aout_link_hash_entry root;
580 /* If this is a dynamic symbol, this is its index into the dynamic
581 symbol table. This is initialized to -1. As the linker looks at
582 the input files, it changes this to -2 if it will be added to the
583 dynamic symbol table. After all the input files have been seen,
584 the linker will know whether to build a dynamic symbol table; if
585 it does build one, this becomes the index into the table. */
588 /* If this is a dynamic symbol, this is the index of the name in the
589 dynamic symbol string table. */
592 /* The offset into the global offset table used for this symbol. If
593 the symbol does not require a GOT entry, this is 0. */
596 /* The offset into the procedure linkage table used for this symbol.
597 If the symbol does not require a PLT entry, this is 0. */
600 /* Some linker flags. */
602 /* Symbol is referenced by a regular object. */
603 #define SUNOS_REF_REGULAR 01
604 /* Symbol is defined by a regular object. */
605 #define SUNOS_DEF_REGULAR 02
606 /* Symbol is referenced by a dynamic object. */
607 #define SUNOS_REF_DYNAMIC 010
608 /* Symbol is defined by a dynamic object. */
609 #define SUNOS_DEF_DYNAMIC 020
612 /* The SunOS linker hash table. */
614 struct sunos_link_hash_table
616 struct aout_link_hash_table root;
618 /* The object which holds the dynamic sections. */
621 /* Whether we have created the dynamic sections. */
622 boolean dynamic_sections_created;
624 /* Whether we need the dynamic sections. */
625 boolean dynamic_sections_needed;
627 /* The number of dynamic symbols. */
630 /* The number of buckets in the hash table. */
634 /* Routine to create an entry in an SunOS link hash table. */
636 static struct bfd_hash_entry *
637 sunos_link_hash_newfunc (entry, table, string)
638 struct bfd_hash_entry *entry;
639 struct bfd_hash_table *table;
642 struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
644 /* Allocate the structure if it has not already been allocated by a
646 if (ret == (struct sunos_link_hash_entry *) NULL)
647 ret = ((struct sunos_link_hash_entry *)
648 bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry)));
649 if (ret == (struct sunos_link_hash_entry *) NULL)
651 bfd_set_error (bfd_error_no_memory);
652 return (struct bfd_hash_entry *) ret;
655 /* Call the allocation method of the superclass. */
656 ret = ((struct sunos_link_hash_entry *)
657 NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
661 /* Set local fields. */
663 ret->dynstr_index = -1;
669 return (struct bfd_hash_entry *) ret;
672 /* Create a SunOS link hash table. */
674 static struct bfd_link_hash_table *
675 sunos_link_hash_table_create (abfd)
678 struct sunos_link_hash_table *ret;
680 ret = ((struct sunos_link_hash_table *)
681 bfd_alloc (abfd, sizeof (struct sunos_link_hash_table)));
682 if (ret == (struct sunos_link_hash_table *) NULL)
684 bfd_set_error (bfd_error_no_memory);
685 return (struct bfd_link_hash_table *) NULL;
687 if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
688 sunos_link_hash_newfunc))
691 return (struct bfd_link_hash_table *) NULL;
695 ret->dynamic_sections_created = false;
696 ret->dynamic_sections_needed = false;
697 ret->dynsymcount = 0;
698 ret->bucketcount = 0;
700 return &ret->root.root;
703 /* Look up an entry in an SunOS link hash table. */
705 #define sunos_link_hash_lookup(table, string, create, copy, follow) \
706 ((struct sunos_link_hash_entry *) \
707 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
710 /* Traverse a SunOS link hash table. */
712 #define sunos_link_hash_traverse(table, func, info) \
713 (aout_link_hash_traverse \
715 (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
718 /* Get the SunOS link hash table from the info structure. This is
721 #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
723 static boolean sunos_scan_dynamic_symbol
724 PARAMS ((struct sunos_link_hash_entry *, PTR));
726 /* Create the dynamic sections needed if we are linking against a
727 dynamic object, or if we are linking PIC compiled code. ABFD is a
728 bfd we can attach the dynamic sections to. The linker script will
729 look for these special sections names and put them in the right
730 place in the output file. See include/aout/sun4.h for more details
731 of the dynamic linking information. */
734 sunos_create_dynamic_sections (abfd, info, needed)
736 struct bfd_link_info *info;
741 if (! sunos_hash_table (info)->dynamic_sections_created)
745 sunos_hash_table (info)->dynobj = abfd;
747 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
749 /* The .dynamic section holds the basic dynamic information: the
750 sun4_dynamic structure, the dynamic debugger information, and
751 the sun4_dynamic_link structure. */
752 s = bfd_make_section (abfd, ".dynamic");
754 || ! bfd_set_section_flags (abfd, s, flags)
755 || ! bfd_set_section_alignment (abfd, s, 2))
758 /* The .got section holds the global offset table. The address
759 is put in the ld_got field. */
760 s = bfd_make_section (abfd, ".got");
762 || ! bfd_set_section_flags (abfd, s, flags)
763 || ! bfd_set_section_alignment (abfd, s, 2))
766 /* The .plt section holds the procedure linkage table. The
767 address is put in the ld_plt field. */
768 s = bfd_make_section (abfd, ".plt");
770 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
771 || ! bfd_set_section_alignment (abfd, s, 2))
774 /* The .dynrel section holds the dynamic relocs. The address is
775 put in the ld_rel field. */
776 s = bfd_make_section (abfd, ".dynrel");
778 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
779 || ! bfd_set_section_alignment (abfd, s, 2))
782 /* The .hash section holds the dynamic hash table. The address
783 is put in the ld_hash field. */
784 s = bfd_make_section (abfd, ".hash");
786 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
787 || ! bfd_set_section_alignment (abfd, s, 2))
790 /* The .dynsym section holds the dynamic symbols. The address
791 is put in the ld_stab field. */
792 s = bfd_make_section (abfd, ".dynsym");
794 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
795 || ! bfd_set_section_alignment (abfd, s, 2))
798 /* The .dynstr section holds the dynamic symbol string table.
799 The address is put in the ld_symbols field. */
800 s = bfd_make_section (abfd, ".dynstr");
802 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
803 || ! bfd_set_section_alignment (abfd, s, 2))
806 sunos_hash_table (info)->dynamic_sections_created = true;
809 if (needed && ! sunos_hash_table (info)->dynamic_sections_needed)
813 dynobj = sunos_hash_table (info)->dynobj;
815 s = bfd_get_section_by_name (dynobj, ".got");
816 s->_raw_size = BYTES_IN_WORD;
818 sunos_hash_table (info)->dynamic_sections_needed = true;
824 /* Add dynamic symbols during a link. This is called by the a.out
825 backend linker when it encounters an object with the DYNAMIC flag
829 sunos_add_dynamic_symbols (abfd, info)
831 struct bfd_link_info *info;
836 /* We do not want to include the sections in a dynamic object in the
837 output file. We hack by simply clobbering the list of sections
838 in the BFD. This could be handled more cleanly by, say, a new
839 section flag; the existing SEC_NEVER_LOAD flag is not the one we
840 want, because that one still implies that the section takes up
841 space in the output file. */
842 abfd->sections = NULL;
844 /* The native linker seems to just ignore dynamic objects when -r is
846 if (info->relocateable)
849 /* There's no hope of using a dynamic object which does not exactly
850 match the format of the output file. */
851 if (info->hash->creator != abfd->xvec)
853 bfd_set_error (bfd_error_invalid_operation);
857 /* Make sure we have all the required information. */
858 if (! sunos_create_dynamic_sections (abfd, info, true))
861 /* Make sure we have a .need and a .rules sections. These are only
862 needed if there really is a dynamic object in the link, so they
863 are not added by sunos_create_dynamic_sections. */
864 dynobj = sunos_hash_table (info)->dynobj;
865 if (bfd_get_section_by_name (dynobj, ".need") == NULL)
867 /* The .need section holds the list of names of shared objets
868 which must be included at runtime. The address of this
869 section is put in the ld_need field. */
870 s = bfd_make_section (dynobj, ".need");
872 || ! bfd_set_section_flags (dynobj, s,
878 || ! bfd_set_section_alignment (dynobj, s, 2))
882 if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
884 /* The .rules section holds the path to search for shared
885 objects. The address of this section is put in the ld_rules
887 s = bfd_make_section (dynobj, ".rules");
889 || ! bfd_set_section_flags (dynobj, s,
895 || ! bfd_set_section_alignment (dynobj, s, 2))
902 /* Function to add a single symbol to the linker hash table. This is
903 a wrapper around _bfd_generic_link_add_one_symbol which handles the
904 tweaking needed for dynamic linking support. */
907 sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
908 copy, collect, hashp)
909 struct bfd_link_info *info;
918 struct bfd_link_hash_entry **hashp;
920 struct sunos_link_hash_entry *h;
923 if (! sunos_hash_table (info)->dynamic_sections_created)
925 /* We must create the dynamic sections while reading the input
926 files, even though at this point we don't know if any of the
927 sections will be needed. This will ensure that the dynamic
928 sections are mapped to the right output section. It does no
929 harm to create these sections if they are not needed. */
930 if (! sunos_create_dynamic_sections (abfd, info, info->shared))
934 h = sunos_link_hash_lookup (sunos_hash_table (info), name, true, copy,
940 *hashp = (struct bfd_link_hash_entry *) h;
942 /* Treat a common symbol in a dynamic object as defined in the .bss
943 section of the dynamic object. We don't want to allocate space
944 for it in our process image. */
945 if ((abfd->flags & DYNAMIC) != 0
946 && bfd_is_com_section (section))
947 section = obj_bsssec (abfd);
949 if (! bfd_is_und_section (section)
950 && h->root.root.type != bfd_link_hash_new
951 && h->root.root.type != bfd_link_hash_undefined
952 && h->root.root.type != bfd_link_hash_defweak)
954 /* We are defining the symbol, and it is already defined. This
955 is a potential multiple definition error. */
956 if ((abfd->flags & DYNAMIC) != 0)
958 /* The definition we are adding is from a dynamic object.
959 We do not want this new definition to override the
960 existing definition, so we pretend it is just a
962 section = bfd_und_section_ptr;
964 else if ((h->root.root.type == bfd_link_hash_defined
965 && h->root.root.u.def.section->owner != NULL
966 && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
967 || (h->root.root.type == bfd_link_hash_common
968 && ((h->root.root.u.c.p->section->owner->flags & DYNAMIC)
971 /* The existing definition is from a dynamic object. We
972 want to override it with the definition we just found.
973 Clobber the existing definition. */
974 h->root.root.type = bfd_link_hash_new;
978 /* Do the usual procedure for adding a symbol. */
979 if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
980 value, string, copy, collect,
984 if (abfd->xvec == info->hash->creator)
986 /* Set a flag in the hash table entry indicating the type of
987 reference or definition we just found. Keep a count of the
988 number of dynamic symbols we find. A dynamic symbol is one
989 which is referenced or defined by both a regular object and a
991 if ((abfd->flags & DYNAMIC) == 0)
993 if (bfd_is_und_section (section))
994 new_flag = SUNOS_REF_REGULAR;
996 new_flag = SUNOS_DEF_REGULAR;
1000 if (bfd_is_und_section (section))
1001 new_flag = SUNOS_REF_DYNAMIC;
1003 new_flag = SUNOS_DEF_DYNAMIC;
1005 h->flags |= new_flag;
1007 if (h->dynindx == -1
1008 && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1010 ++sunos_hash_table (info)->dynsymcount;
1018 /* Record an assignment made to a symbol by a linker script. We need
1019 this in case some dynamic object refers to this symbol. */
1022 bfd_sunos_record_link_assignment (output_bfd, info, name)
1024 struct bfd_link_info *info;
1027 struct sunos_link_hash_entry *h;
1029 /* This is called after we have examined all the input objects. If
1030 the symbol does not exist, it merely means that no object refers
1031 to it, and we can just ignore it at this point. */
1032 h = sunos_link_hash_lookup (sunos_hash_table (info), name,
1033 false, false, false);
1037 h->flags |= SUNOS_DEF_REGULAR;
1039 if (h->dynindx == -1)
1041 ++sunos_hash_table (info)->dynsymcount;
1048 /* Set up the sizes and contents of the dynamic sections created in
1049 sunos_add_dynamic_symbols. This is called by the SunOS linker
1050 emulation before_allocation routine. We must set the sizes of the
1051 sections before the linker sets the addresses of the various
1052 sections. This unfortunately requires reading all the relocs so
1053 that we can work out which ones need to become dynamic relocs. If
1054 info->keep_memory is true, we keep the relocs in memory; otherwise,
1055 we discard them, and will read them again later. */
1058 bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
1061 struct bfd_link_info *info;
1063 asection **sneedptr;
1064 asection **srulesptr;
1068 struct sunos_link_hash_entry *h;
1079 /* Look through all the input BFD's and read their relocs. It would
1080 be better if we didn't have to do this, but there is no other way
1081 to determine the number of dynamic relocs we need, and, more
1082 importantly, there is no other way to know which symbols should
1083 get an entry in the procedure linkage table. */
1084 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
1086 if ((sub->flags & DYNAMIC) == 0)
1088 if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
1089 exec_hdr (sub)->a_trsize)
1090 || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
1091 exec_hdr (sub)->a_drsize))
1096 dynobj = sunos_hash_table (info)->dynobj;
1097 dynsymcount = sunos_hash_table (info)->dynsymcount;
1099 /* If there were no dynamic objects in the link, and we don't need
1100 to build a global offset table, there is nothing to do here. */
1101 if (! sunos_hash_table (info)->dynamic_sections_needed)
1104 /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it. */
1105 h = sunos_link_hash_lookup (sunos_hash_table (info),
1106 "__GLOBAL_OFFSET_TABLE_", false, false, false);
1107 if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
1109 h->flags |= SUNOS_DEF_REGULAR;
1110 if (h->dynindx == -1)
1112 ++sunos_hash_table (info)->dynsymcount;
1115 h->root.root.type = bfd_link_hash_defined;
1116 h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
1117 h->root.root.u.def.value = 0;
1120 /* The .dynamic section is always the same size. */
1121 s = bfd_get_section_by_name (dynobj, ".dynamic");
1122 BFD_ASSERT (s != NULL);
1123 s->_raw_size = (sizeof (struct external_sun4_dynamic)
1124 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
1125 + sizeof (struct external_sun4_dynamic_link));
1127 /* Set the size of the .dynsym and .hash sections. We counted the
1128 number of dynamic symbols as we read the input files. We will
1129 build the dynamic symbol table (.dynsym) and the hash table
1130 (.hash) when we build the final symbol table, because until then
1131 we do not know the correct value to give the symbols. We build
1132 the dynamic symbol string table (.dynstr) in a traversal of the
1133 symbol table using sunos_scan_dynamic_symbol. */
1134 s = bfd_get_section_by_name (dynobj, ".dynsym");
1135 BFD_ASSERT (s != NULL);
1136 s->_raw_size = dynsymcount * sizeof (struct external_nlist);
1137 s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
1138 if (s->contents == NULL && s->_raw_size != 0)
1140 bfd_set_error (bfd_error_no_memory);
1144 /* The number of buckets is just the number of symbols divided by
1145 four. To compute the final size of the hash table, we must
1146 actually compute the hash table. Normally we need exactly as
1147 many entries in the hash table as there are dynamic symbols, but
1148 if some of the buckets are not used we will need additional
1149 entries. In the worst case, every symbol will hash to the same
1150 bucket, and we will need BUCKETCOUNT - 1 extra entries. */
1151 if (dynsymcount >= 4)
1152 bucketcount = dynsymcount / 4;
1153 else if (dynsymcount > 0)
1154 bucketcount = dynsymcount;
1157 s = bfd_get_section_by_name (dynobj, ".hash");
1158 BFD_ASSERT (s != NULL);
1159 hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
1160 s->contents = (bfd_byte *) bfd_alloc (dynobj, hashalloc);
1161 if (s->contents == NULL && dynsymcount > 0)
1163 bfd_set_error (bfd_error_no_memory);
1166 memset (s->contents, 0, hashalloc);
1167 for (i = 0; i < bucketcount; i++)
1168 PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
1169 s->_raw_size = bucketcount * HASH_ENTRY_SIZE;
1171 sunos_hash_table (info)->bucketcount = bucketcount;
1173 /* Scan all the symbols, place them in the dynamic symbol table, and
1174 build the dynamic hash table. We reuse dynsymcount as a counter
1175 for the number of symbols we have added so far. */
1176 sunos_hash_table (info)->dynsymcount = 0;
1177 sunos_link_hash_traverse (sunos_hash_table (info),
1178 sunos_scan_dynamic_symbol,
1180 BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
1182 /* The SunOS native linker seems to align the total size of the
1183 symbol strings to a multiple of 8. I don't know if this is
1184 important, but it can't hurt much. */
1185 s = bfd_get_section_by_name (dynobj, ".dynstr");
1186 BFD_ASSERT (s != NULL);
1187 if ((s->_raw_size & 7) != 0)
1192 add = 8 - (s->_raw_size & 7);
1193 contents = (bfd_byte *) realloc (s->contents,
1194 (size_t) (s->_raw_size + add));
1195 if (contents == NULL)
1197 bfd_set_error (bfd_error_no_memory);
1200 memset (contents + s->_raw_size, 0, (size_t) add);
1201 s->contents = contents;
1202 s->_raw_size += add;
1205 /* Now that we have worked out the sizes of the procedure linkage
1206 table and the dynamic relocs, allocate storage for them. */
1207 s = bfd_get_section_by_name (dynobj, ".plt");
1208 BFD_ASSERT (s != NULL);
1209 if (s->_raw_size != 0)
1211 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1212 if (s->contents == NULL)
1214 bfd_set_error (bfd_error_no_memory);
1218 /* Fill in the first entry in the table. */
1219 switch (bfd_get_arch (dynobj))
1221 case bfd_arch_sparc:
1222 memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
1226 memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
1234 s = bfd_get_section_by_name (dynobj, ".dynrel");
1235 if (s->_raw_size != 0)
1237 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1238 if (s->contents == NULL)
1240 bfd_set_error (bfd_error_no_memory);
1244 /* We use the reloc_count field to keep track of how many of the
1245 relocs we have output so far. */
1248 /* Make space for the global offset table. */
1249 s = bfd_get_section_by_name (dynobj, ".got");
1250 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1251 if (s->contents == NULL)
1253 bfd_set_error (bfd_error_no_memory);
1257 *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
1258 *sneedptr = bfd_get_section_by_name (dynobj, ".need");
1259 *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
1264 /* Scan the relocs for an input section. */
1267 sunos_scan_relocs (info, abfd, sec, rel_size)
1268 struct bfd_link_info *info;
1271 bfd_size_type rel_size;
1274 PTR free_relocs = NULL;
1279 if (! info->keep_memory)
1280 relocs = free_relocs = malloc ((size_t) rel_size);
1283 struct aout_section_data_struct *n;
1285 n = ((struct aout_section_data_struct *)
1286 bfd_alloc (abfd, sizeof (struct aout_section_data_struct)));
1291 set_aout_section_data (sec, n);
1292 relocs = malloc ((size_t) rel_size);
1293 aout_section_data (sec)->relocs = relocs;
1298 bfd_set_error (bfd_error_no_memory);
1302 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
1303 || bfd_read (relocs, 1, rel_size, abfd) != rel_size)
1306 if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
1308 if (! sunos_scan_std_relocs (info, abfd, sec,
1309 (struct reloc_std_external *) relocs,
1315 if (! sunos_scan_ext_relocs (info, abfd, sec,
1316 (struct reloc_ext_external *) relocs,
1321 if (free_relocs != NULL)
1327 if (free_relocs != NULL)
1332 /* Scan the relocs for an input section using standard relocs. We
1333 need to figure out what to do for each reloc against a dynamic
1334 symbol. If the symbol is in the .text section, an entry is made in
1335 the procedure linkage table. Note that this will do the wrong
1336 thing if the symbol is actually data; I don't think the Sun 3
1337 native linker handles this case correctly either. If the symbol is
1338 not in the .text section, we must preserve the reloc as a dynamic
1339 reloc. FIXME: We should also handle the PIC relocs here by
1340 building global offset table entries. */
1343 sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
1344 struct bfd_link_info *info;
1347 const struct reloc_std_external *relocs;
1348 bfd_size_type rel_size;
1351 asection *splt = NULL;
1352 asection *srel = NULL;
1353 struct sunos_link_hash_entry **sym_hashes;
1354 const struct reloc_std_external *rel, *relend;
1356 /* We only know how to handle m68k plt entries. */
1357 if (bfd_get_arch (abfd) != bfd_arch_m68k)
1359 bfd_set_error (bfd_error_invalid_target);
1365 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1367 relend = relocs + rel_size / RELOC_STD_SIZE;
1368 for (rel = relocs; rel < relend; rel++)
1371 struct sunos_link_hash_entry *h;
1373 /* We only want relocs against external symbols. */
1374 if (abfd->xvec->header_byteorder_big_p)
1376 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
1381 if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
1385 /* Get the symbol index. */
1386 if (abfd->xvec->header_byteorder_big_p)
1387 r_index = ((rel->r_index[0] << 16)
1388 | (rel->r_index[1] << 8)
1391 r_index = ((rel->r_index[2] << 16)
1392 | (rel->r_index[1] << 8)
1395 /* Get the hash table entry. */
1396 h = sym_hashes[r_index];
1399 /* This should not normally happen, but it will in any case
1400 be caught in the relocation phase. */
1404 /* At this point common symbols have already been allocated, so
1405 we don't have to worry about them. We need to consider that
1406 we may have already seen this symbol and marked it undefined;
1407 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1409 if (h->root.root.type != bfd_link_hash_defined
1410 && h->root.root.type != bfd_link_hash_defweak
1411 && h->root.root.type != bfd_link_hash_undefined)
1414 if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1415 || (h->flags & SUNOS_DEF_REGULAR) != 0)
1420 if (! sunos_create_dynamic_sections (abfd, info, true))
1422 dynobj = sunos_hash_table (info)->dynobj;
1423 splt = bfd_get_section_by_name (dynobj, ".plt");
1424 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1425 BFD_ASSERT (splt != NULL && srel != NULL);
1428 BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
1429 BFD_ASSERT ((h->root.root.type == bfd_link_hash_defined
1430 || h->root.root.type == bfd_link_hash_defweak)
1431 ? (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0
1432 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0);
1434 /* This reloc is against a symbol defined only by a dynamic
1437 if (h->root.root.type == bfd_link_hash_undefined)
1439 /* Presumably this symbol was marked as being undefined by
1440 an earlier reloc. */
1441 srel->_raw_size += RELOC_STD_SIZE;
1443 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1447 /* This reloc is not in the .text section. It must be
1448 copied into the dynamic relocs. We mark the symbol as
1450 srel->_raw_size += RELOC_STD_SIZE;
1451 sub = h->root.root.u.def.section->owner;
1452 h->root.root.type = bfd_link_hash_undefined;
1453 h->root.root.u.undef.abfd = sub;
1457 /* This symbol is in the .text section. We must give it an
1458 entry in the procedure linkage table, if we have not
1459 already done so. We change the definition of the symbol
1460 to the .plt section; this will cause relocs against it to
1461 be handled correctly. */
1462 if (h->plt_offset == 0)
1464 if (splt->_raw_size == 0)
1465 splt->_raw_size = M68K_PLT_ENTRY_SIZE;
1466 h->plt_offset = splt->_raw_size;
1468 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1470 h->root.root.u.def.section = splt;
1471 h->root.root.u.def.value = splt->_raw_size;
1474 splt->_raw_size += M68K_PLT_ENTRY_SIZE;
1476 /* We may also need a dynamic reloc entry. */
1477 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1478 srel->_raw_size += RELOC_STD_SIZE;
1486 /* Scan the relocs for an input section using extended relocs. We
1487 need to figure out what to do for each reloc against a dynamic
1488 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1489 section, an entry is made in the procedure linkage table.
1490 Otherwise, we must preserve the reloc as a dynamic reloc. */
1493 sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
1494 struct bfd_link_info *info;
1497 const struct reloc_ext_external *relocs;
1498 bfd_size_type rel_size;
1501 struct sunos_link_hash_entry **sym_hashes;
1502 const struct reloc_ext_external *rel, *relend;
1503 asection *splt = NULL;
1504 asection *sgot = NULL;
1505 asection *srel = NULL;
1507 /* We only know how to handle SPARC plt entries. */
1508 if (bfd_get_arch (abfd) != bfd_arch_sparc)
1510 bfd_set_error (bfd_error_invalid_target);
1516 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1518 relend = relocs + rel_size / RELOC_EXT_SIZE;
1519 for (rel = relocs; rel < relend; rel++)
1524 struct sunos_link_hash_entry *h = NULL;
1526 /* Swap in the reloc information. */
1527 if (abfd->xvec->header_byteorder_big_p)
1529 r_index = ((rel->r_index[0] << 16)
1530 | (rel->r_index[1] << 8)
1532 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1533 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1534 >> RELOC_EXT_BITS_TYPE_SH_BIG);
1538 r_index = ((rel->r_index[2] << 16)
1539 | (rel->r_index[1] << 8)
1541 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1542 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1543 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
1548 h = sym_hashes[r_index];
1551 /* This should not normally happen, but it will in any
1552 case be caught in the relocation phase. */
1558 if (r_index >= bfd_get_symcount (abfd))
1560 /* This is abnormal, but should be caught in the
1561 relocation phase. */
1566 /* If this is a base relative reloc, we need to make an entry in
1567 the .got section. */
1568 if (r_type == RELOC_BASE10
1569 || r_type == RELOC_BASE13
1570 || r_type == RELOC_BASE22)
1574 if (! sunos_create_dynamic_sections (abfd, info, true))
1576 dynobj = sunos_hash_table (info)->dynobj;
1577 splt = bfd_get_section_by_name (dynobj, ".plt");
1578 sgot = bfd_get_section_by_name (dynobj, ".got");
1579 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1580 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1585 if (h->got_offset != 0)
1588 h->got_offset = sgot->_raw_size;
1592 if (adata (abfd).local_got_offsets == NULL)
1594 adata (abfd).local_got_offsets =
1595 (bfd_vma *) bfd_zalloc (abfd,
1596 (bfd_get_symcount (abfd)
1597 * sizeof (bfd_vma)));
1598 if (adata (abfd).local_got_offsets == NULL)
1600 bfd_set_error (bfd_error_no_memory);
1605 if (adata (abfd).local_got_offsets[r_index] != 0)
1608 adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
1611 sgot->_raw_size += BYTES_IN_WORD;
1613 /* If we are making a shared library, or if the symbol is
1614 defined by a dynamic object, we will need a dynamic reloc
1618 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1619 && (h->flags & SUNOS_DEF_REGULAR) == 0))
1620 srel->_raw_size += RELOC_EXT_SIZE;
1625 /* Otherwise, we are only interested in relocs against symbols
1626 defined in dynamic objects but not in regular objects. We
1627 only need to consider relocs against external symbols. */
1631 /* At this point common symbols have already been allocated, so
1632 we don't have to worry about them. We need to consider that
1633 we may have already seen this symbol and marked it undefined;
1634 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1636 if (h->root.root.type != bfd_link_hash_defined
1637 && h->root.root.type != bfd_link_hash_defweak
1638 && h->root.root.type != bfd_link_hash_undefined)
1641 if (r_type != RELOC_JMP_TBL
1642 && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1643 || (h->flags & SUNOS_DEF_REGULAR) != 0))
1646 if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1651 if (! sunos_create_dynamic_sections (abfd, info, true))
1653 dynobj = sunos_hash_table (info)->dynobj;
1654 splt = bfd_get_section_by_name (dynobj, ".plt");
1655 sgot = bfd_get_section_by_name (dynobj, ".got");
1656 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1657 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1660 BFD_ASSERT (r_type == RELOC_JMP_TBL
1661 || (h->flags & SUNOS_REF_REGULAR) != 0);
1662 BFD_ASSERT (r_type == RELOC_JMP_TBL
1663 || h->plt_offset != 0
1664 || ((h->root.root.type == bfd_link_hash_defined
1665 || h->root.root.type == bfd_link_hash_defweak)
1666 ? (h->root.root.u.def.section->owner->flags
1668 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1670 /* This reloc is against a symbol defined only by a dynamic
1671 object, or it is a jump table reloc from PIC compiled code. */
1673 if (h->root.root.type == bfd_link_hash_undefined)
1675 /* Presumably this symbol was marked as being undefined by
1676 an earlier reloc. */
1677 srel->_raw_size += RELOC_EXT_SIZE;
1679 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1683 /* This reloc is not in the .text section. It must be
1684 copied into the dynamic relocs. We mark the symbol as
1686 BFD_ASSERT (r_type != RELOC_JMP_TBL);
1687 srel->_raw_size += RELOC_EXT_SIZE;
1688 sub = h->root.root.u.def.section->owner;
1689 h->root.root.type = bfd_link_hash_undefined;
1690 h->root.root.u.undef.abfd = sub;
1694 /* This symbol is in the .text section. We must give it an
1695 entry in the procedure linkage table, if we have not
1696 already done so. We change the definition of the symbol
1697 to the .plt section; this will cause relocs against it to
1698 be handled correctly. */
1699 if (h->plt_offset == 0)
1701 if (splt->_raw_size == 0)
1702 splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
1703 h->plt_offset = splt->_raw_size;
1705 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1707 h->root.root.u.def.section = splt;
1708 h->root.root.u.def.value = splt->_raw_size;
1711 splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
1713 /* We will also need a dynamic reloc entry, unless this
1714 is a JMP_TBL reloc produced by linking PIC compiled
1715 code, and we are not making a shared library. */
1716 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1717 srel->_raw_size += RELOC_EXT_SIZE;
1725 /* Build the hash table of dynamic symbols, and to mark as written all
1726 symbols from dynamic objects which we do not plan to write out. */
1729 sunos_scan_dynamic_symbol (h, data)
1730 struct sunos_link_hash_entry *h;
1733 struct bfd_link_info *info = (struct bfd_link_info *) data;
1735 /* Set the written flag for symbols we do not want to write out as
1736 part of the regular symbol table. This is all symbols which are
1737 not defined in a regular object file. For some reason symbols
1738 which are referenced by a regular object and defined by a dynamic
1739 object do not seem to show up in the regular symbol table. */
1740 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1741 h->root.written = true;
1743 /* If this symbol is defined by a dynamic object and referenced by a
1744 regular object, see whether we gave it a reasonable value while
1745 scanning the relocs. */
1747 if ((h->flags & SUNOS_DEF_REGULAR) == 0
1748 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1749 && (h->flags & SUNOS_REF_REGULAR) != 0)
1751 if ((h->root.root.type == bfd_link_hash_defined
1752 || h->root.root.type == bfd_link_hash_defweak)
1753 && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1754 && h->root.root.u.def.section->output_section == NULL)
1758 /* This symbol is currently defined in a dynamic section
1759 which is not being put into the output file. This
1760 implies that there is no reloc against the symbol. I'm
1761 not sure why this case would ever occur. In any case, we
1762 change the symbol to be undefined. */
1763 sub = h->root.root.u.def.section->owner;
1764 h->root.root.type = bfd_link_hash_undefined;
1765 h->root.root.u.undef.abfd = sub;
1769 /* If this symbol is defined or referenced by a regular file, add it
1770 to the dynamic symbols. */
1771 if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1776 unsigned char *name;
1780 BFD_ASSERT (h->dynindx == -2);
1782 dynobj = sunos_hash_table (info)->dynobj;
1784 h->dynindx = sunos_hash_table (info)->dynsymcount;
1785 ++sunos_hash_table (info)->dynsymcount;
1787 len = strlen (h->root.root.root.string);
1789 /* We don't bother to construct a BFD hash table for the strings
1790 which are the names of the dynamic symbols. Using a hash
1791 table for the regular symbols is beneficial, because the
1792 regular symbols includes the debugging symbols, which have
1793 long names and are often duplicated in several object files.
1794 There are no debugging symbols in the dynamic symbols. */
1795 s = bfd_get_section_by_name (dynobj, ".dynstr");
1796 BFD_ASSERT (s != NULL);
1797 if (s->contents == NULL)
1798 contents = (bfd_byte *) malloc (len + 1);
1800 contents = (bfd_byte *) realloc (s->contents,
1801 (size_t) (s->_raw_size + len + 1));
1802 if (contents == NULL)
1804 bfd_set_error (bfd_error_no_memory);
1807 s->contents = contents;
1809 h->dynstr_index = s->_raw_size;
1810 strcpy (contents + s->_raw_size, h->root.root.root.string);
1811 s->_raw_size += len + 1;
1813 /* Add it to the dynamic hash table. */
1814 name = (unsigned char *) h->root.root.root.string;
1816 while (*name != '\0')
1817 hash = (hash << 1) + *name++;
1819 hash %= sunos_hash_table (info)->bucketcount;
1821 s = bfd_get_section_by_name (dynobj, ".hash");
1822 BFD_ASSERT (s != NULL);
1824 if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
1825 PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
1830 next = GET_WORD (dynobj,
1832 + hash * HASH_ENTRY_SIZE
1834 PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
1835 s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
1836 PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
1837 PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
1838 s->_raw_size += HASH_ENTRY_SIZE;
1845 /* Link a dynamic object. We actually don't have anything to do at
1846 this point. This entry point exists to prevent the regular linker
1847 code from doing anything with the object. */
1851 sunos_link_dynamic_object (info, abfd)
1852 struct bfd_link_info *info;
1858 /* Write out a dynamic symbol. This is called by the final traversal
1859 over the symbol table. */
1862 sunos_write_dynamic_symbol (output_bfd, info, harg)
1864 struct bfd_link_info *info;
1865 struct aout_link_hash_entry *harg;
1867 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
1871 struct external_nlist *outsym;
1876 switch (h->root.root.type)
1879 case bfd_link_hash_new:
1881 /* Avoid variable not initialized warnings. */
1883 case bfd_link_hash_undefined:
1884 type = N_UNDF | N_EXT;
1887 case bfd_link_hash_defined:
1888 case bfd_link_hash_defweak:
1891 asection *output_section;
1893 sec = h->root.root.u.def.section;
1894 output_section = sec->output_section;
1895 BFD_ASSERT (bfd_is_abs_section (output_section)
1896 || output_section->owner == output_bfd);
1897 if (h->plt_offset != 0
1898 && (h->flags & SUNOS_DEF_REGULAR) == 0)
1900 type = N_UNDF | N_EXT;
1905 if (output_section == obj_textsec (output_bfd))
1906 type = (h->root.root.type == bfd_link_hash_defined
1909 else if (output_section == obj_datasec (output_bfd))
1910 type = (h->root.root.type == bfd_link_hash_defined
1913 else if (output_section == obj_bsssec (output_bfd))
1914 type = (h->root.root.type == bfd_link_hash_defined
1918 type = (h->root.root.type == bfd_link_hash_defined
1922 val = (h->root.root.u.def.value
1923 + output_section->vma
1924 + sec->output_offset);
1928 case bfd_link_hash_common:
1929 type = N_UNDF | N_EXT;
1930 val = h->root.root.u.c.size;
1932 case bfd_link_hash_undefweak:
1936 case bfd_link_hash_indirect:
1937 case bfd_link_hash_warning:
1938 /* FIXME: Ignore these for now. The circumstances under which
1939 they should be written out are not clear to me. */
1943 s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
1944 BFD_ASSERT (s != NULL);
1945 outsym = ((struct external_nlist *)
1946 (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
1948 bfd_h_put_8 (output_bfd, type, outsym->e_type);
1949 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
1951 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
1952 one less than the desc value in the shared library, although that
1954 bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
1956 PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
1957 PUT_WORD (output_bfd, val, outsym->e_value);
1959 /* If this symbol is in the procedure linkage table, fill in the
1961 if (h->plt_offset != 0)
1969 dynobj = sunos_hash_table (info)->dynobj;
1970 splt = bfd_get_section_by_name (dynobj, ".plt");
1971 p = splt->contents + h->plt_offset;
1973 s = bfd_get_section_by_name (dynobj, ".dynrel");
1975 r_address = (h->root.root.u.def.section->output_section->vma
1976 + h->root.root.u.def.section->output_offset
1977 + h->root.root.u.def.value);
1979 switch (bfd_get_arch (output_bfd))
1981 case bfd_arch_sparc:
1982 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1984 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
1985 bfd_put_32 (output_bfd,
1986 (SPARC_PLT_ENTRY_WORD1
1987 + (((- (h->plt_offset + 4) >> 2)
1990 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
1997 val = (h->root.root.u.def.section->output_section->vma
1998 + h->root.root.u.def.section->output_offset
1999 + h->root.root.u.def.value);
2000 bfd_put_32 (output_bfd,
2001 SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
2003 bfd_put_32 (output_bfd,
2004 SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
2006 bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
2011 if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
2013 bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
2014 bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
2015 bfd_put_16 (output_bfd, s->reloc_count, p + 6);
2023 /* We also need to add a jump table reloc, unless this is the
2024 result of a JMP_TBL reloc from PIC compiled code. */
2025 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2027 p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
2028 if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
2030 struct reloc_std_external *srel;
2032 srel = (struct reloc_std_external *) p;
2033 PUT_WORD (output_bfd, r_address, srel->r_address);
2034 if (output_bfd->xvec->header_byteorder_big_p)
2036 srel->r_index[0] = h->dynindx >> 16;
2037 srel->r_index[1] = h->dynindx >> 8;
2038 srel->r_index[2] = h->dynindx;
2039 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
2040 | RELOC_STD_BITS_JMPTABLE_BIG);
2044 srel->r_index[2] = h->dynindx >> 16;
2045 srel->r_index[1] = h->dynindx >> 8;
2046 srel->r_index[0] = h->dynindx;
2047 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2048 | RELOC_STD_BITS_JMPTABLE_LITTLE);
2053 struct reloc_ext_external *erel;
2055 erel = (struct reloc_ext_external *) p;
2056 PUT_WORD (output_bfd, r_address, erel->r_address);
2057 if (output_bfd->xvec->header_byteorder_big_p)
2059 erel->r_index[0] = h->dynindx >> 16;
2060 erel->r_index[1] = h->dynindx >> 8;
2061 erel->r_index[2] = h->dynindx;
2062 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_BIG
2063 | (22 << RELOC_EXT_BITS_TYPE_SH_BIG));
2067 erel->r_index[2] = h->dynindx >> 16;
2068 erel->r_index[1] = h->dynindx >> 8;
2069 erel->r_index[0] = h->dynindx;
2070 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_LITTLE
2071 | (22 << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2073 PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
2083 /* This is called for each reloc against an external symbol. If this
2084 is a reloc which are are going to copy as a dynamic reloc, then
2085 copy it over, and tell the caller to not bother processing this
2090 sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
2091 contents, skip, relocationp)
2092 struct bfd_link_info *info;
2094 asection *input_section;
2095 struct aout_link_hash_entry *harg;
2099 bfd_vma *relocationp;
2101 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
2109 dynobj = sunos_hash_table (info)->dynobj;
2111 if (h != NULL && h->plt_offset != 0)
2115 /* Redirect the relocation to the PLT entry. */
2116 splt = bfd_get_section_by_name (dynobj, ".plt");
2117 *relocationp = (splt->output_section->vma
2118 + splt->output_offset
2122 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2124 struct reloc_std_external *srel;
2126 srel = (struct reloc_std_external *) reloc;
2127 if (input_bfd->xvec->header_byteorder_big_p)
2128 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2130 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2134 struct reloc_ext_external *erel;
2137 erel = (struct reloc_ext_external *) reloc;
2138 if (input_bfd->xvec->header_byteorder_big_p)
2139 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2140 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2142 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2143 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2144 baserel = (r_type == RELOC_BASE10
2145 || r_type == RELOC_BASE13
2146 || r_type == RELOC_BASE22);
2151 bfd_vma *got_offsetp;
2155 got_offsetp = &h->got_offset;
2156 else if (adata (input_bfd).local_got_offsets == NULL)
2160 struct reloc_std_external *srel;
2163 srel = (struct reloc_std_external *) reloc;
2164 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2166 if (input_bfd->xvec->header_byteorder_big_p)
2167 r_index = ((srel->r_index[0] << 16)
2168 | (srel->r_index[1] << 8)
2169 | srel->r_index[2]);
2171 r_index = ((srel->r_index[2] << 16)
2172 | (srel->r_index[1] << 8)
2173 | srel->r_index[0]);
2177 struct reloc_ext_external *erel;
2179 erel = (struct reloc_ext_external *) reloc;
2180 if (input_bfd->xvec->header_byteorder_big_p)
2181 r_index = ((erel->r_index[0] << 16)
2182 | (erel->r_index[1] << 8)
2183 | erel->r_index[2]);
2185 r_index = ((erel->r_index[2] << 16)
2186 | (erel->r_index[1] << 8)
2187 | erel->r_index[0]);
2190 got_offsetp = adata (input_bfd).local_got_offsets + r_index;
2193 BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
2195 sgot = bfd_get_section_by_name (dynobj, ".got");
2197 /* We set the least significant bit to indicate whether we have
2198 already initialized the GOT entry. */
2199 if ((*got_offsetp & 1) == 0)
2201 PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
2204 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
2205 && (h->flags & SUNOS_DEF_REGULAR) == 0)
2207 /* We need to create a GLOB_DAT reloc to tell the
2208 dynamic linker to fill in this entry in the table. */
2210 s = bfd_get_section_by_name (dynobj, ".dynrel");
2211 BFD_ASSERT (s != NULL);
2214 + s->reloc_count * obj_reloc_entry_size (dynobj));
2216 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2218 struct reloc_std_external *srel;
2220 srel = (struct reloc_std_external *) p;
2223 + sgot->output_section->vma
2224 + sgot->output_offset),
2226 if (dynobj->xvec->header_byteorder_big_p)
2228 srel->r_index[0] = h->dynindx >> 16;
2229 srel->r_index[1] = h->dynindx >> 8;
2230 srel->r_index[2] = h->dynindx;
2232 (RELOC_STD_BITS_EXTERN_BIG
2233 | RELOC_STD_BITS_BASEREL_BIG
2234 | RELOC_STD_BITS_RELATIVE_BIG
2235 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
2239 srel->r_index[2] = h->dynindx >> 16;
2240 srel->r_index[1] = h->dynindx >> 8;
2241 srel->r_index[0] = h->dynindx;
2243 (RELOC_STD_BITS_EXTERN_LITTLE
2244 | RELOC_STD_BITS_BASEREL_LITTLE
2245 | RELOC_STD_BITS_RELATIVE_LITTLE
2246 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2251 struct reloc_ext_external *erel;
2253 erel = (struct reloc_ext_external *) p;
2256 + sgot->output_section->vma
2257 + sgot->output_offset),
2259 if (dynobj->xvec->header_byteorder_big_p)
2261 erel->r_index[0] = h->dynindx >> 16;
2262 erel->r_index[1] = h->dynindx >> 8;
2263 erel->r_index[2] = h->dynindx;
2265 (RELOC_EXT_BITS_EXTERN_BIG
2266 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
2270 erel->r_index[2] = h->dynindx >> 16;
2271 erel->r_index[1] = h->dynindx >> 8;
2272 erel->r_index[0] = h->dynindx;
2274 (RELOC_EXT_BITS_EXTERN_LITTLE
2275 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2277 PUT_WORD (dynobj, 0, erel->r_addend);
2286 *relocationp = sgot->vma + (*got_offsetp &~ 1);
2288 /* There is nothing else to do for a base relative reloc. */
2292 if (! sunos_hash_table (info)->dynamic_sections_needed
2295 || h->root.root.type != bfd_link_hash_undefined
2296 || (h->flags & SUNOS_DEF_REGULAR) != 0
2297 || (h->flags & SUNOS_DEF_DYNAMIC) == 0
2298 || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
2301 /* It looks like this is a reloc we are supposed to copy. */
2303 s = bfd_get_section_by_name (dynobj, ".dynrel");
2304 BFD_ASSERT (s != NULL);
2306 p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
2308 /* Copy the reloc over. */
2309 memcpy (p, reloc, obj_reloc_entry_size (dynobj));
2311 /* Adjust the address and symbol index. */
2312 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2314 struct reloc_std_external *srel;
2316 srel = (struct reloc_std_external *) p;
2318 (GET_WORD (dynobj, srel->r_address)
2319 + input_section->output_section->vma
2320 + input_section->output_offset),
2322 if (dynobj->xvec->header_byteorder_big_p)
2324 srel->r_index[0] = h->dynindx >> 16;
2325 srel->r_index[1] = h->dynindx >> 8;
2326 srel->r_index[2] = h->dynindx;
2330 srel->r_index[2] = h->dynindx >> 16;
2331 srel->r_index[1] = h->dynindx >> 8;
2332 srel->r_index[0] = h->dynindx;
2337 struct reloc_ext_external *erel;
2339 erel = (struct reloc_ext_external *) p;
2341 (GET_WORD (dynobj, erel->r_address)
2342 + input_section->output_section->vma
2343 + input_section->output_offset),
2345 if (dynobj->xvec->header_byteorder_big_p)
2347 erel->r_index[0] = h->dynindx >> 16;
2348 erel->r_index[1] = h->dynindx >> 8;
2349 erel->r_index[2] = h->dynindx;
2353 erel->r_index[2] = h->dynindx >> 16;
2354 erel->r_index[1] = h->dynindx >> 8;
2355 erel->r_index[0] = h->dynindx;
2366 /* Finish up the dynamic linking information. */
2369 sunos_finish_dynamic_link (abfd, info)
2371 struct bfd_link_info *info;
2377 struct external_sun4_dynamic esd;
2378 struct external_sun4_dynamic_link esdl;
2380 if (! sunos_hash_table (info)->dynamic_sections_needed)
2383 dynobj = sunos_hash_table (info)->dynobj;
2385 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2386 BFD_ASSERT (sdyn != NULL);
2388 /* Finish up the .need section. The linker emulation code filled it
2389 in, but with offsets from the start of the section instead of
2390 real addresses. Now that we know the section location, we can
2391 fill in the final values. */
2392 s = bfd_get_section_by_name (dynobj, ".need");
2393 if (s != NULL && s->_raw_size != 0)
2398 filepos = s->output_section->filepos + s->output_offset;
2404 PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
2405 val = GET_WORD (dynobj, p + 12);
2408 PUT_WORD (dynobj, val + filepos, p + 12);
2413 /* The first entry in the .got section is the address of the dynamic
2415 s = bfd_get_section_by_name (dynobj, ".got");
2416 BFD_ASSERT (s != NULL);
2417 PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
2420 for (o = dynobj->sections; o != NULL; o = o->next)
2422 if ((o->flags & SEC_HAS_CONTENTS) != 0
2423 && o->contents != NULL)
2425 BFD_ASSERT (o->output_section != NULL
2426 && o->output_section->owner == abfd);
2427 if (! bfd_set_section_contents (abfd, o->output_section,
2428 o->contents, o->output_offset,
2434 /* Finish up the dynamic link information. */
2435 PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
2437 sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
2440 (sdyn->output_section->vma
2441 + sdyn->output_offset
2443 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2446 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
2447 sdyn->output_offset, sizeof esd))
2451 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
2453 s = bfd_get_section_by_name (dynobj, ".need");
2454 if (s == NULL || s->_raw_size == 0)
2455 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
2457 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2460 s = bfd_get_section_by_name (dynobj, ".rules");
2461 if (s == NULL || s->_raw_size == 0)
2462 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
2464 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2467 s = bfd_get_section_by_name (dynobj, ".got");
2468 BFD_ASSERT (s != NULL);
2469 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
2471 s = bfd_get_section_by_name (dynobj, ".plt");
2472 BFD_ASSERT (s != NULL);
2473 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
2474 PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
2476 s = bfd_get_section_by_name (dynobj, ".dynrel");
2477 BFD_ASSERT (s != NULL);
2478 BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
2479 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2482 s = bfd_get_section_by_name (dynobj, ".hash");
2483 BFD_ASSERT (s != NULL);
2484 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2487 s = bfd_get_section_by_name (dynobj, ".dynsym");
2488 BFD_ASSERT (s != NULL);
2489 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2492 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
2494 PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
2497 s = bfd_get_section_by_name (dynobj, ".dynstr");
2498 BFD_ASSERT (s != NULL);
2499 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2501 PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
2503 /* The size of the text area is the size of the .text section
2504 rounded up to a page boundary. FIXME: Should the page size be
2505 conditional on something? */
2507 BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
2510 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
2511 (sdyn->output_offset
2513 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2517 abfd->flags |= DYNAMIC;