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->plt_offset != 0
1430 || ((h->root.root.type == bfd_link_hash_defined
1431 || h->root.root.type == bfd_link_hash_defweak)
1432 ? (h->root.root.u.def.section->owner->flags
1434 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1436 /* This reloc is against a symbol defined only by a dynamic
1439 if (h->root.root.type == bfd_link_hash_undefined)
1441 /* Presumably this symbol was marked as being undefined by
1442 an earlier reloc. */
1443 srel->_raw_size += RELOC_STD_SIZE;
1445 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1449 /* This reloc is not in the .text section. It must be
1450 copied into the dynamic relocs. We mark the symbol as
1452 srel->_raw_size += RELOC_STD_SIZE;
1453 sub = h->root.root.u.def.section->owner;
1454 h->root.root.type = bfd_link_hash_undefined;
1455 h->root.root.u.undef.abfd = sub;
1459 /* This symbol is in the .text section. We must give it an
1460 entry in the procedure linkage table, if we have not
1461 already done so. We change the definition of the symbol
1462 to the .plt section; this will cause relocs against it to
1463 be handled correctly. */
1464 if (h->plt_offset == 0)
1466 if (splt->_raw_size == 0)
1467 splt->_raw_size = M68K_PLT_ENTRY_SIZE;
1468 h->plt_offset = splt->_raw_size;
1470 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1472 h->root.root.u.def.section = splt;
1473 h->root.root.u.def.value = splt->_raw_size;
1476 splt->_raw_size += M68K_PLT_ENTRY_SIZE;
1478 /* We may also need a dynamic reloc entry. */
1479 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1480 srel->_raw_size += RELOC_STD_SIZE;
1488 /* Scan the relocs for an input section using extended relocs. We
1489 need to figure out what to do for each reloc against a dynamic
1490 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1491 section, an entry is made in the procedure linkage table.
1492 Otherwise, we must preserve the reloc as a dynamic reloc. */
1495 sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
1496 struct bfd_link_info *info;
1499 const struct reloc_ext_external *relocs;
1500 bfd_size_type rel_size;
1503 struct sunos_link_hash_entry **sym_hashes;
1504 const struct reloc_ext_external *rel, *relend;
1505 asection *splt = NULL;
1506 asection *sgot = NULL;
1507 asection *srel = NULL;
1509 /* We only know how to handle SPARC plt entries. */
1510 if (bfd_get_arch (abfd) != bfd_arch_sparc)
1512 bfd_set_error (bfd_error_invalid_target);
1518 sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
1520 relend = relocs + rel_size / RELOC_EXT_SIZE;
1521 for (rel = relocs; rel < relend; rel++)
1526 struct sunos_link_hash_entry *h = NULL;
1528 /* Swap in the reloc information. */
1529 if (abfd->xvec->header_byteorder_big_p)
1531 r_index = ((rel->r_index[0] << 16)
1532 | (rel->r_index[1] << 8)
1534 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1535 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1536 >> RELOC_EXT_BITS_TYPE_SH_BIG);
1540 r_index = ((rel->r_index[2] << 16)
1541 | (rel->r_index[1] << 8)
1543 r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1544 r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1545 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
1550 h = sym_hashes[r_index];
1553 /* This should not normally happen, but it will in any
1554 case be caught in the relocation phase. */
1560 if (r_index >= bfd_get_symcount (abfd))
1562 /* This is abnormal, but should be caught in the
1563 relocation phase. */
1568 /* If this is a base relative reloc, we need to make an entry in
1569 the .got section. */
1570 if (r_type == RELOC_BASE10
1571 || r_type == RELOC_BASE13
1572 || r_type == RELOC_BASE22)
1576 if (! sunos_create_dynamic_sections (abfd, info, true))
1578 dynobj = sunos_hash_table (info)->dynobj;
1579 splt = bfd_get_section_by_name (dynobj, ".plt");
1580 sgot = bfd_get_section_by_name (dynobj, ".got");
1581 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1582 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1587 if (h->got_offset != 0)
1590 h->got_offset = sgot->_raw_size;
1594 if (adata (abfd).local_got_offsets == NULL)
1596 adata (abfd).local_got_offsets =
1597 (bfd_vma *) bfd_zalloc (abfd,
1598 (bfd_get_symcount (abfd)
1599 * sizeof (bfd_vma)));
1600 if (adata (abfd).local_got_offsets == NULL)
1602 bfd_set_error (bfd_error_no_memory);
1607 if (adata (abfd).local_got_offsets[r_index] != 0)
1610 adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
1613 sgot->_raw_size += BYTES_IN_WORD;
1615 /* If we are making a shared library, or if the symbol is
1616 defined by a dynamic object, we will need a dynamic reloc
1620 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1621 && (h->flags & SUNOS_DEF_REGULAR) == 0))
1622 srel->_raw_size += RELOC_EXT_SIZE;
1627 /* Otherwise, we are only interested in relocs against symbols
1628 defined in dynamic objects but not in regular objects. We
1629 only need to consider relocs against external symbols. */
1633 /* At this point common symbols have already been allocated, so
1634 we don't have to worry about them. We need to consider that
1635 we may have already seen this symbol and marked it undefined;
1636 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1638 if (h->root.root.type != bfd_link_hash_defined
1639 && h->root.root.type != bfd_link_hash_defweak
1640 && h->root.root.type != bfd_link_hash_undefined)
1643 if (r_type != RELOC_JMP_TBL
1644 && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
1645 || (h->flags & SUNOS_DEF_REGULAR) != 0))
1648 if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1653 if (! sunos_create_dynamic_sections (abfd, info, true))
1655 dynobj = sunos_hash_table (info)->dynobj;
1656 splt = bfd_get_section_by_name (dynobj, ".plt");
1657 sgot = bfd_get_section_by_name (dynobj, ".got");
1658 srel = bfd_get_section_by_name (dynobj, ".dynrel");
1659 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
1662 BFD_ASSERT (r_type == RELOC_JMP_TBL
1663 || (h->flags & SUNOS_REF_REGULAR) != 0);
1664 BFD_ASSERT (r_type == RELOC_JMP_TBL
1665 || h->plt_offset != 0
1666 || ((h->root.root.type == bfd_link_hash_defined
1667 || h->root.root.type == bfd_link_hash_defweak)
1668 ? (h->root.root.u.def.section->owner->flags
1670 : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
1672 /* This reloc is against a symbol defined only by a dynamic
1673 object, or it is a jump table reloc from PIC compiled code. */
1675 if (h->root.root.type == bfd_link_hash_undefined)
1677 /* Presumably this symbol was marked as being undefined by
1678 an earlier reloc. */
1679 srel->_raw_size += RELOC_EXT_SIZE;
1681 else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
1685 /* This reloc is not in the .text section. It must be
1686 copied into the dynamic relocs. We mark the symbol as
1688 BFD_ASSERT (r_type != RELOC_JMP_TBL);
1689 srel->_raw_size += RELOC_EXT_SIZE;
1690 sub = h->root.root.u.def.section->owner;
1691 h->root.root.type = bfd_link_hash_undefined;
1692 h->root.root.u.undef.abfd = sub;
1696 /* This symbol is in the .text section. We must give it an
1697 entry in the procedure linkage table, if we have not
1698 already done so. We change the definition of the symbol
1699 to the .plt section; this will cause relocs against it to
1700 be handled correctly. */
1701 if (h->plt_offset == 0)
1703 if (splt->_raw_size == 0)
1704 splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
1705 h->plt_offset = splt->_raw_size;
1707 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1709 h->root.root.u.def.section = splt;
1710 h->root.root.u.def.value = splt->_raw_size;
1713 splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
1715 /* We will also need a dynamic reloc entry, unless this
1716 is a JMP_TBL reloc produced by linking PIC compiled
1717 code, and we are not making a shared library. */
1718 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1719 srel->_raw_size += RELOC_EXT_SIZE;
1727 /* Build the hash table of dynamic symbols, and to mark as written all
1728 symbols from dynamic objects which we do not plan to write out. */
1731 sunos_scan_dynamic_symbol (h, data)
1732 struct sunos_link_hash_entry *h;
1735 struct bfd_link_info *info = (struct bfd_link_info *) data;
1737 /* Set the written flag for symbols we do not want to write out as
1738 part of the regular symbol table. This is all symbols which are
1739 not defined in a regular object file. For some reason symbols
1740 which are referenced by a regular object and defined by a dynamic
1741 object do not seem to show up in the regular symbol table. */
1742 if ((h->flags & SUNOS_DEF_REGULAR) == 0)
1743 h->root.written = true;
1745 /* If this symbol is defined by a dynamic object and referenced by a
1746 regular object, see whether we gave it a reasonable value while
1747 scanning the relocs. */
1749 if ((h->flags & SUNOS_DEF_REGULAR) == 0
1750 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
1751 && (h->flags & SUNOS_REF_REGULAR) != 0)
1753 if ((h->root.root.type == bfd_link_hash_defined
1754 || h->root.root.type == bfd_link_hash_defweak)
1755 && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
1756 && h->root.root.u.def.section->output_section == NULL)
1760 /* This symbol is currently defined in a dynamic section
1761 which is not being put into the output file. This
1762 implies that there is no reloc against the symbol. I'm
1763 not sure why this case would ever occur. In any case, we
1764 change the symbol to be undefined. */
1765 sub = h->root.root.u.def.section->owner;
1766 h->root.root.type = bfd_link_hash_undefined;
1767 h->root.root.u.undef.abfd = sub;
1771 /* If this symbol is defined or referenced by a regular file, add it
1772 to the dynamic symbols. */
1773 if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
1778 unsigned char *name;
1782 BFD_ASSERT (h->dynindx == -2);
1784 dynobj = sunos_hash_table (info)->dynobj;
1786 h->dynindx = sunos_hash_table (info)->dynsymcount;
1787 ++sunos_hash_table (info)->dynsymcount;
1789 len = strlen (h->root.root.root.string);
1791 /* We don't bother to construct a BFD hash table for the strings
1792 which are the names of the dynamic symbols. Using a hash
1793 table for the regular symbols is beneficial, because the
1794 regular symbols includes the debugging symbols, which have
1795 long names and are often duplicated in several object files.
1796 There are no debugging symbols in the dynamic symbols. */
1797 s = bfd_get_section_by_name (dynobj, ".dynstr");
1798 BFD_ASSERT (s != NULL);
1799 if (s->contents == NULL)
1800 contents = (bfd_byte *) malloc (len + 1);
1802 contents = (bfd_byte *) realloc (s->contents,
1803 (size_t) (s->_raw_size + len + 1));
1804 if (contents == NULL)
1806 bfd_set_error (bfd_error_no_memory);
1809 s->contents = contents;
1811 h->dynstr_index = s->_raw_size;
1812 strcpy (contents + s->_raw_size, h->root.root.root.string);
1813 s->_raw_size += len + 1;
1815 /* Add it to the dynamic hash table. */
1816 name = (unsigned char *) h->root.root.root.string;
1818 while (*name != '\0')
1819 hash = (hash << 1) + *name++;
1821 hash %= sunos_hash_table (info)->bucketcount;
1823 s = bfd_get_section_by_name (dynobj, ".hash");
1824 BFD_ASSERT (s != NULL);
1826 if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
1827 PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
1832 next = GET_WORD (dynobj,
1834 + hash * HASH_ENTRY_SIZE
1836 PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
1837 s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
1838 PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
1839 PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
1840 s->_raw_size += HASH_ENTRY_SIZE;
1847 /* Link a dynamic object. We actually don't have anything to do at
1848 this point. This entry point exists to prevent the regular linker
1849 code from doing anything with the object. */
1853 sunos_link_dynamic_object (info, abfd)
1854 struct bfd_link_info *info;
1860 /* Write out a dynamic symbol. This is called by the final traversal
1861 over the symbol table. */
1864 sunos_write_dynamic_symbol (output_bfd, info, harg)
1866 struct bfd_link_info *info;
1867 struct aout_link_hash_entry *harg;
1869 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
1873 struct external_nlist *outsym;
1878 switch (h->root.root.type)
1881 case bfd_link_hash_new:
1883 /* Avoid variable not initialized warnings. */
1885 case bfd_link_hash_undefined:
1886 type = N_UNDF | N_EXT;
1889 case bfd_link_hash_defined:
1890 case bfd_link_hash_defweak:
1893 asection *output_section;
1895 sec = h->root.root.u.def.section;
1896 output_section = sec->output_section;
1897 BFD_ASSERT (bfd_is_abs_section (output_section)
1898 || output_section->owner == output_bfd);
1899 if (h->plt_offset != 0
1900 && (h->flags & SUNOS_DEF_REGULAR) == 0)
1902 type = N_UNDF | N_EXT;
1907 if (output_section == obj_textsec (output_bfd))
1908 type = (h->root.root.type == bfd_link_hash_defined
1911 else if (output_section == obj_datasec (output_bfd))
1912 type = (h->root.root.type == bfd_link_hash_defined
1915 else if (output_section == obj_bsssec (output_bfd))
1916 type = (h->root.root.type == bfd_link_hash_defined
1920 type = (h->root.root.type == bfd_link_hash_defined
1924 val = (h->root.root.u.def.value
1925 + output_section->vma
1926 + sec->output_offset);
1930 case bfd_link_hash_common:
1931 type = N_UNDF | N_EXT;
1932 val = h->root.root.u.c.size;
1934 case bfd_link_hash_undefweak:
1938 case bfd_link_hash_indirect:
1939 case bfd_link_hash_warning:
1940 /* FIXME: Ignore these for now. The circumstances under which
1941 they should be written out are not clear to me. */
1945 s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
1946 BFD_ASSERT (s != NULL);
1947 outsym = ((struct external_nlist *)
1948 (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
1950 bfd_h_put_8 (output_bfd, type, outsym->e_type);
1951 bfd_h_put_8 (output_bfd, 0, outsym->e_other);
1953 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
1954 one less than the desc value in the shared library, although that
1956 bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
1958 PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
1959 PUT_WORD (output_bfd, val, outsym->e_value);
1961 /* If this symbol is in the procedure linkage table, fill in the
1963 if (h->plt_offset != 0)
1971 dynobj = sunos_hash_table (info)->dynobj;
1972 splt = bfd_get_section_by_name (dynobj, ".plt");
1973 p = splt->contents + h->plt_offset;
1975 s = bfd_get_section_by_name (dynobj, ".dynrel");
1977 r_address = (h->root.root.u.def.section->output_section->vma
1978 + h->root.root.u.def.section->output_offset
1979 + h->root.root.u.def.value);
1981 switch (bfd_get_arch (output_bfd))
1983 case bfd_arch_sparc:
1984 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
1986 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
1987 bfd_put_32 (output_bfd,
1988 (SPARC_PLT_ENTRY_WORD1
1989 + (((- (h->plt_offset + 4) >> 2)
1992 bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
1999 val = (h->root.root.u.def.section->output_section->vma
2000 + h->root.root.u.def.section->output_offset
2001 + h->root.root.u.def.value);
2002 bfd_put_32 (output_bfd,
2003 SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
2005 bfd_put_32 (output_bfd,
2006 SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
2008 bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
2013 if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
2015 bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
2016 bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
2017 bfd_put_16 (output_bfd, s->reloc_count, p + 6);
2025 /* We also need to add a jump table reloc, unless this is the
2026 result of a JMP_TBL reloc from PIC compiled code. */
2027 if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
2029 p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
2030 if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
2032 struct reloc_std_external *srel;
2034 srel = (struct reloc_std_external *) p;
2035 PUT_WORD (output_bfd, r_address, srel->r_address);
2036 if (output_bfd->xvec->header_byteorder_big_p)
2038 srel->r_index[0] = h->dynindx >> 16;
2039 srel->r_index[1] = h->dynindx >> 8;
2040 srel->r_index[2] = h->dynindx;
2041 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
2042 | RELOC_STD_BITS_JMPTABLE_BIG);
2046 srel->r_index[2] = h->dynindx >> 16;
2047 srel->r_index[1] = h->dynindx >> 8;
2048 srel->r_index[0] = h->dynindx;
2049 srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2050 | RELOC_STD_BITS_JMPTABLE_LITTLE);
2055 struct reloc_ext_external *erel;
2057 erel = (struct reloc_ext_external *) p;
2058 PUT_WORD (output_bfd, r_address, erel->r_address);
2059 if (output_bfd->xvec->header_byteorder_big_p)
2061 erel->r_index[0] = h->dynindx >> 16;
2062 erel->r_index[1] = h->dynindx >> 8;
2063 erel->r_index[2] = h->dynindx;
2064 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_BIG
2065 | (22 << RELOC_EXT_BITS_TYPE_SH_BIG));
2069 erel->r_index[2] = h->dynindx >> 16;
2070 erel->r_index[1] = h->dynindx >> 8;
2071 erel->r_index[0] = h->dynindx;
2072 erel->r_type[0] = (RELOC_EXT_BITS_EXTERN_LITTLE
2073 | (22 << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2075 PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
2085 /* This is called for each reloc against an external symbol. If this
2086 is a reloc which are are going to copy as a dynamic reloc, then
2087 copy it over, and tell the caller to not bother processing this
2092 sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
2093 contents, skip, relocationp)
2094 struct bfd_link_info *info;
2096 asection *input_section;
2097 struct aout_link_hash_entry *harg;
2101 bfd_vma *relocationp;
2103 struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
2111 dynobj = sunos_hash_table (info)->dynobj;
2113 if (h != NULL && h->plt_offset != 0)
2117 /* Redirect the relocation to the PLT entry. */
2118 splt = bfd_get_section_by_name (dynobj, ".plt");
2119 *relocationp = (splt->output_section->vma
2120 + splt->output_offset
2124 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2126 struct reloc_std_external *srel;
2128 srel = (struct reloc_std_external *) reloc;
2129 if (input_bfd->xvec->header_byteorder_big_p)
2130 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
2132 baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
2136 struct reloc_ext_external *erel;
2139 erel = (struct reloc_ext_external *) reloc;
2140 if (input_bfd->xvec->header_byteorder_big_p)
2141 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
2142 >> RELOC_EXT_BITS_TYPE_SH_BIG);
2144 r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
2145 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
2146 baserel = (r_type == RELOC_BASE10
2147 || r_type == RELOC_BASE13
2148 || r_type == RELOC_BASE22);
2153 bfd_vma *got_offsetp;
2157 got_offsetp = &h->got_offset;
2158 else if (adata (input_bfd).local_got_offsets == NULL)
2162 struct reloc_std_external *srel;
2165 srel = (struct reloc_std_external *) reloc;
2166 if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
2168 if (input_bfd->xvec->header_byteorder_big_p)
2169 r_index = ((srel->r_index[0] << 16)
2170 | (srel->r_index[1] << 8)
2171 | srel->r_index[2]);
2173 r_index = ((srel->r_index[2] << 16)
2174 | (srel->r_index[1] << 8)
2175 | srel->r_index[0]);
2179 struct reloc_ext_external *erel;
2181 erel = (struct reloc_ext_external *) reloc;
2182 if (input_bfd->xvec->header_byteorder_big_p)
2183 r_index = ((erel->r_index[0] << 16)
2184 | (erel->r_index[1] << 8)
2185 | erel->r_index[2]);
2187 r_index = ((erel->r_index[2] << 16)
2188 | (erel->r_index[1] << 8)
2189 | erel->r_index[0]);
2192 got_offsetp = adata (input_bfd).local_got_offsets + r_index;
2195 BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
2197 sgot = bfd_get_section_by_name (dynobj, ".got");
2199 /* We set the least significant bit to indicate whether we have
2200 already initialized the GOT entry. */
2201 if ((*got_offsetp & 1) == 0)
2203 PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
2206 && (h->flags & SUNOS_DEF_DYNAMIC) != 0
2207 && (h->flags & SUNOS_DEF_REGULAR) == 0)
2209 /* We need to create a GLOB_DAT reloc to tell the
2210 dynamic linker to fill in this entry in the table. */
2212 s = bfd_get_section_by_name (dynobj, ".dynrel");
2213 BFD_ASSERT (s != NULL);
2216 + s->reloc_count * obj_reloc_entry_size (dynobj));
2218 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2220 struct reloc_std_external *srel;
2222 srel = (struct reloc_std_external *) p;
2225 + sgot->output_section->vma
2226 + sgot->output_offset),
2228 if (dynobj->xvec->header_byteorder_big_p)
2230 srel->r_index[0] = h->dynindx >> 16;
2231 srel->r_index[1] = h->dynindx >> 8;
2232 srel->r_index[2] = h->dynindx;
2234 (RELOC_STD_BITS_EXTERN_BIG
2235 | RELOC_STD_BITS_BASEREL_BIG
2236 | RELOC_STD_BITS_RELATIVE_BIG
2237 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
2241 srel->r_index[2] = h->dynindx >> 16;
2242 srel->r_index[1] = h->dynindx >> 8;
2243 srel->r_index[0] = h->dynindx;
2245 (RELOC_STD_BITS_EXTERN_LITTLE
2246 | RELOC_STD_BITS_BASEREL_LITTLE
2247 | RELOC_STD_BITS_RELATIVE_LITTLE
2248 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
2253 struct reloc_ext_external *erel;
2255 erel = (struct reloc_ext_external *) p;
2258 + sgot->output_section->vma
2259 + sgot->output_offset),
2261 if (dynobj->xvec->header_byteorder_big_p)
2263 erel->r_index[0] = h->dynindx >> 16;
2264 erel->r_index[1] = h->dynindx >> 8;
2265 erel->r_index[2] = h->dynindx;
2267 (RELOC_EXT_BITS_EXTERN_BIG
2268 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
2272 erel->r_index[2] = h->dynindx >> 16;
2273 erel->r_index[1] = h->dynindx >> 8;
2274 erel->r_index[0] = h->dynindx;
2276 (RELOC_EXT_BITS_EXTERN_LITTLE
2277 | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
2279 PUT_WORD (dynobj, 0, erel->r_addend);
2288 *relocationp = sgot->vma + (*got_offsetp &~ 1);
2290 /* There is nothing else to do for a base relative reloc. */
2294 if (! sunos_hash_table (info)->dynamic_sections_needed
2297 || h->root.root.type != bfd_link_hash_undefined
2298 || (h->flags & SUNOS_DEF_REGULAR) != 0
2299 || (h->flags & SUNOS_DEF_DYNAMIC) == 0
2300 || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
2303 /* It looks like this is a reloc we are supposed to copy. */
2305 s = bfd_get_section_by_name (dynobj, ".dynrel");
2306 BFD_ASSERT (s != NULL);
2308 p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
2310 /* Copy the reloc over. */
2311 memcpy (p, reloc, obj_reloc_entry_size (dynobj));
2313 /* Adjust the address and symbol index. */
2314 if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
2316 struct reloc_std_external *srel;
2318 srel = (struct reloc_std_external *) p;
2320 (GET_WORD (dynobj, srel->r_address)
2321 + input_section->output_section->vma
2322 + input_section->output_offset),
2324 if (dynobj->xvec->header_byteorder_big_p)
2326 srel->r_index[0] = h->dynindx >> 16;
2327 srel->r_index[1] = h->dynindx >> 8;
2328 srel->r_index[2] = h->dynindx;
2332 srel->r_index[2] = h->dynindx >> 16;
2333 srel->r_index[1] = h->dynindx >> 8;
2334 srel->r_index[0] = h->dynindx;
2339 struct reloc_ext_external *erel;
2341 erel = (struct reloc_ext_external *) p;
2343 (GET_WORD (dynobj, erel->r_address)
2344 + input_section->output_section->vma
2345 + input_section->output_offset),
2347 if (dynobj->xvec->header_byteorder_big_p)
2349 erel->r_index[0] = h->dynindx >> 16;
2350 erel->r_index[1] = h->dynindx >> 8;
2351 erel->r_index[2] = h->dynindx;
2355 erel->r_index[2] = h->dynindx >> 16;
2356 erel->r_index[1] = h->dynindx >> 8;
2357 erel->r_index[0] = h->dynindx;
2368 /* Finish up the dynamic linking information. */
2371 sunos_finish_dynamic_link (abfd, info)
2373 struct bfd_link_info *info;
2379 struct external_sun4_dynamic esd;
2380 struct external_sun4_dynamic_link esdl;
2382 if (! sunos_hash_table (info)->dynamic_sections_needed)
2385 dynobj = sunos_hash_table (info)->dynobj;
2387 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2388 BFD_ASSERT (sdyn != NULL);
2390 /* Finish up the .need section. The linker emulation code filled it
2391 in, but with offsets from the start of the section instead of
2392 real addresses. Now that we know the section location, we can
2393 fill in the final values. */
2394 s = bfd_get_section_by_name (dynobj, ".need");
2395 if (s != NULL && s->_raw_size != 0)
2400 filepos = s->output_section->filepos + s->output_offset;
2406 PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
2407 val = GET_WORD (dynobj, p + 12);
2410 PUT_WORD (dynobj, val + filepos, p + 12);
2415 /* The first entry in the .got section is the address of the dynamic
2417 s = bfd_get_section_by_name (dynobj, ".got");
2418 BFD_ASSERT (s != NULL);
2419 PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
2422 for (o = dynobj->sections; o != NULL; o = o->next)
2424 if ((o->flags & SEC_HAS_CONTENTS) != 0
2425 && o->contents != NULL)
2427 BFD_ASSERT (o->output_section != NULL
2428 && o->output_section->owner == abfd);
2429 if (! bfd_set_section_contents (abfd, o->output_section,
2430 o->contents, o->output_offset,
2436 /* Finish up the dynamic link information. */
2437 PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
2439 sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
2442 (sdyn->output_section->vma
2443 + sdyn->output_offset
2445 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2448 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
2449 sdyn->output_offset, sizeof esd))
2453 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
2455 s = bfd_get_section_by_name (dynobj, ".need");
2456 if (s == NULL || s->_raw_size == 0)
2457 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
2459 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2462 s = bfd_get_section_by_name (dynobj, ".rules");
2463 if (s == NULL || s->_raw_size == 0)
2464 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
2466 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2469 s = bfd_get_section_by_name (dynobj, ".got");
2470 BFD_ASSERT (s != NULL);
2471 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
2473 s = bfd_get_section_by_name (dynobj, ".plt");
2474 BFD_ASSERT (s != NULL);
2475 PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
2476 PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
2478 s = bfd_get_section_by_name (dynobj, ".dynrel");
2479 BFD_ASSERT (s != NULL);
2480 BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
2481 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2484 s = bfd_get_section_by_name (dynobj, ".hash");
2485 BFD_ASSERT (s != NULL);
2486 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2489 s = bfd_get_section_by_name (dynobj, ".dynsym");
2490 BFD_ASSERT (s != NULL);
2491 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2494 PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
2496 PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
2499 s = bfd_get_section_by_name (dynobj, ".dynstr");
2500 BFD_ASSERT (s != NULL);
2501 PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
2503 PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
2505 /* The size of the text area is the size of the .text section
2506 rounded up to a page boundary. FIXME: Should the page size be
2507 conditional on something? */
2509 BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
2512 if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
2513 (sdyn->output_offset
2515 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
2519 abfd->flags |= DYNAMIC;