1 /* BFD backend for SunOS binaries.
2 Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define TARGETNAME "a.out-sunos-big"
25 /* Do not "beautify" the CONCAT* macro args. Traditional C will not
26 remove whitespace added here, and thus will fail to concatenate
28 #define MY(OP) CONCAT2 (sunos_big_,OP)
34 /* Static routines defined in this file. */
36 static boolean sunos_read_dynamic_info
PARAMS ((bfd
*));
37 static long sunos_get_dynamic_symtab_upper_bound
PARAMS ((bfd
*));
38 static boolean sunos_slurp_dynamic_symtab
PARAMS ((bfd
*));
39 static long sunos_canonicalize_dynamic_symtab
PARAMS ((bfd
*, asymbol
**));
40 static long sunos_get_dynamic_reloc_upper_bound
PARAMS ((bfd
*));
41 static long sunos_canonicalize_dynamic_reloc
42 PARAMS ((bfd
*, arelent
**, asymbol
**));
43 static struct bfd_hash_entry
*sunos_link_hash_newfunc
44 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
45 static struct bfd_link_hash_table
*sunos_link_hash_table_create
47 static boolean sunos_create_dynamic_sections
48 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
));
49 static boolean sunos_add_dynamic_symbols
50 PARAMS ((bfd
*, struct bfd_link_info
*, struct external_nlist
**,
51 bfd_size_type
*, char **));
52 static boolean sunos_add_one_symbol
53 PARAMS ((struct bfd_link_info
*, bfd
*, const char *, flagword
, asection
*,
54 bfd_vma
, const char *, boolean
, boolean
,
55 struct bfd_link_hash_entry
**));
56 static boolean sunos_scan_relocs
57 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*, bfd_size_type
));
58 static boolean sunos_scan_std_relocs
59 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
60 const struct reloc_std_external
*, bfd_size_type
));
61 static boolean sunos_scan_ext_relocs
62 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
63 const struct reloc_ext_external
*, bfd_size_type
));
64 static boolean sunos_link_dynamic_object
65 PARAMS ((struct bfd_link_info
*, bfd
*));
66 static boolean sunos_write_dynamic_symbol
67 PARAMS ((bfd
*, struct bfd_link_info
*, struct aout_link_hash_entry
*));
68 static boolean sunos_check_dynamic_reloc
69 PARAMS ((struct bfd_link_info
*, bfd
*, asection
*,
70 struct aout_link_hash_entry
*, PTR
, bfd_byte
*, boolean
*,
72 static boolean sunos_finish_dynamic_link
73 PARAMS ((bfd
*, struct bfd_link_info
*));
75 #define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound
76 #define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab
77 #define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound
78 #define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc
79 #define MY_bfd_link_hash_table_create sunos_link_hash_table_create
80 #define MY_add_dynamic_symbols sunos_add_dynamic_symbols
81 #define MY_add_one_symbol sunos_add_one_symbol
82 #define MY_link_dynamic_object sunos_link_dynamic_object
83 #define MY_write_dynamic_symbol sunos_write_dynamic_symbol
84 #define MY_check_dynamic_reloc sunos_check_dynamic_reloc
85 #define MY_finish_dynamic_link sunos_finish_dynamic_link
87 /* ??? Where should this go? */
88 #define MACHTYPE_OK(mtype) \
89 (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
90 || ((mtype) == M_SPARCLET \
91 && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
92 || ((mtype) == M_SPARCLITE_LE \
93 && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
94 || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
95 && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
97 /* Include the usual a.out support. */
100 /* The SunOS 4.1.4 /usr/include/locale.h defines valid as a macro. */
103 /* SunOS shared library support. We store a pointer to this structure
104 in obj_aout_dynamic_info (abfd). */
106 struct sunos_dynamic_info
108 /* Whether we found any dynamic information. */
110 /* Dynamic information. */
111 struct internal_sun4_dynamic_link dyninfo
;
112 /* Number of dynamic symbols. */
113 unsigned long dynsym_count
;
114 /* Read in nlists for dynamic symbols. */
115 struct external_nlist
*dynsym
;
116 /* asymbol structures for dynamic symbols. */
117 aout_symbol_type
*canonical_dynsym
;
118 /* Read in dynamic string table. */
120 /* Number of dynamic relocs. */
121 unsigned long dynrel_count
;
122 /* Read in dynamic relocs. This may be reloc_std_external or
123 reloc_ext_external. */
125 /* arelent structures for dynamic relocs. */
126 arelent
*canonical_dynrel
;
129 /* The hash table of dynamic symbols is composed of two word entries.
130 See include/aout/sun4.h for details. */
132 #define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
134 /* Read in the basic dynamic information. This locates the __DYNAMIC
135 structure and uses it to find the dynamic_link structure. It
136 creates and saves a sunos_dynamic_info structure. If it can't find
137 __DYNAMIC, it sets the valid field of the sunos_dynamic_info
138 structure to false to avoid doing this work again. */
141 sunos_read_dynamic_info (abfd
)
144 struct sunos_dynamic_info
*info
;
147 struct external_sun4_dynamic dyninfo
;
148 unsigned long dynver
;
149 struct external_sun4_dynamic_link linkinfo
;
152 if (obj_aout_dynamic_info (abfd
) != (PTR
) NULL
)
155 if ((abfd
->flags
& DYNAMIC
) == 0)
157 bfd_set_error (bfd_error_invalid_operation
);
161 amt
= sizeof (struct sunos_dynamic_info
);
162 info
= (struct sunos_dynamic_info
*) bfd_zalloc (abfd
, amt
);
168 info
->canonical_dynsym
= NULL
;
170 info
->canonical_dynrel
= NULL
;
171 obj_aout_dynamic_info (abfd
) = (PTR
) info
;
173 /* This code used to look for the __DYNAMIC symbol to locate the dynamic
175 However this inhibits recovering the dynamic symbols from a
176 stripped object file, so blindly assume that the dynamic linking
177 information is located at the start of the data section.
178 We could verify this assumption later by looking through the dynamic
179 symbols for the __DYNAMIC symbol. */
180 if ((abfd
->flags
& DYNAMIC
) == 0)
182 if (! bfd_get_section_contents (abfd
, obj_datasec (abfd
), (PTR
) &dyninfo
,
184 (bfd_size_type
) sizeof dyninfo
))
187 dynver
= GET_WORD (abfd
, dyninfo
.ld_version
);
188 if (dynver
!= 2 && dynver
!= 3)
191 dynoff
= GET_WORD (abfd
, dyninfo
.ld
);
193 /* dynoff is a virtual address. It is probably always in the .data
194 section, but this code should work even if it moves. */
195 if (dynoff
< bfd_get_section_vma (abfd
, obj_datasec (abfd
)))
196 dynsec
= obj_textsec (abfd
);
198 dynsec
= obj_datasec (abfd
);
199 dynoff
-= bfd_get_section_vma (abfd
, dynsec
);
200 if (dynoff
> bfd_section_size (abfd
, dynsec
))
203 /* This executable appears to be dynamically linked in a way that we
205 if (! bfd_get_section_contents (abfd
, dynsec
, (PTR
) &linkinfo
,
207 (bfd_size_type
) sizeof linkinfo
))
210 /* Swap in the dynamic link information. */
211 info
->dyninfo
.ld_loaded
= GET_WORD (abfd
, linkinfo
.ld_loaded
);
212 info
->dyninfo
.ld_need
= GET_WORD (abfd
, linkinfo
.ld_need
);
213 info
->dyninfo
.ld_rules
= GET_WORD (abfd
, linkinfo
.ld_rules
);
214 info
->dyninfo
.ld_got
= GET_WORD (abfd
, linkinfo
.ld_got
);
215 info
->dyninfo
.ld_plt
= GET_WORD (abfd
, linkinfo
.ld_plt
);
216 info
->dyninfo
.ld_rel
= GET_WORD (abfd
, linkinfo
.ld_rel
);
217 info
->dyninfo
.ld_hash
= GET_WORD (abfd
, linkinfo
.ld_hash
);
218 info
->dyninfo
.ld_stab
= GET_WORD (abfd
, linkinfo
.ld_stab
);
219 info
->dyninfo
.ld_stab_hash
= GET_WORD (abfd
, linkinfo
.ld_stab_hash
);
220 info
->dyninfo
.ld_buckets
= GET_WORD (abfd
, linkinfo
.ld_buckets
);
221 info
->dyninfo
.ld_symbols
= GET_WORD (abfd
, linkinfo
.ld_symbols
);
222 info
->dyninfo
.ld_symb_size
= GET_WORD (abfd
, linkinfo
.ld_symb_size
);
223 info
->dyninfo
.ld_text
= GET_WORD (abfd
, linkinfo
.ld_text
);
224 info
->dyninfo
.ld_plt_sz
= GET_WORD (abfd
, linkinfo
.ld_plt_sz
);
226 /* Reportedly the addresses need to be offset by the size of the
227 exec header in an NMAGIC file. */
228 if (adata (abfd
).magic
== n_magic
)
230 unsigned long exec_bytes_size
= adata (abfd
).exec_bytes_size
;
232 info
->dyninfo
.ld_need
+= exec_bytes_size
;
233 info
->dyninfo
.ld_rules
+= exec_bytes_size
;
234 info
->dyninfo
.ld_rel
+= exec_bytes_size
;
235 info
->dyninfo
.ld_hash
+= exec_bytes_size
;
236 info
->dyninfo
.ld_stab
+= exec_bytes_size
;
237 info
->dyninfo
.ld_symbols
+= exec_bytes_size
;
240 /* The only way to get the size of the symbol information appears to
241 be to determine the distance between it and the string table. */
242 info
->dynsym_count
= ((info
->dyninfo
.ld_symbols
- info
->dyninfo
.ld_stab
)
243 / EXTERNAL_NLIST_SIZE
);
244 BFD_ASSERT (info
->dynsym_count
* EXTERNAL_NLIST_SIZE
245 == (unsigned long) (info
->dyninfo
.ld_symbols
246 - info
->dyninfo
.ld_stab
));
248 /* Similarly, the relocs end at the hash table. */
249 info
->dynrel_count
= ((info
->dyninfo
.ld_hash
- info
->dyninfo
.ld_rel
)
250 / obj_reloc_entry_size (abfd
));
251 BFD_ASSERT (info
->dynrel_count
* obj_reloc_entry_size (abfd
)
252 == (unsigned long) (info
->dyninfo
.ld_hash
253 - info
->dyninfo
.ld_rel
));
260 /* Return the amount of memory required for the dynamic symbols. */
263 sunos_get_dynamic_symtab_upper_bound (abfd
)
266 struct sunos_dynamic_info
*info
;
268 if (! sunos_read_dynamic_info (abfd
))
271 info
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
274 bfd_set_error (bfd_error_no_symbols
);
278 return (info
->dynsym_count
+ 1) * sizeof (asymbol
*);
281 /* Read the external dynamic symbols. */
284 sunos_slurp_dynamic_symtab (abfd
)
287 struct sunos_dynamic_info
*info
;
290 /* Get the general dynamic information. */
291 if (obj_aout_dynamic_info (abfd
) == NULL
)
293 if (! sunos_read_dynamic_info (abfd
))
297 info
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
300 bfd_set_error (bfd_error_no_symbols
);
304 /* Get the dynamic nlist structures. */
305 if (info
->dynsym
== (struct external_nlist
*) NULL
)
307 amt
= (bfd_size_type
) info
->dynsym_count
* EXTERNAL_NLIST_SIZE
;
308 info
->dynsym
= (struct external_nlist
*) bfd_alloc (abfd
, amt
);
309 if (info
->dynsym
== NULL
&& info
->dynsym_count
!= 0)
311 if (bfd_seek (abfd
, (file_ptr
) info
->dyninfo
.ld_stab
, SEEK_SET
) != 0
312 || bfd_bread ((PTR
) info
->dynsym
, amt
, abfd
) != amt
)
314 if (info
->dynsym
!= NULL
)
316 bfd_release (abfd
, info
->dynsym
);
323 /* Get the dynamic strings. */
324 if (info
->dynstr
== (char *) NULL
)
326 amt
= info
->dyninfo
.ld_symb_size
;
327 info
->dynstr
= (char *) bfd_alloc (abfd
, amt
);
328 if (info
->dynstr
== NULL
&& info
->dyninfo
.ld_symb_size
!= 0)
330 if (bfd_seek (abfd
, (file_ptr
) info
->dyninfo
.ld_symbols
, SEEK_SET
) != 0
331 || bfd_bread ((PTR
) info
->dynstr
, amt
, abfd
) != amt
)
333 if (info
->dynstr
!= NULL
)
335 bfd_release (abfd
, info
->dynstr
);
345 /* Read in the dynamic symbols. */
348 sunos_canonicalize_dynamic_symtab (abfd
, storage
)
352 struct sunos_dynamic_info
*info
;
355 if (! sunos_slurp_dynamic_symtab (abfd
))
358 info
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
360 #ifdef CHECK_DYNAMIC_HASH
361 /* Check my understanding of the dynamic hash table by making sure
362 that each symbol can be located in the hash table. */
364 bfd_size_type table_size
;
368 if (info
->dyninfo
.ld_buckets
> info
->dynsym_count
)
370 table_size
= info
->dyninfo
.ld_stab
- info
->dyninfo
.ld_hash
;
371 table
= (bfd_byte
*) bfd_malloc (table_size
);
372 if (table
== NULL
&& table_size
!= 0)
374 if (bfd_seek (abfd
, (file_ptr
) info
->dyninfo
.ld_hash
, SEEK_SET
) != 0
375 || bfd_bread ((PTR
) table
, table_size
, abfd
) != table_size
)
377 for (i
= 0; i
< info
->dynsym_count
; i
++)
382 name
= ((unsigned char *) info
->dynstr
383 + GET_WORD (abfd
, info
->dynsym
[i
].e_strx
));
385 while (*name
!= '\0')
386 hash
= (hash
<< 1) + *name
++;
388 hash
%= info
->dyninfo
.ld_buckets
;
389 while (GET_WORD (abfd
, table
+ hash
* HASH_ENTRY_SIZE
) != i
)
391 hash
= GET_WORD (abfd
,
392 table
+ hash
* HASH_ENTRY_SIZE
+ BYTES_IN_WORD
);
393 if (hash
== 0 || hash
>= table_size
/ HASH_ENTRY_SIZE
)
399 #endif /* CHECK_DYNAMIC_HASH */
401 /* Get the asymbol structures corresponding to the dynamic nlist
403 if (info
->canonical_dynsym
== (aout_symbol_type
*) NULL
)
406 bfd_size_type strsize
= info
->dyninfo
.ld_symb_size
;
408 size
= (bfd_size_type
) info
->dynsym_count
* sizeof (aout_symbol_type
);
409 info
->canonical_dynsym
= (aout_symbol_type
*) bfd_alloc (abfd
, size
);
410 if (info
->canonical_dynsym
== NULL
&& info
->dynsym_count
!= 0)
413 if (! aout_32_translate_symbol_table (abfd
, info
->canonical_dynsym
,
415 (bfd_size_type
) info
->dynsym_count
,
416 info
->dynstr
, strsize
, true))
418 if (info
->canonical_dynsym
!= NULL
)
420 bfd_release (abfd
, info
->canonical_dynsym
);
421 info
->canonical_dynsym
= NULL
;
427 /* Return pointers to the dynamic asymbol structures. */
428 for (i
= 0; i
< info
->dynsym_count
; i
++)
429 *storage
++ = (asymbol
*) (info
->canonical_dynsym
+ i
);
432 return info
->dynsym_count
;
435 /* Return the amount of memory required for the dynamic relocs. */
438 sunos_get_dynamic_reloc_upper_bound (abfd
)
441 struct sunos_dynamic_info
*info
;
443 if (! sunos_read_dynamic_info (abfd
))
446 info
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
449 bfd_set_error (bfd_error_no_symbols
);
453 return (info
->dynrel_count
+ 1) * sizeof (arelent
*);
456 /* Read in the dynamic relocs. */
459 sunos_canonicalize_dynamic_reloc (abfd
, storage
, syms
)
464 struct sunos_dynamic_info
*info
;
468 /* Get the general dynamic information. */
469 if (obj_aout_dynamic_info (abfd
) == (PTR
) NULL
)
471 if (! sunos_read_dynamic_info (abfd
))
475 info
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
478 bfd_set_error (bfd_error_no_symbols
);
482 /* Get the dynamic reloc information. */
483 if (info
->dynrel
== NULL
)
485 size
= (bfd_size_type
) info
->dynrel_count
* obj_reloc_entry_size (abfd
);
486 info
->dynrel
= (PTR
) bfd_alloc (abfd
, size
);
487 if (info
->dynrel
== NULL
&& size
!= 0)
489 if (bfd_seek (abfd
, (file_ptr
) info
->dyninfo
.ld_rel
, SEEK_SET
) != 0
490 || bfd_bread ((PTR
) info
->dynrel
, size
, abfd
) != size
)
492 if (info
->dynrel
!= NULL
)
494 bfd_release (abfd
, info
->dynrel
);
501 /* Get the arelent structures corresponding to the dynamic reloc
503 if (info
->canonical_dynrel
== (arelent
*) NULL
)
507 size
= (bfd_size_type
) info
->dynrel_count
* sizeof (arelent
);
508 info
->canonical_dynrel
= (arelent
*) bfd_alloc (abfd
, size
);
509 if (info
->canonical_dynrel
== NULL
&& info
->dynrel_count
!= 0)
512 to
= info
->canonical_dynrel
;
514 if (obj_reloc_entry_size (abfd
) == RELOC_EXT_SIZE
)
516 register struct reloc_ext_external
*p
;
517 struct reloc_ext_external
*pend
;
519 p
= (struct reloc_ext_external
*) info
->dynrel
;
520 pend
= p
+ info
->dynrel_count
;
521 for (; p
< pend
; p
++, to
++)
522 NAME(aout
,swap_ext_reloc_in
) (abfd
, p
, to
, syms
,
523 (bfd_size_type
) info
->dynsym_count
);
527 register struct reloc_std_external
*p
;
528 struct reloc_std_external
*pend
;
530 p
= (struct reloc_std_external
*) info
->dynrel
;
531 pend
= p
+ info
->dynrel_count
;
532 for (; p
< pend
; p
++, to
++)
533 NAME(aout
,swap_std_reloc_in
) (abfd
, p
, to
, syms
,
534 (bfd_size_type
) info
->dynsym_count
);
538 /* Return pointers to the dynamic arelent structures. */
539 for (i
= 0; i
< info
->dynrel_count
; i
++)
540 *storage
++ = info
->canonical_dynrel
+ i
;
543 return info
->dynrel_count
;
546 /* Code to handle linking of SunOS shared libraries. */
548 /* A SPARC procedure linkage table entry is 12 bytes. The first entry
549 in the table is a jump which is filled in by the runtime linker.
550 The remaining entries are branches back to the first entry,
551 followed by an index into the relocation table encoded to look like
554 #define SPARC_PLT_ENTRY_SIZE (12)
556 static const bfd_byte sparc_plt_first_entry
[SPARC_PLT_ENTRY_SIZE
] =
558 /* sethi %hi(0),%g1; address filled in by runtime linker. */
560 /* jmp %g1; offset filled in by runtime linker. */
566 /* save %sp, -96, %sp */
567 #define SPARC_PLT_ENTRY_WORD0 ((bfd_vma) 0x9de3bfa0)
568 /* call; address filled in later. */
569 #define SPARC_PLT_ENTRY_WORD1 ((bfd_vma) 0x40000000)
570 /* sethi; reloc index filled in later. */
571 #define SPARC_PLT_ENTRY_WORD2 ((bfd_vma) 0x01000000)
573 /* This sequence is used when for the jump table entry to a defined
574 symbol in a complete executable. It is used when linking PIC
575 compiled code which is not being put into a shared library. */
576 /* sethi <address to be filled in later>, %g1 */
577 #define SPARC_PLT_PIC_WORD0 ((bfd_vma) 0x03000000)
578 /* jmp %g1 + <address to be filled in later> */
579 #define SPARC_PLT_PIC_WORD1 ((bfd_vma) 0x81c06000)
581 #define SPARC_PLT_PIC_WORD2 ((bfd_vma) 0x01000000)
583 /* An m68k procedure linkage table entry is 8 bytes. The first entry
584 in the table is a jump which is filled in the by the runtime
585 linker. The remaining entries are branches back to the first
586 entry, followed by a two byte index into the relocation table. */
588 #define M68K_PLT_ENTRY_SIZE (8)
590 static const bfd_byte m68k_plt_first_entry
[M68K_PLT_ENTRY_SIZE
] =
594 /* Filled in by runtime linker with a magic address. */
601 #define M68K_PLT_ENTRY_WORD0 ((bfd_vma) 0x61ff)
602 /* Remaining words filled in later. */
604 /* An entry in the SunOS linker hash table. */
606 struct sunos_link_hash_entry
608 struct aout_link_hash_entry root
;
610 /* If this is a dynamic symbol, this is its index into the dynamic
611 symbol table. This is initialized to -1. As the linker looks at
612 the input files, it changes this to -2 if it will be added to the
613 dynamic symbol table. After all the input files have been seen,
614 the linker will know whether to build a dynamic symbol table; if
615 it does build one, this becomes the index into the table. */
618 /* If this is a dynamic symbol, this is the index of the name in the
619 dynamic symbol string table. */
622 /* The offset into the global offset table used for this symbol. If
623 the symbol does not require a GOT entry, this is 0. */
626 /* The offset into the procedure linkage table used for this symbol.
627 If the symbol does not require a PLT entry, this is 0. */
630 /* Some linker flags. */
632 /* Symbol is referenced by a regular object. */
633 #define SUNOS_REF_REGULAR 01
634 /* Symbol is defined by a regular object. */
635 #define SUNOS_DEF_REGULAR 02
636 /* Symbol is referenced by a dynamic object. */
637 #define SUNOS_REF_DYNAMIC 04
638 /* Symbol is defined by a dynamic object. */
639 #define SUNOS_DEF_DYNAMIC 010
640 /* Symbol is a constructor symbol in a regular object. */
641 #define SUNOS_CONSTRUCTOR 020
644 /* The SunOS linker hash table. */
646 struct sunos_link_hash_table
648 struct aout_link_hash_table root
;
650 /* The object which holds the dynamic sections. */
653 /* Whether we have created the dynamic sections. */
654 boolean dynamic_sections_created
;
656 /* Whether we need the dynamic sections. */
657 boolean dynamic_sections_needed
;
659 /* Whether we need the .got table. */
662 /* The number of dynamic symbols. */
665 /* The number of buckets in the hash table. */
668 /* The list of dynamic objects needed by dynamic objects included in
670 struct bfd_link_needed_list
*needed
;
672 /* The offset of __GLOBAL_OFFSET_TABLE_ into the .got section. */
676 /* Routine to create an entry in an SunOS link hash table. */
678 static struct bfd_hash_entry
*
679 sunos_link_hash_newfunc (entry
, table
, string
)
680 struct bfd_hash_entry
*entry
;
681 struct bfd_hash_table
*table
;
684 struct sunos_link_hash_entry
*ret
= (struct sunos_link_hash_entry
*) entry
;
686 /* Allocate the structure if it has not already been allocated by a
688 if (ret
== (struct sunos_link_hash_entry
*) NULL
)
689 ret
= ((struct sunos_link_hash_entry
*)
690 bfd_hash_allocate (table
, sizeof (struct sunos_link_hash_entry
)));
691 if (ret
== (struct sunos_link_hash_entry
*) NULL
)
692 return (struct bfd_hash_entry
*) ret
;
694 /* Call the allocation method of the superclass. */
695 ret
= ((struct sunos_link_hash_entry
*)
696 NAME(aout
,link_hash_newfunc
) ((struct bfd_hash_entry
*) ret
,
700 /* Set local fields. */
702 ret
->dynstr_index
= -1;
708 return (struct bfd_hash_entry
*) ret
;
711 /* Create a SunOS link hash table. */
713 static struct bfd_link_hash_table
*
714 sunos_link_hash_table_create (abfd
)
717 struct sunos_link_hash_table
*ret
;
718 bfd_size_type amt
= sizeof (struct sunos_link_hash_table
);
720 ret
= (struct sunos_link_hash_table
*) bfd_malloc (amt
);
721 if (ret
== (struct sunos_link_hash_table
*) NULL
)
722 return (struct bfd_link_hash_table
*) NULL
;
723 if (! NAME(aout
,link_hash_table_init
) (&ret
->root
, abfd
,
724 sunos_link_hash_newfunc
))
727 return (struct bfd_link_hash_table
*) NULL
;
731 ret
->dynamic_sections_created
= false;
732 ret
->dynamic_sections_needed
= false;
733 ret
->got_needed
= false;
734 ret
->dynsymcount
= 0;
735 ret
->bucketcount
= 0;
739 return &ret
->root
.root
;
742 /* Look up an entry in an SunOS link hash table. */
744 #define sunos_link_hash_lookup(table, string, create, copy, follow) \
745 ((struct sunos_link_hash_entry *) \
746 aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
749 /* Traverse a SunOS link hash table. */
751 #define sunos_link_hash_traverse(table, func, info) \
752 (aout_link_hash_traverse \
754 (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
757 /* Get the SunOS link hash table from the info structure. This is
760 #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
762 static boolean sunos_scan_dynamic_symbol
763 PARAMS ((struct sunos_link_hash_entry
*, PTR
));
765 /* Create the dynamic sections needed if we are linking against a
766 dynamic object, or if we are linking PIC compiled code. ABFD is a
767 bfd we can attach the dynamic sections to. The linker script will
768 look for these special sections names and put them in the right
769 place in the output file. See include/aout/sun4.h for more details
770 of the dynamic linking information. */
773 sunos_create_dynamic_sections (abfd
, info
, needed
)
775 struct bfd_link_info
*info
;
780 if (! sunos_hash_table (info
)->dynamic_sections_created
)
784 sunos_hash_table (info
)->dynobj
= abfd
;
786 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
787 | SEC_LINKER_CREATED
);
789 /* The .dynamic section holds the basic dynamic information: the
790 sun4_dynamic structure, the dynamic debugger information, and
791 the sun4_dynamic_link structure. */
792 s
= bfd_make_section (abfd
, ".dynamic");
794 || ! bfd_set_section_flags (abfd
, s
, flags
)
795 || ! bfd_set_section_alignment (abfd
, s
, 2))
798 /* The .got section holds the global offset table. The address
799 is put in the ld_got field. */
800 s
= bfd_make_section (abfd
, ".got");
802 || ! bfd_set_section_flags (abfd
, s
, flags
)
803 || ! bfd_set_section_alignment (abfd
, s
, 2))
806 /* The .plt section holds the procedure linkage table. The
807 address is put in the ld_plt field. */
808 s
= bfd_make_section (abfd
, ".plt");
810 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
811 || ! bfd_set_section_alignment (abfd
, s
, 2))
814 /* The .dynrel section holds the dynamic relocs. The address is
815 put in the ld_rel field. */
816 s
= bfd_make_section (abfd
, ".dynrel");
818 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
819 || ! bfd_set_section_alignment (abfd
, s
, 2))
822 /* The .hash section holds the dynamic hash table. The address
823 is put in the ld_hash field. */
824 s
= bfd_make_section (abfd
, ".hash");
826 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
827 || ! bfd_set_section_alignment (abfd
, s
, 2))
830 /* The .dynsym section holds the dynamic symbols. The address
831 is put in the ld_stab field. */
832 s
= bfd_make_section (abfd
, ".dynsym");
834 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
835 || ! bfd_set_section_alignment (abfd
, s
, 2))
838 /* The .dynstr section holds the dynamic symbol string table.
839 The address is put in the ld_symbols field. */
840 s
= bfd_make_section (abfd
, ".dynstr");
842 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
843 || ! bfd_set_section_alignment (abfd
, s
, 2))
846 sunos_hash_table (info
)->dynamic_sections_created
= true;
849 if ((needed
&& ! sunos_hash_table (info
)->dynamic_sections_needed
)
854 dynobj
= sunos_hash_table (info
)->dynobj
;
856 s
= bfd_get_section_by_name (dynobj
, ".got");
857 if (s
->_raw_size
== 0)
858 s
->_raw_size
= BYTES_IN_WORD
;
860 sunos_hash_table (info
)->dynamic_sections_needed
= true;
861 sunos_hash_table (info
)->got_needed
= true;
867 /* Add dynamic symbols during a link. This is called by the a.out
868 backend linker for each object it encounters. */
871 sunos_add_dynamic_symbols (abfd
, info
, symsp
, sym_countp
, stringsp
)
873 struct bfd_link_info
*info
;
874 struct external_nlist
**symsp
;
875 bfd_size_type
*sym_countp
;
879 struct sunos_dynamic_info
*dinfo
;
883 /* Make sure we have all the required sections. */
884 if (info
->hash
->creator
== abfd
->xvec
)
886 if (! sunos_create_dynamic_sections (abfd
, info
,
887 (((abfd
->flags
& DYNAMIC
) != 0
888 && ! info
->relocateable
)
894 /* There is nothing else to do for a normal object. */
895 if ((abfd
->flags
& DYNAMIC
) == 0)
898 dynobj
= sunos_hash_table (info
)->dynobj
;
900 /* We do not want to include the sections in a dynamic object in the
901 output file. We hack by simply clobbering the list of sections
902 in the BFD. This could be handled more cleanly by, say, a new
903 section flag; the existing SEC_NEVER_LOAD flag is not the one we
904 want, because that one still implies that the section takes up
905 space in the output file. If this is the first object we have
906 seen, we must preserve the dynamic sections we just created. */
907 for (ps
= &abfd
->sections
; *ps
!= NULL
; )
909 if (abfd
!= dynobj
|| ((*ps
)->flags
& SEC_LINKER_CREATED
) == 0)
910 bfd_section_list_remove (abfd
, ps
);
915 /* The native linker seems to just ignore dynamic objects when -r is
917 if (info
->relocateable
)
920 /* There's no hope of using a dynamic object which does not exactly
921 match the format of the output file. */
922 if (info
->hash
->creator
!= abfd
->xvec
)
924 bfd_set_error (bfd_error_invalid_operation
);
928 /* Make sure we have a .need and a .rules sections. These are only
929 needed if there really is a dynamic object in the link, so they
930 are not added by sunos_create_dynamic_sections. */
931 if (bfd_get_section_by_name (dynobj
, ".need") == NULL
)
933 /* The .need section holds the list of names of shared objets
934 which must be included at runtime. The address of this
935 section is put in the ld_need field. */
936 asection
*s
= bfd_make_section (dynobj
, ".need");
938 || ! bfd_set_section_flags (dynobj
, s
,
944 || ! bfd_set_section_alignment (dynobj
, s
, 2))
948 if (bfd_get_section_by_name (dynobj
, ".rules") == NULL
)
950 /* The .rules section holds the path to search for shared
951 objects. The address of this section is put in the ld_rules
953 asection
*s
= bfd_make_section (dynobj
, ".rules");
955 || ! bfd_set_section_flags (dynobj
, s
,
961 || ! bfd_set_section_alignment (dynobj
, s
, 2))
965 /* Pick up the dynamic symbols and return them to the caller. */
966 if (! sunos_slurp_dynamic_symtab (abfd
))
969 dinfo
= (struct sunos_dynamic_info
*) obj_aout_dynamic_info (abfd
);
970 *symsp
= dinfo
->dynsym
;
971 *sym_countp
= dinfo
->dynsym_count
;
972 *stringsp
= dinfo
->dynstr
;
974 /* Record information about any other objects needed by this one. */
975 need
= dinfo
->dyninfo
.ld_need
;
979 unsigned long name
, flags
;
980 unsigned short major_vno
, minor_vno
;
981 struct bfd_link_needed_list
*needed
, **pp
;
987 if (bfd_seek (abfd
, (file_ptr
) need
, SEEK_SET
) != 0
988 || bfd_bread (buf
, (bfd_size_type
) 16, abfd
) != 16)
991 /* For the format of an ld_need entry, see aout/sun4.h. We
992 should probably define structs for this manipulation. */
994 name
= bfd_get_32 (abfd
, buf
);
995 flags
= bfd_get_32 (abfd
, buf
+ 4);
996 major_vno
= (unsigned short) bfd_get_16 (abfd
, buf
+ 8);
997 minor_vno
= (unsigned short) bfd_get_16 (abfd
, buf
+ 10);
998 need
= bfd_get_32 (abfd
, buf
+ 12);
1000 alc
= sizeof (struct bfd_link_needed_list
);
1001 needed
= (struct bfd_link_needed_list
*) bfd_alloc (abfd
, alc
);
1006 /* We return the name as [-l]name[.maj][.min]. */
1008 namebuf
= (char *) bfd_malloc (alc
+ 1);
1009 if (namebuf
== NULL
)
1013 if ((flags
& 0x80000000) != 0)
1018 if (bfd_seek (abfd
, (file_ptr
) name
, SEEK_SET
) != 0)
1026 if (bfd_bread (&b
, (bfd_size_type
) 1, abfd
) != 1)
1032 if ((bfd_size_type
) (p
- namebuf
) >= alc
)
1037 n
= (char *) bfd_realloc (namebuf
, alc
+ 1);
1043 p
= n
+ (p
- namebuf
);
1058 sprintf (majbuf
, ".%d", major_vno
);
1062 sprintf (minbuf
, ".%d", minor_vno
);
1064 if ((p
- namebuf
) + strlen (majbuf
) + strlen (minbuf
) >= alc
)
1068 alc
= (p
- namebuf
) + strlen (majbuf
) + strlen (minbuf
);
1069 n
= (char *) bfd_realloc (namebuf
, alc
+ 1);
1075 p
= n
+ (p
- namebuf
);
1083 namecopy
= bfd_alloc (abfd
, (bfd_size_type
) strlen (namebuf
) + 1);
1084 if (namecopy
== NULL
)
1089 strcpy (namecopy
, namebuf
);
1091 needed
->name
= namecopy
;
1093 needed
->next
= NULL
;
1095 for (pp
= &sunos_hash_table (info
)->needed
;
1105 /* Function to add a single symbol to the linker hash table. This is
1106 a wrapper around _bfd_generic_link_add_one_symbol which handles the
1107 tweaking needed for dynamic linking support. */
1110 sunos_add_one_symbol (info
, abfd
, name
, flags
, section
, value
, string
,
1111 copy
, collect
, hashp
)
1112 struct bfd_link_info
*info
;
1121 struct bfd_link_hash_entry
**hashp
;
1123 struct sunos_link_hash_entry
*h
;
1126 if ((flags
& (BSF_INDIRECT
| BSF_WARNING
| BSF_CONSTRUCTOR
)) != 0
1127 || ! bfd_is_und_section (section
))
1128 h
= sunos_link_hash_lookup (sunos_hash_table (info
), name
, true, copy
,
1131 h
= ((struct sunos_link_hash_entry
*)
1132 bfd_wrapped_link_hash_lookup (abfd
, info
, name
, true, copy
, false));
1137 *hashp
= (struct bfd_link_hash_entry
*) h
;
1139 /* Treat a common symbol in a dynamic object as defined in the .bss
1140 section of the dynamic object. We don't want to allocate space
1141 for it in our process image. */
1142 if ((abfd
->flags
& DYNAMIC
) != 0
1143 && bfd_is_com_section (section
))
1144 section
= obj_bsssec (abfd
);
1146 if (! bfd_is_und_section (section
)
1147 && h
->root
.root
.type
!= bfd_link_hash_new
1148 && h
->root
.root
.type
!= bfd_link_hash_undefined
1149 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1151 /* We are defining the symbol, and it is already defined. This
1152 is a potential multiple definition error. */
1153 if ((abfd
->flags
& DYNAMIC
) != 0)
1155 /* The definition we are adding is from a dynamic object.
1156 We do not want this new definition to override the
1157 existing definition, so we pretend it is just a
1159 section
= bfd_und_section_ptr
;
1161 else if (h
->root
.root
.type
== bfd_link_hash_defined
1162 && h
->root
.root
.u
.def
.section
->owner
!= NULL
1163 && (h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
) != 0)
1165 /* The existing definition is from a dynamic object. We
1166 want to override it with the definition we just found.
1167 Clobber the existing definition. */
1168 h
->root
.root
.type
= bfd_link_hash_undefined
;
1169 h
->root
.root
.u
.undef
.abfd
= h
->root
.root
.u
.def
.section
->owner
;
1171 else if (h
->root
.root
.type
== bfd_link_hash_common
1172 && (h
->root
.root
.u
.c
.p
->section
->owner
->flags
& DYNAMIC
) != 0)
1174 /* The existing definition is from a dynamic object. We
1175 want to override it with the definition we just found.
1176 Clobber the existing definition. We can't set it to new,
1177 because it is on the undefined list. */
1178 h
->root
.root
.type
= bfd_link_hash_undefined
;
1179 h
->root
.root
.u
.undef
.abfd
= h
->root
.root
.u
.c
.p
->section
->owner
;
1183 if ((abfd
->flags
& DYNAMIC
) != 0
1184 && abfd
->xvec
== info
->hash
->creator
1185 && (h
->flags
& SUNOS_CONSTRUCTOR
) != 0)
1187 /* The existing symbol is a constructor symbol, and this symbol
1188 is from a dynamic object. A constructor symbol is actually a
1189 definition, although the type will be bfd_link_hash_undefined
1190 at this point. We want to ignore the definition from the
1192 section
= bfd_und_section_ptr
;
1194 else if ((flags
& BSF_CONSTRUCTOR
) != 0
1195 && (abfd
->flags
& DYNAMIC
) == 0
1196 && h
->root
.root
.type
== bfd_link_hash_defined
1197 && h
->root
.root
.u
.def
.section
->owner
!= NULL
1198 && (h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
) != 0)
1200 /* The existing symbol is defined by a dynamic object, and this
1201 is a constructor symbol. As above, we want to force the use
1202 of the constructor symbol from the regular object. */
1203 h
->root
.root
.type
= bfd_link_hash_new
;
1206 /* Do the usual procedure for adding a symbol. */
1207 if (! _bfd_generic_link_add_one_symbol (info
, abfd
, name
, flags
, section
,
1208 value
, string
, copy
, collect
,
1212 if (abfd
->xvec
== info
->hash
->creator
)
1214 /* Set a flag in the hash table entry indicating the type of
1215 reference or definition we just found. Keep a count of the
1216 number of dynamic symbols we find. A dynamic symbol is one
1217 which is referenced or defined by both a regular object and a
1219 if ((abfd
->flags
& DYNAMIC
) == 0)
1221 if (bfd_is_und_section (section
))
1222 new_flag
= SUNOS_REF_REGULAR
;
1224 new_flag
= SUNOS_DEF_REGULAR
;
1228 if (bfd_is_und_section (section
))
1229 new_flag
= SUNOS_REF_DYNAMIC
;
1231 new_flag
= SUNOS_DEF_DYNAMIC
;
1233 h
->flags
|= new_flag
;
1235 if (h
->dynindx
== -1
1236 && (h
->flags
& (SUNOS_DEF_REGULAR
| SUNOS_REF_REGULAR
)) != 0)
1238 ++sunos_hash_table (info
)->dynsymcount
;
1242 if ((flags
& BSF_CONSTRUCTOR
) != 0
1243 && (abfd
->flags
& DYNAMIC
) == 0)
1244 h
->flags
|= SUNOS_CONSTRUCTOR
;
1250 /* Return the list of objects needed by BFD. */
1253 struct bfd_link_needed_list
*
1254 bfd_sunos_get_needed_list (abfd
, info
)
1255 bfd
*abfd ATTRIBUTE_UNUSED
;
1256 struct bfd_link_info
*info
;
1258 if (info
->hash
->creator
!= &MY(vec
))
1260 return sunos_hash_table (info
)->needed
;
1263 /* Record an assignment made to a symbol by a linker script. We need
1264 this in case some dynamic object refers to this symbol. */
1267 bfd_sunos_record_link_assignment (output_bfd
, info
, name
)
1269 struct bfd_link_info
*info
;
1272 struct sunos_link_hash_entry
*h
;
1274 if (output_bfd
->xvec
!= &MY(vec
))
1277 /* This is called after we have examined all the input objects. If
1278 the symbol does not exist, it merely means that no object refers
1279 to it, and we can just ignore it at this point. */
1280 h
= sunos_link_hash_lookup (sunos_hash_table (info
), name
,
1281 false, false, false);
1285 /* In a shared library, the __DYNAMIC symbol does not appear in the
1286 dynamic symbol table. */
1287 if (! info
->shared
|| strcmp (name
, "__DYNAMIC") != 0)
1289 h
->flags
|= SUNOS_DEF_REGULAR
;
1291 if (h
->dynindx
== -1)
1293 ++sunos_hash_table (info
)->dynsymcount
;
1301 /* Set up the sizes and contents of the dynamic sections created in
1302 sunos_add_dynamic_symbols. This is called by the SunOS linker
1303 emulation before_allocation routine. We must set the sizes of the
1304 sections before the linker sets the addresses of the various
1305 sections. This unfortunately requires reading all the relocs so
1306 that we can work out which ones need to become dynamic relocs. If
1307 info->keep_memory is true, we keep the relocs in memory; otherwise,
1308 we discard them, and will read them again later. */
1311 bfd_sunos_size_dynamic_sections (output_bfd
, info
, sdynptr
, sneedptr
,
1314 struct bfd_link_info
*info
;
1316 asection
**sneedptr
;
1317 asection
**srulesptr
;
1320 bfd_size_type dynsymcount
;
1321 struct sunos_link_hash_entry
*h
;
1324 bfd_size_type hashalloc
;
1332 if (info
->relocateable
)
1335 if (output_bfd
->xvec
!= &MY(vec
))
1338 /* Look through all the input BFD's and read their relocs. It would
1339 be better if we didn't have to do this, but there is no other way
1340 to determine the number of dynamic relocs we need, and, more
1341 importantly, there is no other way to know which symbols should
1342 get an entry in the procedure linkage table. */
1343 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
1345 if ((sub
->flags
& DYNAMIC
) == 0
1346 && sub
->xvec
== output_bfd
->xvec
)
1348 if (! sunos_scan_relocs (info
, sub
, obj_textsec (sub
),
1349 exec_hdr (sub
)->a_trsize
)
1350 || ! sunos_scan_relocs (info
, sub
, obj_datasec (sub
),
1351 exec_hdr (sub
)->a_drsize
))
1356 dynobj
= sunos_hash_table (info
)->dynobj
;
1357 dynsymcount
= sunos_hash_table (info
)->dynsymcount
;
1359 /* If there were no dynamic objects in the link, and we don't need
1360 to build a global offset table, there is nothing to do here. */
1361 if (! sunos_hash_table (info
)->dynamic_sections_needed
1362 && ! sunos_hash_table (info
)->got_needed
)
1365 /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it. */
1366 h
= sunos_link_hash_lookup (sunos_hash_table (info
),
1367 "__GLOBAL_OFFSET_TABLE_", false, false, false);
1368 if (h
!= NULL
&& (h
->flags
& SUNOS_REF_REGULAR
) != 0)
1370 h
->flags
|= SUNOS_DEF_REGULAR
;
1371 if (h
->dynindx
== -1)
1373 ++sunos_hash_table (info
)->dynsymcount
;
1376 h
->root
.root
.type
= bfd_link_hash_defined
;
1377 h
->root
.root
.u
.def
.section
= bfd_get_section_by_name (dynobj
, ".got");
1379 /* If the .got section is more than 0x1000 bytes, we set
1380 __GLOBAL_OFFSET_TABLE_ to be 0x1000 bytes into the section,
1381 so that 13 bit relocations have a greater chance of working. */
1382 s
= bfd_get_section_by_name (dynobj
, ".got");
1383 BFD_ASSERT (s
!= NULL
);
1384 if (s
->_raw_size
>= 0x1000)
1385 h
->root
.root
.u
.def
.value
= 0x1000;
1387 h
->root
.root
.u
.def
.value
= 0;
1389 sunos_hash_table (info
)->got_base
= h
->root
.root
.u
.def
.value
;
1392 /* If there are any shared objects in the link, then we need to set
1393 up the dynamic linking information. */
1394 if (sunos_hash_table (info
)->dynamic_sections_needed
)
1396 *sdynptr
= bfd_get_section_by_name (dynobj
, ".dynamic");
1398 /* The .dynamic section is always the same size. */
1400 BFD_ASSERT (s
!= NULL
);
1401 s
->_raw_size
= (sizeof (struct external_sun4_dynamic
)
1402 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
1403 + sizeof (struct external_sun4_dynamic_link
));
1405 /* Set the size of the .dynsym and .hash sections. We counted
1406 the number of dynamic symbols as we read the input files. We
1407 will build the dynamic symbol table (.dynsym) and the hash
1408 table (.hash) when we build the final symbol table, because
1409 until then we do not know the correct value to give the
1410 symbols. We build the dynamic symbol string table (.dynstr)
1411 in a traversal of the symbol table using
1412 sunos_scan_dynamic_symbol. */
1413 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
1414 BFD_ASSERT (s
!= NULL
);
1415 s
->_raw_size
= dynsymcount
* sizeof (struct external_nlist
);
1416 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
1417 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1420 /* The number of buckets is just the number of symbols divided
1421 by four. To compute the final size of the hash table, we
1422 must actually compute the hash table. Normally we need
1423 exactly as many entries in the hash table as there are
1424 dynamic symbols, but if some of the buckets are not used we
1425 will need additional entries. In the worst case, every
1426 symbol will hash to the same bucket, and we will need
1427 BUCKETCOUNT - 1 extra entries. */
1428 if (dynsymcount
>= 4)
1429 bucketcount
= dynsymcount
/ 4;
1430 else if (dynsymcount
> 0)
1431 bucketcount
= dynsymcount
;
1434 s
= bfd_get_section_by_name (dynobj
, ".hash");
1435 BFD_ASSERT (s
!= NULL
);
1436 hashalloc
= (dynsymcount
+ bucketcount
- 1) * HASH_ENTRY_SIZE
;
1437 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, hashalloc
);
1438 if (s
->contents
== NULL
&& dynsymcount
> 0)
1440 for (i
= 0; i
< bucketcount
; i
++)
1441 PUT_WORD (output_bfd
, (bfd_vma
) -1, s
->contents
+ i
* HASH_ENTRY_SIZE
);
1442 s
->_raw_size
= bucketcount
* HASH_ENTRY_SIZE
;
1444 sunos_hash_table (info
)->bucketcount
= bucketcount
;
1446 /* Scan all the symbols, place them in the dynamic symbol table,
1447 and build the dynamic hash table. We reuse dynsymcount as a
1448 counter for the number of symbols we have added so far. */
1449 sunos_hash_table (info
)->dynsymcount
= 0;
1450 sunos_link_hash_traverse (sunos_hash_table (info
),
1451 sunos_scan_dynamic_symbol
,
1453 BFD_ASSERT (sunos_hash_table (info
)->dynsymcount
== dynsymcount
);
1455 /* The SunOS native linker seems to align the total size of the
1456 symbol strings to a multiple of 8. I don't know if this is
1457 important, but it can't hurt much. */
1458 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
1459 BFD_ASSERT (s
!= NULL
);
1460 if ((s
->_raw_size
& 7) != 0)
1465 add
= 8 - (s
->_raw_size
& 7);
1466 contents
= (bfd_byte
*) bfd_realloc (s
->contents
,
1467 s
->_raw_size
+ add
);
1468 if (contents
== NULL
)
1470 memset (contents
+ s
->_raw_size
, 0, (size_t) add
);
1471 s
->contents
= contents
;
1472 s
->_raw_size
+= add
;
1476 /* Now that we have worked out the sizes of the procedure linkage
1477 table and the dynamic relocs, allocate storage for them. */
1478 s
= bfd_get_section_by_name (dynobj
, ".plt");
1479 BFD_ASSERT (s
!= NULL
);
1480 if (s
->_raw_size
!= 0)
1482 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1483 if (s
->contents
== NULL
)
1486 /* Fill in the first entry in the table. */
1487 switch (bfd_get_arch (dynobj
))
1489 case bfd_arch_sparc
:
1490 memcpy (s
->contents
, sparc_plt_first_entry
, SPARC_PLT_ENTRY_SIZE
);
1494 memcpy (s
->contents
, m68k_plt_first_entry
, M68K_PLT_ENTRY_SIZE
);
1502 s
= bfd_get_section_by_name (dynobj
, ".dynrel");
1503 if (s
->_raw_size
!= 0)
1505 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1506 if (s
->contents
== NULL
)
1509 /* We use the reloc_count field to keep track of how many of the
1510 relocs we have output so far. */
1513 /* Make space for the global offset table. */
1514 s
= bfd_get_section_by_name (dynobj
, ".got");
1515 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1516 if (s
->contents
== NULL
)
1519 *sneedptr
= bfd_get_section_by_name (dynobj
, ".need");
1520 *srulesptr
= bfd_get_section_by_name (dynobj
, ".rules");
1525 /* Scan the relocs for an input section. */
1528 sunos_scan_relocs (info
, abfd
, sec
, rel_size
)
1529 struct bfd_link_info
*info
;
1532 bfd_size_type rel_size
;
1535 PTR free_relocs
= NULL
;
1540 if (! info
->keep_memory
)
1541 relocs
= free_relocs
= bfd_malloc (rel_size
);
1544 struct aout_section_data_struct
*n
;
1545 bfd_size_type amt
= sizeof (struct aout_section_data_struct
);
1547 n
= (struct aout_section_data_struct
*) bfd_alloc (abfd
, amt
);
1552 set_aout_section_data (sec
, n
);
1553 relocs
= bfd_malloc (rel_size
);
1554 aout_section_data (sec
)->relocs
= relocs
;
1560 if (bfd_seek (abfd
, sec
->rel_filepos
, SEEK_SET
) != 0
1561 || bfd_bread (relocs
, rel_size
, abfd
) != rel_size
)
1564 if (obj_reloc_entry_size (abfd
) == RELOC_STD_SIZE
)
1566 if (! sunos_scan_std_relocs (info
, abfd
, sec
,
1567 (struct reloc_std_external
*) relocs
,
1573 if (! sunos_scan_ext_relocs (info
, abfd
, sec
,
1574 (struct reloc_ext_external
*) relocs
,
1579 if (free_relocs
!= NULL
)
1585 if (free_relocs
!= NULL
)
1590 /* Scan the relocs for an input section using standard relocs. We
1591 need to figure out what to do for each reloc against a dynamic
1592 symbol. If the symbol is in the .text section, an entry is made in
1593 the procedure linkage table. Note that this will do the wrong
1594 thing if the symbol is actually data; I don't think the Sun 3
1595 native linker handles this case correctly either. If the symbol is
1596 not in the .text section, we must preserve the reloc as a dynamic
1597 reloc. FIXME: We should also handle the PIC relocs here by
1598 building global offset table entries. */
1601 sunos_scan_std_relocs (info
, abfd
, sec
, relocs
, rel_size
)
1602 struct bfd_link_info
*info
;
1604 asection
*sec ATTRIBUTE_UNUSED
;
1605 const struct reloc_std_external
*relocs
;
1606 bfd_size_type rel_size
;
1609 asection
*splt
= NULL
;
1610 asection
*srel
= NULL
;
1611 struct sunos_link_hash_entry
**sym_hashes
;
1612 const struct reloc_std_external
*rel
, *relend
;
1614 /* We only know how to handle m68k plt entries. */
1615 if (bfd_get_arch (abfd
) != bfd_arch_m68k
)
1617 bfd_set_error (bfd_error_invalid_target
);
1623 sym_hashes
= (struct sunos_link_hash_entry
**) obj_aout_sym_hashes (abfd
);
1625 relend
= relocs
+ rel_size
/ RELOC_STD_SIZE
;
1626 for (rel
= relocs
; rel
< relend
; rel
++)
1629 struct sunos_link_hash_entry
*h
;
1631 /* We only want relocs against external symbols. */
1632 if (bfd_header_big_endian (abfd
))
1634 if ((rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_BIG
) == 0)
1639 if ((rel
->r_type
[0] & RELOC_STD_BITS_EXTERN_LITTLE
) == 0)
1643 /* Get the symbol index. */
1644 if (bfd_header_big_endian (abfd
))
1645 r_index
= ((rel
->r_index
[0] << 16)
1646 | (rel
->r_index
[1] << 8)
1649 r_index
= ((rel
->r_index
[2] << 16)
1650 | (rel
->r_index
[1] << 8)
1653 /* Get the hash table entry. */
1654 h
= sym_hashes
[r_index
];
1657 /* This should not normally happen, but it will in any case
1658 be caught in the relocation phase. */
1662 /* At this point common symbols have already been allocated, so
1663 we don't have to worry about them. We need to consider that
1664 we may have already seen this symbol and marked it undefined;
1665 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1667 if (h
->root
.root
.type
!= bfd_link_hash_defined
1668 && h
->root
.root
.type
!= bfd_link_hash_defweak
1669 && h
->root
.root
.type
!= bfd_link_hash_undefined
)
1672 if ((h
->flags
& SUNOS_DEF_DYNAMIC
) == 0
1673 || (h
->flags
& SUNOS_DEF_REGULAR
) != 0)
1680 if (! sunos_create_dynamic_sections (abfd
, info
, false))
1682 dynobj
= sunos_hash_table (info
)->dynobj
;
1683 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1684 srel
= bfd_get_section_by_name (dynobj
, ".dynrel");
1685 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
1687 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1688 BFD_ASSERT (sgot
!= NULL
);
1689 if (sgot
->_raw_size
== 0)
1690 sgot
->_raw_size
= BYTES_IN_WORD
;
1691 sunos_hash_table (info
)->got_needed
= true;
1694 BFD_ASSERT ((h
->flags
& SUNOS_REF_REGULAR
) != 0);
1695 BFD_ASSERT (h
->plt_offset
!= 0
1696 || ((h
->root
.root
.type
== bfd_link_hash_defined
1697 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1698 ? (h
->root
.root
.u
.def
.section
->owner
->flags
1700 : (h
->root
.root
.u
.undef
.abfd
->flags
& DYNAMIC
) != 0));
1702 /* This reloc is against a symbol defined only by a dynamic
1705 if (h
->root
.root
.type
== bfd_link_hash_undefined
)
1707 /* Presumably this symbol was marked as being undefined by
1708 an earlier reloc. */
1709 srel
->_raw_size
+= RELOC_STD_SIZE
;
1711 else if ((h
->root
.root
.u
.def
.section
->flags
& SEC_CODE
) == 0)
1715 /* This reloc is not in the .text section. It must be
1716 copied into the dynamic relocs. We mark the symbol as
1718 srel
->_raw_size
+= RELOC_STD_SIZE
;
1719 sub
= h
->root
.root
.u
.def
.section
->owner
;
1720 h
->root
.root
.type
= bfd_link_hash_undefined
;
1721 h
->root
.root
.u
.undef
.abfd
= sub
;
1725 /* This symbol is in the .text section. We must give it an
1726 entry in the procedure linkage table, if we have not
1727 already done so. We change the definition of the symbol
1728 to the .plt section; this will cause relocs against it to
1729 be handled correctly. */
1730 if (h
->plt_offset
== 0)
1732 if (splt
->_raw_size
== 0)
1733 splt
->_raw_size
= M68K_PLT_ENTRY_SIZE
;
1734 h
->plt_offset
= splt
->_raw_size
;
1736 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0)
1738 h
->root
.root
.u
.def
.section
= splt
;
1739 h
->root
.root
.u
.def
.value
= splt
->_raw_size
;
1742 splt
->_raw_size
+= M68K_PLT_ENTRY_SIZE
;
1744 /* We may also need a dynamic reloc entry. */
1745 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0)
1746 srel
->_raw_size
+= RELOC_STD_SIZE
;
1754 /* Scan the relocs for an input section using extended relocs. We
1755 need to figure out what to do for each reloc against a dynamic
1756 symbol. If the reloc is a WDISP30, and the symbol is in the .text
1757 section, an entry is made in the procedure linkage table.
1758 Otherwise, we must preserve the reloc as a dynamic reloc. */
1761 sunos_scan_ext_relocs (info
, abfd
, sec
, relocs
, rel_size
)
1762 struct bfd_link_info
*info
;
1764 asection
*sec ATTRIBUTE_UNUSED
;
1765 const struct reloc_ext_external
*relocs
;
1766 bfd_size_type rel_size
;
1769 struct sunos_link_hash_entry
**sym_hashes
;
1770 const struct reloc_ext_external
*rel
, *relend
;
1771 asection
*splt
= NULL
;
1772 asection
*sgot
= NULL
;
1773 asection
*srel
= NULL
;
1776 /* We only know how to handle SPARC plt entries. */
1777 if (bfd_get_arch (abfd
) != bfd_arch_sparc
)
1779 bfd_set_error (bfd_error_invalid_target
);
1785 sym_hashes
= (struct sunos_link_hash_entry
**) obj_aout_sym_hashes (abfd
);
1787 relend
= relocs
+ rel_size
/ RELOC_EXT_SIZE
;
1788 for (rel
= relocs
; rel
< relend
; rel
++)
1790 unsigned int r_index
;
1793 struct sunos_link_hash_entry
*h
= NULL
;
1795 /* Swap in the reloc information. */
1796 if (bfd_header_big_endian (abfd
))
1798 r_index
= ((rel
->r_index
[0] << 16)
1799 | (rel
->r_index
[1] << 8)
1801 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_BIG
));
1802 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
1803 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
1807 r_index
= ((rel
->r_index
[2] << 16)
1808 | (rel
->r_index
[1] << 8)
1810 r_extern
= (0 != (rel
->r_type
[0] & RELOC_EXT_BITS_EXTERN_LITTLE
));
1811 r_type
= ((rel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
1812 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
1817 h
= sym_hashes
[r_index
];
1820 /* This should not normally happen, but it will in any
1821 case be caught in the relocation phase. */
1826 /* If this is a base relative reloc, we need to make an entry in
1827 the .got section. */
1828 if (r_type
== RELOC_BASE10
1829 || r_type
== RELOC_BASE13
1830 || r_type
== RELOC_BASE22
)
1834 if (! sunos_create_dynamic_sections (abfd
, info
, false))
1836 dynobj
= sunos_hash_table (info
)->dynobj
;
1837 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1838 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1839 srel
= bfd_get_section_by_name (dynobj
, ".dynrel");
1840 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
1842 /* Make sure we have an initial entry in the .got table. */
1843 if (sgot
->_raw_size
== 0)
1844 sgot
->_raw_size
= BYTES_IN_WORD
;
1845 sunos_hash_table (info
)->got_needed
= true;
1850 if (h
->got_offset
!= 0)
1853 h
->got_offset
= sgot
->_raw_size
;
1857 if (r_index
>= bfd_get_symcount (abfd
))
1859 /* This is abnormal, but should be caught in the
1860 relocation phase. */
1864 if (adata (abfd
).local_got_offsets
== NULL
)
1866 amt
= bfd_get_symcount (abfd
);
1867 amt
*= sizeof (bfd_vma
);
1868 adata (abfd
).local_got_offsets
=
1869 (bfd_vma
*) bfd_zalloc (abfd
, amt
);
1870 if (adata (abfd
).local_got_offsets
== NULL
)
1874 if (adata (abfd
).local_got_offsets
[r_index
] != 0)
1877 adata (abfd
).local_got_offsets
[r_index
] = sgot
->_raw_size
;
1880 sgot
->_raw_size
+= BYTES_IN_WORD
;
1882 /* If we are making a shared library, or if the symbol is
1883 defined by a dynamic object, we will need a dynamic reloc
1887 && (h
->flags
& SUNOS_DEF_DYNAMIC
) != 0
1888 && (h
->flags
& SUNOS_DEF_REGULAR
) == 0))
1889 srel
->_raw_size
+= RELOC_EXT_SIZE
;
1894 /* Otherwise, we are only interested in relocs against symbols
1895 defined in dynamic objects but not in regular objects. We
1896 only need to consider relocs against external symbols. */
1899 /* But, if we are creating a shared library, we need to
1900 generate an absolute reloc. */
1905 if (! sunos_create_dynamic_sections (abfd
, info
, true))
1907 dynobj
= sunos_hash_table (info
)->dynobj
;
1908 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1909 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1910 srel
= bfd_get_section_by_name (dynobj
, ".dynrel");
1911 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
1914 srel
->_raw_size
+= RELOC_EXT_SIZE
;
1920 /* At this point common symbols have already been allocated, so
1921 we don't have to worry about them. We need to consider that
1922 we may have already seen this symbol and marked it undefined;
1923 if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
1925 if (h
->root
.root
.type
!= bfd_link_hash_defined
1926 && h
->root
.root
.type
!= bfd_link_hash_defweak
1927 && h
->root
.root
.type
!= bfd_link_hash_undefined
)
1930 if (r_type
!= RELOC_JMP_TBL
1932 && ((h
->flags
& SUNOS_DEF_DYNAMIC
) == 0
1933 || (h
->flags
& SUNOS_DEF_REGULAR
) != 0))
1936 if (r_type
== RELOC_JMP_TBL
1938 && (h
->flags
& SUNOS_DEF_DYNAMIC
) == 0
1939 && (h
->flags
& SUNOS_DEF_REGULAR
) == 0)
1941 /* This symbol is apparently undefined. Don't do anything
1942 here; just let the relocation routine report an undefined
1947 if (strcmp (h
->root
.root
.root
.string
, "__GLOBAL_OFFSET_TABLE_") == 0)
1952 if (! sunos_create_dynamic_sections (abfd
, info
, false))
1954 dynobj
= sunos_hash_table (info
)->dynobj
;
1955 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1956 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1957 srel
= bfd_get_section_by_name (dynobj
, ".dynrel");
1958 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
1960 /* Make sure we have an initial entry in the .got table. */
1961 if (sgot
->_raw_size
== 0)
1962 sgot
->_raw_size
= BYTES_IN_WORD
;
1963 sunos_hash_table (info
)->got_needed
= true;
1966 BFD_ASSERT (r_type
== RELOC_JMP_TBL
1968 || (h
->flags
& SUNOS_REF_REGULAR
) != 0);
1969 BFD_ASSERT (r_type
== RELOC_JMP_TBL
1971 || h
->plt_offset
!= 0
1972 || ((h
->root
.root
.type
== bfd_link_hash_defined
1973 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1974 ? (h
->root
.root
.u
.def
.section
->owner
->flags
1976 : (h
->root
.root
.u
.undef
.abfd
->flags
& DYNAMIC
) != 0));
1978 /* This reloc is against a symbol defined only by a dynamic
1979 object, or it is a jump table reloc from PIC compiled code. */
1981 if (r_type
!= RELOC_JMP_TBL
1982 && h
->root
.root
.type
== bfd_link_hash_undefined
)
1984 /* Presumably this symbol was marked as being undefined by
1985 an earlier reloc. */
1986 srel
->_raw_size
+= RELOC_EXT_SIZE
;
1988 else if (r_type
!= RELOC_JMP_TBL
1989 && (h
->root
.root
.u
.def
.section
->flags
& SEC_CODE
) == 0)
1993 /* This reloc is not in the .text section. It must be
1994 copied into the dynamic relocs. We mark the symbol as
1996 srel
->_raw_size
+= RELOC_EXT_SIZE
;
1997 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0)
1999 sub
= h
->root
.root
.u
.def
.section
->owner
;
2000 h
->root
.root
.type
= bfd_link_hash_undefined
;
2001 h
->root
.root
.u
.undef
.abfd
= sub
;
2006 /* This symbol is in the .text section. We must give it an
2007 entry in the procedure linkage table, if we have not
2008 already done so. We change the definition of the symbol
2009 to the .plt section; this will cause relocs against it to
2010 be handled correctly. */
2011 if (h
->plt_offset
== 0)
2013 if (splt
->_raw_size
== 0)
2014 splt
->_raw_size
= SPARC_PLT_ENTRY_SIZE
;
2015 h
->plt_offset
= splt
->_raw_size
;
2017 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0)
2019 if (h
->root
.root
.type
== bfd_link_hash_undefined
)
2020 h
->root
.root
.type
= bfd_link_hash_defined
;
2021 h
->root
.root
.u
.def
.section
= splt
;
2022 h
->root
.root
.u
.def
.value
= splt
->_raw_size
;
2025 splt
->_raw_size
+= SPARC_PLT_ENTRY_SIZE
;
2027 /* We will also need a dynamic reloc entry, unless this
2028 is a JMP_TBL reloc produced by linking PIC compiled
2029 code, and we are not making a shared library. */
2030 if (info
->shared
|| (h
->flags
& SUNOS_DEF_REGULAR
) == 0)
2031 srel
->_raw_size
+= RELOC_EXT_SIZE
;
2034 /* If we are creating a shared library, we need to copy over
2035 any reloc other than a jump table reloc. */
2036 if (info
->shared
&& r_type
!= RELOC_JMP_TBL
)
2037 srel
->_raw_size
+= RELOC_EXT_SIZE
;
2044 /* Build the hash table of dynamic symbols, and to mark as written all
2045 symbols from dynamic objects which we do not plan to write out. */
2048 sunos_scan_dynamic_symbol (h
, data
)
2049 struct sunos_link_hash_entry
*h
;
2052 struct bfd_link_info
*info
= (struct bfd_link_info
*) data
;
2054 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2055 h
= (struct sunos_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2057 /* Set the written flag for symbols we do not want to write out as
2058 part of the regular symbol table. This is all symbols which are
2059 not defined in a regular object file. For some reason symbols
2060 which are referenced by a regular object and defined by a dynamic
2061 object do not seem to show up in the regular symbol table. It is
2062 possible for a symbol to have only SUNOS_REF_REGULAR set here, it
2063 is an undefined symbol which was turned into a common symbol
2064 because it was found in an archive object which was not included
2066 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0
2067 && (h
->flags
& SUNOS_DEF_DYNAMIC
) != 0
2068 && strcmp (h
->root
.root
.root
.string
, "__DYNAMIC") != 0)
2069 h
->root
.written
= true;
2071 /* If this symbol is defined by a dynamic object and referenced by a
2072 regular object, see whether we gave it a reasonable value while
2073 scanning the relocs. */
2075 if ((h
->flags
& SUNOS_DEF_REGULAR
) == 0
2076 && (h
->flags
& SUNOS_DEF_DYNAMIC
) != 0
2077 && (h
->flags
& SUNOS_REF_REGULAR
) != 0)
2079 if ((h
->root
.root
.type
== bfd_link_hash_defined
2080 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2081 && ((h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
) != 0)
2082 && h
->root
.root
.u
.def
.section
->output_section
== NULL
)
2086 /* This symbol is currently defined in a dynamic section
2087 which is not being put into the output file. This
2088 implies that there is no reloc against the symbol. I'm
2089 not sure why this case would ever occur. In any case, we
2090 change the symbol to be undefined. */
2091 sub
= h
->root
.root
.u
.def
.section
->owner
;
2092 h
->root
.root
.type
= bfd_link_hash_undefined
;
2093 h
->root
.root
.u
.undef
.abfd
= sub
;
2097 /* If this symbol is defined or referenced by a regular file, add it
2098 to the dynamic symbols. */
2099 if ((h
->flags
& (SUNOS_DEF_REGULAR
| SUNOS_REF_REGULAR
)) != 0)
2104 unsigned char *name
;
2108 BFD_ASSERT (h
->dynindx
== -2);
2110 dynobj
= sunos_hash_table (info
)->dynobj
;
2112 h
->dynindx
= sunos_hash_table (info
)->dynsymcount
;
2113 ++sunos_hash_table (info
)->dynsymcount
;
2115 len
= strlen (h
->root
.root
.root
.string
);
2117 /* We don't bother to construct a BFD hash table for the strings
2118 which are the names of the dynamic symbols. Using a hash
2119 table for the regular symbols is beneficial, because the
2120 regular symbols includes the debugging symbols, which have
2121 long names and are often duplicated in several object files.
2122 There are no debugging symbols in the dynamic symbols. */
2123 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
2124 BFD_ASSERT (s
!= NULL
);
2125 contents
= (bfd_byte
*) bfd_realloc (s
->contents
,
2126 s
->_raw_size
+ len
+ 1);
2127 if (contents
== NULL
)
2129 s
->contents
= contents
;
2131 h
->dynstr_index
= s
->_raw_size
;
2132 strcpy ((char *) contents
+ s
->_raw_size
, h
->root
.root
.root
.string
);
2133 s
->_raw_size
+= len
+ 1;
2135 /* Add it to the dynamic hash table. */
2136 name
= (unsigned char *) h
->root
.root
.root
.string
;
2138 while (*name
!= '\0')
2139 hash
= (hash
<< 1) + *name
++;
2141 hash
%= sunos_hash_table (info
)->bucketcount
;
2143 s
= bfd_get_section_by_name (dynobj
, ".hash");
2144 BFD_ASSERT (s
!= NULL
);
2146 if (GET_SWORD (dynobj
, s
->contents
+ hash
* HASH_ENTRY_SIZE
) == -1)
2147 PUT_WORD (dynobj
, h
->dynindx
, s
->contents
+ hash
* HASH_ENTRY_SIZE
);
2152 next
= GET_WORD (dynobj
,
2154 + hash
* HASH_ENTRY_SIZE
2156 PUT_WORD (dynobj
, s
->_raw_size
/ HASH_ENTRY_SIZE
,
2157 s
->contents
+ hash
* HASH_ENTRY_SIZE
+ BYTES_IN_WORD
);
2158 PUT_WORD (dynobj
, h
->dynindx
, s
->contents
+ s
->_raw_size
);
2159 PUT_WORD (dynobj
, next
, s
->contents
+ s
->_raw_size
+ BYTES_IN_WORD
);
2160 s
->_raw_size
+= HASH_ENTRY_SIZE
;
2167 /* Link a dynamic object. We actually don't have anything to do at
2168 this point. This entry point exists to prevent the regular linker
2169 code from doing anything with the object. */
2173 sunos_link_dynamic_object (info
, abfd
)
2174 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2175 bfd
*abfd ATTRIBUTE_UNUSED
;
2180 /* Write out a dynamic symbol. This is called by the final traversal
2181 over the symbol table. */
2184 sunos_write_dynamic_symbol (output_bfd
, info
, harg
)
2186 struct bfd_link_info
*info
;
2187 struct aout_link_hash_entry
*harg
;
2189 struct sunos_link_hash_entry
*h
= (struct sunos_link_hash_entry
*) harg
;
2193 struct external_nlist
*outsym
;
2195 /* If this symbol is in the procedure linkage table, fill in the
2197 if (h
->plt_offset
!= 0)
2204 dynobj
= sunos_hash_table (info
)->dynobj
;
2205 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2206 p
= splt
->contents
+ h
->plt_offset
;
2208 s
= bfd_get_section_by_name (dynobj
, ".dynrel");
2210 r_address
= (splt
->output_section
->vma
2211 + splt
->output_offset
2214 switch (bfd_get_arch (output_bfd
))
2216 case bfd_arch_sparc
:
2217 if (info
->shared
|| (h
->flags
& SUNOS_DEF_REGULAR
) == 0)
2219 bfd_put_32 (output_bfd
, SPARC_PLT_ENTRY_WORD0
, p
);
2220 bfd_put_32 (output_bfd
,
2221 (SPARC_PLT_ENTRY_WORD1
2222 + (((- (h
->plt_offset
+ 4) >> 2)
2225 bfd_put_32 (output_bfd
, SPARC_PLT_ENTRY_WORD2
+ s
->reloc_count
,
2230 val
= (h
->root
.root
.u
.def
.section
->output_section
->vma
2231 + h
->root
.root
.u
.def
.section
->output_offset
2232 + h
->root
.root
.u
.def
.value
);
2233 bfd_put_32 (output_bfd
,
2234 SPARC_PLT_PIC_WORD0
+ ((val
>> 10) & 0x3fffff),
2236 bfd_put_32 (output_bfd
,
2237 SPARC_PLT_PIC_WORD1
+ (val
& 0x3ff),
2239 bfd_put_32 (output_bfd
, SPARC_PLT_PIC_WORD2
, p
+ 8);
2244 if (! info
->shared
&& (h
->flags
& SUNOS_DEF_REGULAR
) != 0)
2246 bfd_put_16 (output_bfd
, M68K_PLT_ENTRY_WORD0
, p
);
2247 bfd_put_32 (output_bfd
, (- (h
->plt_offset
+ 2)), p
+ 2);
2248 bfd_put_16 (output_bfd
, (bfd_vma
) s
->reloc_count
, p
+ 6);
2256 /* We also need to add a jump table reloc, unless this is the
2257 result of a JMP_TBL reloc from PIC compiled code. */
2258 if (info
->shared
|| (h
->flags
& SUNOS_DEF_REGULAR
) == 0)
2260 BFD_ASSERT (h
->dynindx
>= 0);
2261 BFD_ASSERT (s
->reloc_count
* obj_reloc_entry_size (dynobj
)
2263 p
= s
->contents
+ s
->reloc_count
* obj_reloc_entry_size (output_bfd
);
2264 if (obj_reloc_entry_size (output_bfd
) == RELOC_STD_SIZE
)
2266 struct reloc_std_external
*srel
;
2268 srel
= (struct reloc_std_external
*) p
;
2269 PUT_WORD (output_bfd
, r_address
, srel
->r_address
);
2270 if (bfd_header_big_endian (output_bfd
))
2272 srel
->r_index
[0] = (bfd_byte
) (h
->dynindx
>> 16);
2273 srel
->r_index
[1] = (bfd_byte
) (h
->dynindx
>> 8);
2274 srel
->r_index
[2] = (bfd_byte
) (h
->dynindx
);
2275 srel
->r_type
[0] = (RELOC_STD_BITS_EXTERN_BIG
2276 | RELOC_STD_BITS_JMPTABLE_BIG
);
2280 srel
->r_index
[2] = (bfd_byte
) (h
->dynindx
>> 16);
2281 srel
->r_index
[1] = (bfd_byte
) (h
->dynindx
>> 8);
2282 srel
->r_index
[0] = (bfd_byte
)h
->dynindx
;
2283 srel
->r_type
[0] = (RELOC_STD_BITS_EXTERN_LITTLE
2284 | RELOC_STD_BITS_JMPTABLE_LITTLE
);
2289 struct reloc_ext_external
*erel
;
2291 erel
= (struct reloc_ext_external
*) p
;
2292 PUT_WORD (output_bfd
, r_address
, erel
->r_address
);
2293 if (bfd_header_big_endian (output_bfd
))
2295 erel
->r_index
[0] = (bfd_byte
) (h
->dynindx
>> 16);
2296 erel
->r_index
[1] = (bfd_byte
) (h
->dynindx
>> 8);
2297 erel
->r_index
[2] = (bfd_byte
)h
->dynindx
;
2299 (RELOC_EXT_BITS_EXTERN_BIG
2300 | (RELOC_JMP_SLOT
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2304 erel
->r_index
[2] = (bfd_byte
) (h
->dynindx
>> 16);
2305 erel
->r_index
[1] = (bfd_byte
) (h
->dynindx
>> 8);
2306 erel
->r_index
[0] = (bfd_byte
)h
->dynindx
;
2308 (RELOC_EXT_BITS_EXTERN_LITTLE
2309 | (RELOC_JMP_SLOT
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2311 PUT_WORD (output_bfd
, (bfd_vma
) 0, erel
->r_addend
);
2318 /* If this is not a dynamic symbol, we don't have to do anything
2319 else. We only check this after handling the PLT entry, because
2320 we can have a PLT entry for a nondynamic symbol when linking PIC
2321 compiled code from a regular object. */
2325 switch (h
->root
.root
.type
)
2328 case bfd_link_hash_new
:
2330 /* Avoid variable not initialized warnings. */
2332 case bfd_link_hash_undefined
:
2333 type
= N_UNDF
| N_EXT
;
2336 case bfd_link_hash_defined
:
2337 case bfd_link_hash_defweak
:
2340 asection
*output_section
;
2342 sec
= h
->root
.root
.u
.def
.section
;
2343 output_section
= sec
->output_section
;
2344 BFD_ASSERT (bfd_is_abs_section (output_section
)
2345 || output_section
->owner
== output_bfd
);
2346 if (h
->plt_offset
!= 0
2347 && (h
->flags
& SUNOS_DEF_REGULAR
) == 0)
2349 type
= N_UNDF
| N_EXT
;
2354 if (output_section
== obj_textsec (output_bfd
))
2355 type
= (h
->root
.root
.type
== bfd_link_hash_defined
2358 else if (output_section
== obj_datasec (output_bfd
))
2359 type
= (h
->root
.root
.type
== bfd_link_hash_defined
2362 else if (output_section
== obj_bsssec (output_bfd
))
2363 type
= (h
->root
.root
.type
== bfd_link_hash_defined
2367 type
= (h
->root
.root
.type
== bfd_link_hash_defined
2371 val
= (h
->root
.root
.u
.def
.value
2372 + output_section
->vma
2373 + sec
->output_offset
);
2377 case bfd_link_hash_common
:
2378 type
= N_UNDF
| N_EXT
;
2379 val
= h
->root
.root
.u
.c
.size
;
2381 case bfd_link_hash_undefweak
:
2385 case bfd_link_hash_indirect
:
2386 case bfd_link_hash_warning
:
2387 /* FIXME: Ignore these for now. The circumstances under which
2388 they should be written out are not clear to me. */
2392 s
= bfd_get_section_by_name (sunos_hash_table (info
)->dynobj
, ".dynsym");
2393 BFD_ASSERT (s
!= NULL
);
2394 outsym
= ((struct external_nlist
*)
2395 (s
->contents
+ h
->dynindx
* EXTERNAL_NLIST_SIZE
));
2397 H_PUT_8 (output_bfd
, type
, outsym
->e_type
);
2398 H_PUT_8 (output_bfd
, 0, outsym
->e_other
);
2400 /* FIXME: The native linker doesn't use 0 for desc. It seems to use
2401 one less than the desc value in the shared library, although that
2403 H_PUT_16 (output_bfd
, 0, outsym
->e_desc
);
2405 PUT_WORD (output_bfd
, h
->dynstr_index
, outsym
->e_strx
);
2406 PUT_WORD (output_bfd
, val
, outsym
->e_value
);
2411 /* This is called for each reloc against an external symbol. If this
2412 is a reloc which are are going to copy as a dynamic reloc, then
2413 copy it over, and tell the caller to not bother processing this
2418 sunos_check_dynamic_reloc (info
, input_bfd
, input_section
, harg
, reloc
,
2419 contents
, skip
, relocationp
)
2420 struct bfd_link_info
*info
;
2422 asection
*input_section
;
2423 struct aout_link_hash_entry
*harg
;
2425 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2427 bfd_vma
*relocationp
;
2429 struct sunos_link_hash_entry
*h
= (struct sunos_link_hash_entry
*) harg
;
2440 dynobj
= sunos_hash_table (info
)->dynobj
;
2443 && h
->plt_offset
!= 0
2445 || (h
->flags
& SUNOS_DEF_REGULAR
) == 0))
2449 /* Redirect the relocation to the PLT entry. */
2450 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2451 *relocationp
= (splt
->output_section
->vma
2452 + splt
->output_offset
2456 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
2458 struct reloc_std_external
*srel
;
2460 srel
= (struct reloc_std_external
*) reloc
;
2461 if (bfd_header_big_endian (input_bfd
))
2463 baserel
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_BASEREL_BIG
));
2464 jmptbl
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_BIG
));
2465 pcrel
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_PCREL_BIG
));
2469 baserel
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_BASEREL_LITTLE
));
2470 jmptbl
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_JMPTABLE_LITTLE
));
2471 pcrel
= (0 != (srel
->r_type
[0] & RELOC_STD_BITS_PCREL_LITTLE
));
2476 struct reloc_ext_external
*erel
;
2479 erel
= (struct reloc_ext_external
*) reloc
;
2480 if (bfd_header_big_endian (input_bfd
))
2481 r_type
= ((erel
->r_type
[0] & RELOC_EXT_BITS_TYPE_BIG
)
2482 >> RELOC_EXT_BITS_TYPE_SH_BIG
);
2484 r_type
= ((erel
->r_type
[0] & RELOC_EXT_BITS_TYPE_LITTLE
)
2485 >> RELOC_EXT_BITS_TYPE_SH_LITTLE
);
2486 baserel
= (r_type
== RELOC_BASE10
2487 || r_type
== RELOC_BASE13
2488 || r_type
== RELOC_BASE22
);
2489 jmptbl
= r_type
== RELOC_JMP_TBL
;
2490 pcrel
= (r_type
== RELOC_DISP8
2491 || r_type
== RELOC_DISP16
2492 || r_type
== RELOC_DISP32
2493 || r_type
== RELOC_WDISP30
2494 || r_type
== RELOC_WDISP22
);
2495 /* We don't consider the PC10 and PC22 types to be PC relative,
2496 because they are pcrel_offset. */
2501 bfd_vma
*got_offsetp
;
2505 got_offsetp
= &h
->got_offset
;
2506 else if (adata (input_bfd
).local_got_offsets
== NULL
)
2510 struct reloc_std_external
*srel
;
2513 srel
= (struct reloc_std_external
*) reloc
;
2514 if (obj_reloc_entry_size (input_bfd
) == RELOC_STD_SIZE
)
2516 if (bfd_header_big_endian (input_bfd
))
2517 r_index
= ((srel
->r_index
[0] << 16)
2518 | (srel
->r_index
[1] << 8)
2519 | srel
->r_index
[2]);
2521 r_index
= ((srel
->r_index
[2] << 16)
2522 | (srel
->r_index
[1] << 8)
2523 | srel
->r_index
[0]);
2527 struct reloc_ext_external
*erel
;
2529 erel
= (struct reloc_ext_external
*) reloc
;
2530 if (bfd_header_big_endian (input_bfd
))
2531 r_index
= ((erel
->r_index
[0] << 16)
2532 | (erel
->r_index
[1] << 8)
2533 | erel
->r_index
[2]);
2535 r_index
= ((erel
->r_index
[2] << 16)
2536 | (erel
->r_index
[1] << 8)
2537 | erel
->r_index
[0]);
2540 got_offsetp
= adata (input_bfd
).local_got_offsets
+ r_index
;
2543 BFD_ASSERT (got_offsetp
!= NULL
&& *got_offsetp
!= 0);
2545 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2547 /* We set the least significant bit to indicate whether we have
2548 already initialized the GOT entry. */
2549 if ((*got_offsetp
& 1) == 0)
2553 && ((h
->flags
& SUNOS_DEF_DYNAMIC
) == 0
2554 || (h
->flags
& SUNOS_DEF_REGULAR
) != 0)))
2555 PUT_WORD (dynobj
, *relocationp
, sgot
->contents
+ *got_offsetp
);
2557 PUT_WORD (dynobj
, 0, sgot
->contents
+ *got_offsetp
);
2561 && (h
->flags
& SUNOS_DEF_DYNAMIC
) != 0
2562 && (h
->flags
& SUNOS_DEF_REGULAR
) == 0))
2564 /* We need to create a GLOB_DAT or 32 reloc to tell the
2565 dynamic linker to fill in this entry in the table. */
2567 s
= bfd_get_section_by_name (dynobj
, ".dynrel");
2568 BFD_ASSERT (s
!= NULL
);
2569 BFD_ASSERT (s
->reloc_count
* obj_reloc_entry_size (dynobj
)
2573 + s
->reloc_count
* obj_reloc_entry_size (dynobj
));
2580 if (obj_reloc_entry_size (dynobj
) == RELOC_STD_SIZE
)
2582 struct reloc_std_external
*srel
;
2584 srel
= (struct reloc_std_external
*) p
;
2587 + sgot
->output_section
->vma
2588 + sgot
->output_offset
),
2590 if (bfd_header_big_endian (dynobj
))
2592 srel
->r_index
[0] = (bfd_byte
) (indx
>> 16);
2593 srel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2594 srel
->r_index
[2] = (bfd_byte
)indx
;
2596 srel
->r_type
[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG
;
2599 (RELOC_STD_BITS_EXTERN_BIG
2600 | RELOC_STD_BITS_BASEREL_BIG
2601 | RELOC_STD_BITS_RELATIVE_BIG
2602 | (2 << RELOC_STD_BITS_LENGTH_SH_BIG
));
2606 srel
->r_index
[2] = (bfd_byte
) (indx
>> 16);
2607 srel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2608 srel
->r_index
[0] = (bfd_byte
)indx
;
2610 srel
->r_type
[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE
;
2613 (RELOC_STD_BITS_EXTERN_LITTLE
2614 | RELOC_STD_BITS_BASEREL_LITTLE
2615 | RELOC_STD_BITS_RELATIVE_LITTLE
2616 | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE
));
2621 struct reloc_ext_external
*erel
;
2623 erel
= (struct reloc_ext_external
*) p
;
2626 + sgot
->output_section
->vma
2627 + sgot
->output_offset
),
2629 if (bfd_header_big_endian (dynobj
))
2631 erel
->r_index
[0] = (bfd_byte
) (indx
>> 16);
2632 erel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2633 erel
->r_index
[2] = (bfd_byte
)indx
;
2636 RELOC_32
<< RELOC_EXT_BITS_TYPE_SH_BIG
;
2639 (RELOC_EXT_BITS_EXTERN_BIG
2640 | (RELOC_GLOB_DAT
<< RELOC_EXT_BITS_TYPE_SH_BIG
));
2644 erel
->r_index
[2] = (bfd_byte
) (indx
>> 16);
2645 erel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2646 erel
->r_index
[0] = (bfd_byte
)indx
;
2649 RELOC_32
<< RELOC_EXT_BITS_TYPE_SH_LITTLE
;
2652 (RELOC_EXT_BITS_EXTERN_LITTLE
2654 << RELOC_EXT_BITS_TYPE_SH_LITTLE
));
2656 PUT_WORD (dynobj
, 0, erel
->r_addend
);
2665 *relocationp
= (sgot
->vma
2666 + (*got_offsetp
&~ (bfd_vma
) 1)
2667 - sunos_hash_table (info
)->got_base
);
2669 /* There is nothing else to do for a base relative reloc. */
2673 if (! sunos_hash_table (info
)->dynamic_sections_needed
)
2679 || h
->root
.root
.type
!= bfd_link_hash_undefined
2680 || (h
->flags
& SUNOS_DEF_REGULAR
) != 0
2681 || (h
->flags
& SUNOS_DEF_DYNAMIC
) == 0
2682 || (h
->root
.root
.u
.undef
.abfd
->flags
& DYNAMIC
) == 0)
2688 && (h
->dynindx
== -1
2690 || strcmp (h
->root
.root
.root
.string
,
2691 "__GLOBAL_OFFSET_TABLE_") == 0))
2695 /* It looks like this is a reloc we are supposed to copy. */
2697 s
= bfd_get_section_by_name (dynobj
, ".dynrel");
2698 BFD_ASSERT (s
!= NULL
);
2699 BFD_ASSERT (s
->reloc_count
* obj_reloc_entry_size (dynobj
) < s
->_raw_size
);
2701 p
= s
->contents
+ s
->reloc_count
* obj_reloc_entry_size (dynobj
);
2703 /* Copy the reloc over. */
2704 memcpy (p
, reloc
, obj_reloc_entry_size (dynobj
));
2711 /* Adjust the address and symbol index. */
2712 if (obj_reloc_entry_size (dynobj
) == RELOC_STD_SIZE
)
2714 struct reloc_std_external
*srel
;
2716 srel
= (struct reloc_std_external
*) p
;
2718 (GET_WORD (dynobj
, srel
->r_address
)
2719 + input_section
->output_section
->vma
2720 + input_section
->output_offset
),
2722 if (bfd_header_big_endian (dynobj
))
2724 srel
->r_index
[0] = (bfd_byte
) (indx
>> 16);
2725 srel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2726 srel
->r_index
[2] = (bfd_byte
)indx
;
2730 srel
->r_index
[2] = (bfd_byte
) (indx
>> 16);
2731 srel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2732 srel
->r_index
[0] = (bfd_byte
)indx
;
2734 /* FIXME: We may have to change the addend for a PC relative
2739 struct reloc_ext_external
*erel
;
2741 erel
= (struct reloc_ext_external
*) p
;
2743 (GET_WORD (dynobj
, erel
->r_address
)
2744 + input_section
->output_section
->vma
2745 + input_section
->output_offset
),
2747 if (bfd_header_big_endian (dynobj
))
2749 erel
->r_index
[0] = (bfd_byte
) (indx
>> 16);
2750 erel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2751 erel
->r_index
[2] = (bfd_byte
)indx
;
2755 erel
->r_index
[2] = (bfd_byte
) (indx
>> 16);
2756 erel
->r_index
[1] = (bfd_byte
) (indx
>> 8);
2757 erel
->r_index
[0] = (bfd_byte
)indx
;
2759 if (pcrel
&& h
!= NULL
)
2761 /* Adjust the addend for the change in address. */
2763 (GET_WORD (dynobj
, erel
->r_addend
)
2764 - (input_section
->output_section
->vma
2765 + input_section
->output_offset
2766 - input_section
->vma
)),
2779 /* Finish up the dynamic linking information. */
2782 sunos_finish_dynamic_link (abfd
, info
)
2784 struct bfd_link_info
*info
;
2791 if (! sunos_hash_table (info
)->dynamic_sections_needed
2792 && ! sunos_hash_table (info
)->got_needed
)
2795 dynobj
= sunos_hash_table (info
)->dynobj
;
2797 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2798 BFD_ASSERT (sdyn
!= NULL
);
2800 /* Finish up the .need section. The linker emulation code filled it
2801 in, but with offsets from the start of the section instead of
2802 real addresses. Now that we know the section location, we can
2803 fill in the final values. */
2804 s
= bfd_get_section_by_name (dynobj
, ".need");
2805 if (s
!= NULL
&& s
->_raw_size
!= 0)
2810 filepos
= s
->output_section
->filepos
+ s
->output_offset
;
2816 PUT_WORD (dynobj
, GET_WORD (dynobj
, p
) + filepos
, p
);
2817 val
= GET_WORD (dynobj
, p
+ 12);
2820 PUT_WORD (dynobj
, val
+ filepos
, p
+ 12);
2825 /* The first entry in the .got section is the address of the
2826 dynamic information, unless this is a shared library. */
2827 s
= bfd_get_section_by_name (dynobj
, ".got");
2828 BFD_ASSERT (s
!= NULL
);
2829 if (info
->shared
|| sdyn
->_raw_size
== 0)
2830 PUT_WORD (dynobj
, 0, s
->contents
);
2832 PUT_WORD (dynobj
, sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2835 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
2837 if ((o
->flags
& SEC_HAS_CONTENTS
) != 0
2838 && o
->contents
!= NULL
)
2840 BFD_ASSERT (o
->output_section
!= NULL
2841 && o
->output_section
->owner
== abfd
);
2842 if (! bfd_set_section_contents (abfd
, o
->output_section
,
2844 (file_ptr
) o
->output_offset
,
2850 if (sdyn
->_raw_size
> 0)
2852 struct external_sun4_dynamic esd
;
2853 struct external_sun4_dynamic_link esdl
;
2856 /* Finish up the dynamic link information. */
2857 PUT_WORD (dynobj
, (bfd_vma
) 3, esd
.ld_version
);
2859 sdyn
->output_section
->vma
+ sdyn
->output_offset
+ sizeof esd
,
2862 (sdyn
->output_section
->vma
2863 + sdyn
->output_offset
2865 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
),
2868 if (! bfd_set_section_contents (abfd
, sdyn
->output_section
, &esd
,
2869 (file_ptr
) sdyn
->output_offset
,
2870 (bfd_size_type
) sizeof esd
))
2873 PUT_WORD (dynobj
, (bfd_vma
) 0, esdl
.ld_loaded
);
2875 s
= bfd_get_section_by_name (dynobj
, ".need");
2876 if (s
== NULL
|| s
->_raw_size
== 0)
2877 PUT_WORD (dynobj
, (bfd_vma
) 0, esdl
.ld_need
);
2879 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2882 s
= bfd_get_section_by_name (dynobj
, ".rules");
2883 if (s
== NULL
|| s
->_raw_size
== 0)
2884 PUT_WORD (dynobj
, (bfd_vma
) 0, esdl
.ld_rules
);
2886 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2889 s
= bfd_get_section_by_name (dynobj
, ".got");
2890 BFD_ASSERT (s
!= NULL
);
2891 PUT_WORD (dynobj
, s
->output_section
->vma
+ s
->output_offset
,
2894 s
= bfd_get_section_by_name (dynobj
, ".plt");
2895 BFD_ASSERT (s
!= NULL
);
2896 PUT_WORD (dynobj
, s
->output_section
->vma
+ s
->output_offset
,
2898 PUT_WORD (dynobj
, s
->_raw_size
, esdl
.ld_plt_sz
);
2900 s
= bfd_get_section_by_name (dynobj
, ".dynrel");
2901 BFD_ASSERT (s
!= NULL
);
2902 BFD_ASSERT (s
->reloc_count
* obj_reloc_entry_size (dynobj
)
2904 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2907 s
= bfd_get_section_by_name (dynobj
, ".hash");
2908 BFD_ASSERT (s
!= NULL
);
2909 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2912 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
2913 BFD_ASSERT (s
!= NULL
);
2914 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2917 PUT_WORD (dynobj
, (bfd_vma
) 0, esdl
.ld_stab_hash
);
2919 PUT_WORD (dynobj
, (bfd_vma
) sunos_hash_table (info
)->bucketcount
,
2922 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
2923 BFD_ASSERT (s
!= NULL
);
2924 PUT_WORD (dynobj
, s
->output_section
->filepos
+ s
->output_offset
,
2926 PUT_WORD (dynobj
, s
->_raw_size
, esdl
.ld_symb_size
);
2928 /* The size of the text area is the size of the .text section
2929 rounded up to a page boundary. FIXME: Should the page size be
2930 conditional on something? */
2932 BFD_ALIGN (obj_textsec (abfd
)->_raw_size
, 0x2000),
2935 pos
= sdyn
->output_offset
;
2936 pos
+= sizeof esd
+ EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
;
2937 if (! bfd_set_section_contents (abfd
, sdyn
->output_section
, &esdl
,
2938 pos
, (bfd_size_type
) sizeof esdl
))
2941 abfd
->flags
|= DYNAMIC
;