#define TARGETNAME "a.out-sunos-big"
#define MY(OP) CONCAT2 (sunos_big_,OP)
#include "bfd.h"
#include "bfdlink.h"
#include "libaout.h"
#define MACHTYPE_OK(mtype) \
(((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
|| ((mtype) == M_SPARCLET \
&& bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
|| ((mtype) == M_SPARCLITE_LE \
&& bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
|| (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
&& bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
#define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound
#define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab
#define MY_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
#define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound
#define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc
#define MY_bfd_link_hash_table_create sunos_link_hash_table_create
#define MY_add_dynamic_symbols sunos_add_dynamic_symbols
#define MY_add_one_symbol sunos_add_one_symbol
#define MY_link_dynamic_object sunos_link_dynamic_object
#define MY_write_dynamic_symbol sunos_write_dynamic_symbol
#define MY_check_dynamic_reloc sunos_check_dynamic_reloc
#define MY_finish_dynamic_link sunos_finish_dynamic_link
static bfd_boolean sunos_add_dynamic_symbols (bfd *, struct bfd_link_info *, struct external_nlist **, bfd_size_type *, char **);
static bfd_boolean sunos_add_one_symbol (struct bfd_link_info *, bfd *, const char *, flagword, asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, struct bfd_link_hash_entry **);
static bfd_boolean sunos_link_dynamic_object (struct bfd_link_info *, bfd *);
static bfd_boolean sunos_write_dynamic_symbol (bfd *, struct bfd_link_info *, struct aout_link_hash_entry *);
static bfd_boolean sunos_check_dynamic_reloc (struct bfd_link_info *, bfd *, asection *, struct aout_link_hash_entry *, void *, bfd_byte *, bfd_boolean *, bfd_vma *);
static bfd_boolean sunos_finish_dynamic_link (bfd *, struct bfd_link_info *);
static struct bfd_link_hash_table *sunos_link_hash_table_create (bfd *);
static long sunos_get_dynamic_symtab_upper_bound (bfd *);
static long sunos_canonicalize_dynamic_symtab (bfd *, asymbol **);
static long sunos_get_dynamic_reloc_upper_bound (bfd *);
static long sunos_canonicalize_dynamic_reloc (bfd *, arelent **, asymbol **);
#include "aoutf1.h"
#undef valid
struct sunos_dynamic_info
{
bfd_boolean valid;
struct internal_sun4_dynamic_link dyninfo;
unsigned long dynsym_count;
struct external_nlist *dynsym;
aout_symbol_type *canonical_dynsym;
char *dynstr;
unsigned long dynrel_count;
void * dynrel;
arelent *canonical_dynrel;
};
#define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
static bfd_boolean
sunos_read_dynamic_info (bfd *abfd)
{
struct sunos_dynamic_info *info;
asection *dynsec;
bfd_vma dynoff;
struct external_sun4_dynamic dyninfo;
unsigned long dynver;
struct external_sun4_dynamic_link linkinfo;
bfd_size_type amt;
if (obj_aout_dynamic_info (abfd) != NULL)
return TRUE;
if ((abfd->flags & DYNAMIC) == 0)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
}
amt = sizeof (struct sunos_dynamic_info);
info = bfd_zalloc (abfd, amt);
if (!info)
return FALSE;
info->valid = FALSE;
info->dynsym = NULL;
info->dynstr = NULL;
info->canonical_dynsym = NULL;
info->dynrel = NULL;
info->canonical_dynrel = NULL;
obj_aout_dynamic_info (abfd) = (void *) info;
if ((abfd->flags & DYNAMIC) == 0)
return TRUE;
if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (void *) &dyninfo,
(file_ptr) 0,
(bfd_size_type) sizeof dyninfo))
return TRUE;
dynver = GET_WORD (abfd, dyninfo.ld_version);
if (dynver != 2 && dynver != 3)
return TRUE;
dynoff = GET_WORD (abfd, dyninfo.ld);
if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
dynsec = obj_textsec (abfd);
else
dynsec = obj_datasec (abfd);
dynoff -= bfd_get_section_vma (abfd, dynsec);
if (dynoff > dynsec->size)
return TRUE;
if (! bfd_get_section_contents (abfd, dynsec, (void *) &linkinfo,
(file_ptr) dynoff,
(bfd_size_type) sizeof linkinfo))
return TRUE;
info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
if (adata (abfd).magic == n_magic)
{
unsigned long exec_bytes_size = adata (abfd).exec_bytes_size;
info->dyninfo.ld_need += exec_bytes_size;
info->dyninfo.ld_rules += exec_bytes_size;
info->dyninfo.ld_rel += exec_bytes_size;
info->dyninfo.ld_hash += exec_bytes_size;
info->dyninfo.ld_stab += exec_bytes_size;
info->dyninfo.ld_symbols += exec_bytes_size;
}
info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
/ EXTERNAL_NLIST_SIZE);
BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
== (unsigned long) (info->dyninfo.ld_symbols
- info->dyninfo.ld_stab));
info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
/ obj_reloc_entry_size (abfd));
BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
== (unsigned long) (info->dyninfo.ld_hash
- info->dyninfo.ld_rel));
info->valid = TRUE;
return TRUE;
}
static long
sunos_get_dynamic_symtab_upper_bound (bfd *abfd)
{
struct sunos_dynamic_info *info;
if (! sunos_read_dynamic_info (abfd))
return -1;
info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
if (! info->valid)
{
bfd_set_error (bfd_error_no_symbols);
return -1;
}
return (info->dynsym_count + 1) * sizeof (asymbol *);
}
static bfd_boolean
sunos_slurp_dynamic_symtab (bfd *abfd)
{
struct sunos_dynamic_info *info;
bfd_size_type amt;
if (obj_aout_dynamic_info (abfd) == NULL)
{
if (! sunos_read_dynamic_info (abfd))
return FALSE;
}
info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
if (! info->valid)
{
bfd_set_error (bfd_error_no_symbols);
return FALSE;
}
if (info->dynsym == NULL)
{
amt = (bfd_size_type) info->dynsym_count * EXTERNAL_NLIST_SIZE;
info->dynsym = bfd_alloc (abfd, amt);
if (info->dynsym == NULL && info->dynsym_count != 0)
return FALSE;
if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_stab, SEEK_SET) != 0
|| bfd_bread ((void *) info->dynsym, amt, abfd) != amt)
{
if (info->dynsym != NULL)
{
bfd_release (abfd, info->dynsym);
info->dynsym = NULL;
}
return FALSE;
}
}
if (info->dynstr == NULL)
{
amt = info->dyninfo.ld_symb_size;
info->dynstr = bfd_alloc (abfd, amt);
if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
return FALSE;
if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_symbols, SEEK_SET) != 0
|| bfd_bread ((void *) info->dynstr, amt, abfd) != amt)
{
if (info->dynstr != NULL)
{
bfd_release (abfd, info->dynstr);
info->dynstr = NULL;
}
return FALSE;
}
}
return TRUE;
}
static long
sunos_canonicalize_dynamic_symtab (bfd *abfd, asymbol **storage)
{
struct sunos_dynamic_info *info;
unsigned long i;
if (! sunos_slurp_dynamic_symtab (abfd))
return -1;
info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
#ifdef CHECK_DYNAMIC_HASH
{
bfd_size_type table_size;
bfd_byte *table;
bfd_size_type i;
if (info->dyninfo.ld_buckets > info->dynsym_count)
abort ();
table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
table = bfd_malloc (table_size);
if (table == NULL && table_size != 0)
abort ();
if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_hash, SEEK_SET) != 0
|| bfd_bread ((void *) table, table_size, abfd) != table_size)
abort ();
for (i = 0; i < info->dynsym_count; i++)
{
unsigned char *name;
unsigned long hash;
name = ((unsigned char *) info->dynstr
+ GET_WORD (abfd, info->dynsym[i].e_strx));
hash = 0;
while (*name != '\0')
hash = (hash << 1) + *name++;
hash &= 0x7fffffff;
hash %= info->dyninfo.ld_buckets;
while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
{
hash = GET_WORD (abfd,
table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
abort ();
}
}
free (table);
}
#endif
if (info->canonical_dynsym == NULL)
{
bfd_size_type size;
bfd_size_type strsize = info->dyninfo.ld_symb_size;
size = (bfd_size_type) info->dynsym_count * sizeof (aout_symbol_type);
info->canonical_dynsym = bfd_alloc (abfd, size);
if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
return -1;
if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
info->dynsym,
(bfd_size_type) info->dynsym_count,
info->dynstr, strsize, TRUE))
{
if (info->canonical_dynsym != NULL)
{
bfd_release (abfd, info->canonical_dynsym);
info->canonical_dynsym = NULL;
}
return -1;
}
}
for (i = 0; i < info->dynsym_count; i++)
*storage++ = (asymbol *) (info->canonical_dynsym + i);
*storage = NULL;
return info->dynsym_count;
}
static long
sunos_get_dynamic_reloc_upper_bound (bfd *abfd)
{
struct sunos_dynamic_info *info;
if (! sunos_read_dynamic_info (abfd))
return -1;
info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
if (! info->valid)
{
bfd_set_error (bfd_error_no_symbols);
return -1;
}
return (info->dynrel_count + 1) * sizeof (arelent *);
}
static long
sunos_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage, asymbol **syms)
{
struct sunos_dynamic_info *info;
unsigned long i;
bfd_size_type size;
if (obj_aout_dynamic_info (abfd) == NULL)
{
if (! sunos_read_dynamic_info (abfd))
return -1;
}
info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
if (! info->valid)
{
bfd_set_error (bfd_error_no_symbols);
return -1;
}
if (info->dynrel == NULL)
{
size = (bfd_size_type) info->dynrel_count * obj_reloc_entry_size (abfd);
info->dynrel = bfd_alloc (abfd, size);
if (info->dynrel == NULL && size != 0)
return -1;
if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_rel, SEEK_SET) != 0
|| bfd_bread ((void *) info->dynrel, size, abfd) != size)
{
if (info->dynrel != NULL)
{
bfd_release (abfd, info->dynrel);
info->dynrel = NULL;
}
return -1;
}
}
if (info->canonical_dynrel == NULL)
{
arelent *to;
size = (bfd_size_type) info->dynrel_count * sizeof (arelent);
info->canonical_dynrel = bfd_alloc (abfd, size);
if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
return -1;
to = info->canonical_dynrel;
if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
{
struct reloc_ext_external *p;
struct reloc_ext_external *pend;
p = (struct reloc_ext_external *) info->dynrel;
pend = p + info->dynrel_count;
for (; p < pend; p++, to++)
NAME (aout, swap_ext_reloc_in) (abfd, p, to, syms,
(bfd_size_type) info->dynsym_count);
}
else
{
struct reloc_std_external *p;
struct reloc_std_external *pend;
p = (struct reloc_std_external *) info->dynrel;
pend = p + info->dynrel_count;
for (; p < pend; p++, to++)
NAME (aout, swap_std_reloc_in) (abfd, p, to, syms,
(bfd_size_type) info->dynsym_count);
}
}
for (i = 0; i < info->dynrel_count; i++)
*storage++ = info->canonical_dynrel + i;
*storage = NULL;
return info->dynrel_count;
}
#define SPARC_PLT_ENTRY_SIZE (12)
static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
{
0x3, 0, 0, 0,
0x81, 0xc0, 0x60, 0,
0x1, 0, 0, 0
};
#define SPARC_PLT_ENTRY_WORD0 ((bfd_vma) 0x9de3bfa0)
#define SPARC_PLT_ENTRY_WORD1 ((bfd_vma) 0x40000000)
#define SPARC_PLT_ENTRY_WORD2 ((bfd_vma) 0x01000000)
#define SPARC_PLT_PIC_WORD0 ((bfd_vma) 0x03000000)
#define SPARC_PLT_PIC_WORD1 ((bfd_vma) 0x81c06000)
#define SPARC_PLT_PIC_WORD2 ((bfd_vma) 0x01000000)
#define M68K_PLT_ENTRY_SIZE (8)
static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
{
0x4e, 0xf9,
0, 0, 0, 0,
0, 0
};
#define M68K_PLT_ENTRY_WORD0 ((bfd_vma) 0x61ff)
struct sunos_link_hash_entry
{
struct aout_link_hash_entry root;
long dynindx;
long dynstr_index;
bfd_vma got_offset;
bfd_vma plt_offset;
unsigned char flags;
#define SUNOS_REF_REGULAR 01
#define SUNOS_DEF_REGULAR 02
#define SUNOS_REF_DYNAMIC 04
#define SUNOS_DEF_DYNAMIC 010
#define SUNOS_CONSTRUCTOR 020
};
struct sunos_link_hash_table
{
struct aout_link_hash_table root;
bfd *dynobj;
bfd_boolean dynamic_sections_created;
bfd_boolean dynamic_sections_needed;
bfd_boolean got_needed;
size_t dynsymcount;
size_t bucketcount;
struct bfd_link_needed_list *needed;
bfd_vma got_base;
};
static struct bfd_hash_entry *
sunos_link_hash_newfunc (struct bfd_hash_entry *entry,
struct bfd_hash_table *table,
const char *string)
{
struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
if (ret == NULL)
ret = bfd_hash_allocate (table, sizeof (* ret));
if (ret == NULL)
return NULL;
ret = ((struct sunos_link_hash_entry *)
NAME (aout, link_hash_newfunc) ((struct bfd_hash_entry *) ret,
table, string));
if (ret != NULL)
{
ret->dynindx = -1;
ret->dynstr_index = -1;
ret->got_offset = 0;
ret->plt_offset = 0;
ret->flags = 0;
}
return (struct bfd_hash_entry *) ret;
}
static struct bfd_link_hash_table *
sunos_link_hash_table_create (bfd *abfd)
{
struct sunos_link_hash_table *ret;
bfd_size_type amt = sizeof (struct sunos_link_hash_table);
ret = bfd_malloc (amt);
if (ret == NULL)
return NULL;
if (! NAME (aout, link_hash_table_init) (&ret->root, abfd,
sunos_link_hash_newfunc))
{
free (ret);
return NULL;
}
ret->dynobj = NULL;
ret->dynamic_sections_created = FALSE;
ret->dynamic_sections_needed = FALSE;
ret->got_needed = FALSE;
ret->dynsymcount = 0;
ret->bucketcount = 0;
ret->needed = NULL;
ret->got_base = 0;
return &ret->root.root;
}
#define sunos_link_hash_lookup(table, string, create, copy, follow) \
((struct sunos_link_hash_entry *) \
aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
(follow)))
#define sunos_link_hash_traverse(table, func, info) \
(aout_link_hash_traverse \
(&(table)->root, \
(bfd_boolean (*) (struct aout_link_hash_entry *, void *)) (func), \
(info)))
#define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
static bfd_boolean
sunos_create_dynamic_sections (bfd *abfd,
struct bfd_link_info *info,
bfd_boolean needed)
{
asection *s;
if (! sunos_hash_table (info)->dynamic_sections_created)
{
flagword flags;
sunos_hash_table (info)->dynobj = abfd;
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
| SEC_LINKER_CREATED);
s = bfd_make_section (abfd, ".dynamic");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".got");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".plt");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".dynrel");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".hash");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".dynsym");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
s = bfd_make_section (abfd, ".dynstr");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
sunos_hash_table (info)->dynamic_sections_created = TRUE;
}
if ((needed && ! sunos_hash_table (info)->dynamic_sections_needed)
|| info->shared)
{
bfd *dynobj;
dynobj = sunos_hash_table (info)->dynobj;
s = bfd_get_section_by_name (dynobj, ".got");
if (s->size == 0)
s->size = BYTES_IN_WORD;
sunos_hash_table (info)->dynamic_sections_needed = TRUE;
sunos_hash_table (info)->got_needed = TRUE;
}
return TRUE;
}
static bfd_boolean
sunos_add_dynamic_symbols (bfd *abfd,
struct bfd_link_info *info,
struct external_nlist **symsp,
bfd_size_type *sym_countp,
char **stringsp)
{
bfd *dynobj;
struct sunos_dynamic_info *dinfo;
unsigned long need;
if (info->hash->creator == abfd->xvec)
{
if (! sunos_create_dynamic_sections (abfd, info,
((abfd->flags & DYNAMIC) != 0
&& !info->relocatable)))
return FALSE;
}
if ((abfd->flags & DYNAMIC) == 0)
return TRUE;
dynobj = sunos_hash_table (info)->dynobj;
if (abfd != dynobj)
abfd->sections = NULL;
else
{
asection *s;
for (s = abfd->sections; s != NULL; s = s->next)
{
if ((s->flags & SEC_LINKER_CREATED) == 0)
bfd_section_list_remove (abfd, s);
}
}
if (info->relocatable)
return TRUE;
if (info->hash->creator != abfd->xvec)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
}
if (bfd_get_section_by_name (dynobj, ".need") == NULL)
{
asection *s = bfd_make_section (dynobj, ".need");
if (s == NULL
|| ! bfd_set_section_flags (dynobj, s,
(SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY))
|| ! bfd_set_section_alignment (dynobj, s, 2))
return FALSE;
}
if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
{
asection *s = bfd_make_section (dynobj, ".rules");
if (s == NULL
|| ! bfd_set_section_flags (dynobj, s,
(SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY))
|| ! bfd_set_section_alignment (dynobj, s, 2))
return FALSE;
}
if (! sunos_slurp_dynamic_symtab (abfd))
return FALSE;
dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
*symsp = dinfo->dynsym;
*sym_countp = dinfo->dynsym_count;
*stringsp = dinfo->dynstr;
need = dinfo->dyninfo.ld_need;
while (need != 0)
{
bfd_byte buf[16];
unsigned long name, flags;
unsigned short major_vno, minor_vno;
struct bfd_link_needed_list *needed, **pp;
char *namebuf, *p;
bfd_size_type alc;
bfd_byte b;
char *namecopy;
if (bfd_seek (abfd, (file_ptr) need, SEEK_SET) != 0
|| bfd_bread (buf, (bfd_size_type) 16, abfd) != 16)
return FALSE;
name = bfd_get_32 (abfd, buf);
flags = bfd_get_32 (abfd, buf + 4);
major_vno = (unsigned short) bfd_get_16 (abfd, buf + 8);
minor_vno = (unsigned short) bfd_get_16 (abfd, buf + 10);
need = bfd_get_32 (abfd, buf + 12);
alc = sizeof (struct bfd_link_needed_list);
needed = bfd_alloc (abfd, alc);
if (needed == NULL)
return FALSE;
needed->by = abfd;
alc = 30;
namebuf = bfd_malloc (alc + 1);
if (namebuf == NULL)
return FALSE;
p = namebuf;
if ((flags & 0x80000000) != 0)
{
*p++ = '-';
*p++ = 'l';
}
if (bfd_seek (abfd, (file_ptr) name, SEEK_SET) != 0)
{
free (namebuf);
return FALSE;
}
do
{
if (bfd_bread (&b, (bfd_size_type) 1, abfd) != 1)
{
free (namebuf);
return FALSE;
}
if ((bfd_size_type) (p - namebuf) >= alc)
{
char *n;
alc *= 2;
n = bfd_realloc (namebuf, alc + 1);
if (n == NULL)
{
free (namebuf);
return FALSE;
}
p = n + (p - namebuf);
namebuf = n;
}
*p++ = b;
}
while (b != '\0');
if (major_vno == 0)
*p = '\0';
else
{
char majbuf[30];
char minbuf[30];
sprintf (majbuf, ".%d", major_vno);
if (minor_vno == 0)
minbuf[0] = '\0';
else
sprintf (minbuf, ".%d", minor_vno);
if ((p - namebuf) + strlen (majbuf) + strlen (minbuf) >= alc)
{
char *n;
alc = (p - namebuf) + strlen (majbuf) + strlen (minbuf);
n = bfd_realloc (namebuf, alc + 1);
if (n == NULL)
{
free (namebuf);
return FALSE;
}
p = n + (p - namebuf);
namebuf = n;
}
strcpy (p, majbuf);
strcat (p, minbuf);
}
namecopy = bfd_alloc (abfd, (bfd_size_type) strlen (namebuf) + 1);
if (namecopy == NULL)
{
free (namebuf);
return FALSE;
}
strcpy (namecopy, namebuf);
free (namebuf);
needed->name = namecopy;
needed->next = NULL;
for (pp = &sunos_hash_table (info)->needed;
*pp != NULL;
pp = &(*pp)->next)
;
*pp = needed;
}
return TRUE;
}
static bfd_boolean
sunos_add_one_symbol (struct bfd_link_info *info,
bfd *abfd,
const char *name,
flagword flags,
asection *section,
bfd_vma value,
const char *string,
bfd_boolean copy,
bfd_boolean collect,
struct bfd_link_hash_entry **hashp)
{
struct sunos_link_hash_entry *h;
int new_flag;
if ((flags & (BSF_INDIRECT | BSF_WARNING | BSF_CONSTRUCTOR)) != 0
|| ! bfd_is_und_section (section))
h = sunos_link_hash_lookup (sunos_hash_table (info), name, TRUE, copy,
FALSE);
else
h = ((struct sunos_link_hash_entry *)
bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE));
if (h == NULL)
return FALSE;
if (hashp != NULL)
*hashp = (struct bfd_link_hash_entry *) h;
if ((abfd->flags & DYNAMIC) != 0
&& bfd_is_com_section (section))
section = obj_bsssec (abfd);
if (! bfd_is_und_section (section)
&& h->root.root.type != bfd_link_hash_new
&& h->root.root.type != bfd_link_hash_undefined
&& h->root.root.type != bfd_link_hash_defweak)
{
if ((abfd->flags & DYNAMIC) != 0)
{
section = bfd_und_section_ptr;
}
else if (h->root.root.type == bfd_link_hash_defined
&& h->root.root.u.def.section->owner != NULL
&& (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
{
h->root.root.type = bfd_link_hash_undefined;
h->root.root.u.undef.abfd = h->root.root.u.def.section->owner;
}
else if (h->root.root.type == bfd_link_hash_common
&& (h->root.root.u.c.p->section->owner->flags & DYNAMIC) != 0)
{
h->root.root.type = bfd_link_hash_undefined;
h->root.root.u.undef.abfd = h->root.root.u.c.p->section->owner;
}
}
if ((abfd->flags & DYNAMIC) != 0
&& abfd->xvec == info->hash->creator
&& (h->flags & SUNOS_CONSTRUCTOR) != 0)
section = bfd_und_section_ptr;
else if ((flags & BSF_CONSTRUCTOR) != 0
&& (abfd->flags & DYNAMIC) == 0
&& h->root.root.type == bfd_link_hash_defined
&& h->root.root.u.def.section->owner != NULL
&& (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
h->root.root.type = bfd_link_hash_new;
if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
value, string, copy, collect,
hashp))
return FALSE;
if (abfd->xvec == info->hash->creator)
{
if ((abfd->flags & DYNAMIC) == 0)
{
if (bfd_is_und_section (section))
new_flag = SUNOS_REF_REGULAR;
else
new_flag = SUNOS_DEF_REGULAR;
}
else
{
if (bfd_is_und_section (section))
new_flag = SUNOS_REF_DYNAMIC;
else
new_flag = SUNOS_DEF_DYNAMIC;
}
h->flags |= new_flag;
if (h->dynindx == -1
&& (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
{
++sunos_hash_table (info)->dynsymcount;
h->dynindx = -2;
}
if ((flags & BSF_CONSTRUCTOR) != 0
&& (abfd->flags & DYNAMIC) == 0)
h->flags |= SUNOS_CONSTRUCTOR;
}
return TRUE;
}
extern const bfd_target MY (vec);
struct bfd_link_needed_list *
bfd_sunos_get_needed_list (bfd *abfd ATTRIBUTE_UNUSED,
struct bfd_link_info *info)
{
if (info->hash->creator != &MY (vec))
return NULL;
return sunos_hash_table (info)->needed;
}
bfd_boolean
bfd_sunos_record_link_assignment (bfd *output_bfd,
struct bfd_link_info *info,
const char *name)
{
struct sunos_link_hash_entry *h;
if (output_bfd->xvec != &MY(vec))
return TRUE;
h = sunos_link_hash_lookup (sunos_hash_table (info), name,
FALSE, FALSE, FALSE);
if (h == NULL)
return TRUE;
if (! info->shared || strcmp (name, "__DYNAMIC") != 0)
{
h->flags |= SUNOS_DEF_REGULAR;
if (h->dynindx == -1)
{
++sunos_hash_table (info)->dynsymcount;
h->dynindx = -2;
}
}
return TRUE;
}
static bfd_boolean
sunos_scan_std_relocs (struct bfd_link_info *info,
bfd *abfd,
asection *sec ATTRIBUTE_UNUSED,
const struct reloc_std_external *relocs,
bfd_size_type rel_size)
{
bfd *dynobj;
asection *splt = NULL;
asection *srel = NULL;
struct sunos_link_hash_entry **sym_hashes;
const struct reloc_std_external *rel, *relend;
if (bfd_get_arch (abfd) != bfd_arch_m68k)
{
bfd_set_error (bfd_error_invalid_target);
return FALSE;
}
dynobj = NULL;
sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
relend = relocs + rel_size / RELOC_STD_SIZE;
for (rel = relocs; rel < relend; rel++)
{
int r_index;
struct sunos_link_hash_entry *h;
if (bfd_header_big_endian (abfd))
{
if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
continue;
}
else
{
if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
continue;
}
if (bfd_header_big_endian (abfd))
r_index = ((rel->r_index[0] << 16)
| (rel->r_index[1] << 8)
| rel->r_index[2]);
else
r_index = ((rel->r_index[2] << 16)
| (rel->r_index[1] << 8)
| rel->r_index[0]);
h = sym_hashes[r_index];
if (h == NULL)
continue;
if (h->root.root.type != bfd_link_hash_defined
&& h->root.root.type != bfd_link_hash_defweak
&& h->root.root.type != bfd_link_hash_undefined)
continue;
if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
|| (h->flags & SUNOS_DEF_REGULAR) != 0)
continue;
if (dynobj == NULL)
{
asection *sgot;
if (! sunos_create_dynamic_sections (abfd, info, FALSE))
return FALSE;
dynobj = sunos_hash_table (info)->dynobj;
splt = bfd_get_section_by_name (dynobj, ".plt");
srel = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && srel != NULL);
sgot = bfd_get_section_by_name (dynobj, ".got");
BFD_ASSERT (sgot != NULL);
if (sgot->size == 0)
sgot->size = BYTES_IN_WORD;
sunos_hash_table (info)->got_needed = TRUE;
}
BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
BFD_ASSERT (h->plt_offset != 0
|| ((h->root.root.type == bfd_link_hash_defined
|| h->root.root.type == bfd_link_hash_defweak)
? (h->root.root.u.def.section->owner->flags
& DYNAMIC) != 0
: (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
if (h->root.root.type == bfd_link_hash_undefined)
srel->size += RELOC_STD_SIZE;
else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
{
bfd *sub;
srel->size += RELOC_STD_SIZE;
sub = h->root.root.u.def.section->owner;
h->root.root.type = bfd_link_hash_undefined;
h->root.root.u.undef.abfd = sub;
}
else
{
if (h->plt_offset == 0)
{
if (splt->size == 0)
splt->size = M68K_PLT_ENTRY_SIZE;
h->plt_offset = splt->size;
if ((h->flags & SUNOS_DEF_REGULAR) == 0)
{
h->root.root.u.def.section = splt;
h->root.root.u.def.value = splt->size;
}
splt->size += M68K_PLT_ENTRY_SIZE;
if ((h->flags & SUNOS_DEF_REGULAR) == 0)
srel->size += RELOC_STD_SIZE;
}
}
}
return TRUE;
}
static bfd_boolean
sunos_scan_ext_relocs (struct bfd_link_info *info,
bfd *abfd,
asection *sec ATTRIBUTE_UNUSED,
const struct reloc_ext_external *relocs,
bfd_size_type rel_size)
{
bfd *dynobj;
struct sunos_link_hash_entry **sym_hashes;
const struct reloc_ext_external *rel, *relend;
asection *splt = NULL;
asection *sgot = NULL;
asection *srel = NULL;
bfd_size_type amt;
if (bfd_get_arch (abfd) != bfd_arch_sparc)
{
bfd_set_error (bfd_error_invalid_target);
return FALSE;
}
dynobj = NULL;
sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
relend = relocs + rel_size / RELOC_EXT_SIZE;
for (rel = relocs; rel < relend; rel++)
{
unsigned int r_index;
int r_extern;
int r_type;
struct sunos_link_hash_entry *h = NULL;
if (bfd_header_big_endian (abfd))
{
r_index = ((rel->r_index[0] << 16)
| (rel->r_index[1] << 8)
| rel->r_index[2]);
r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
>> RELOC_EXT_BITS_TYPE_SH_BIG);
}
else
{
r_index = ((rel->r_index[2] << 16)
| (rel->r_index[1] << 8)
| rel->r_index[0]);
r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
>> RELOC_EXT_BITS_TYPE_SH_LITTLE);
}
if (r_extern)
{
h = sym_hashes[r_index];
if (h == NULL)
{
continue;
}
}
if (r_type == RELOC_BASE10
|| r_type == RELOC_BASE13
|| r_type == RELOC_BASE22)
{
if (dynobj == NULL)
{
if (! sunos_create_dynamic_sections (abfd, info, FALSE))
return FALSE;
dynobj = sunos_hash_table (info)->dynobj;
splt = bfd_get_section_by_name (dynobj, ".plt");
sgot = bfd_get_section_by_name (dynobj, ".got");
srel = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
if (sgot->size == 0)
sgot->size = BYTES_IN_WORD;
sunos_hash_table (info)->got_needed = TRUE;
}
if (r_extern)
{
if (h->got_offset != 0)
continue;
h->got_offset = sgot->size;
}
else
{
if (r_index >= bfd_get_symcount (abfd))
continue;
if (adata (abfd).local_got_offsets == NULL)
{
amt = bfd_get_symcount (abfd);
amt *= sizeof (bfd_vma);
adata (abfd).local_got_offsets = bfd_zalloc (abfd, amt);
if (adata (abfd).local_got_offsets == NULL)
return FALSE;
}
if (adata (abfd).local_got_offsets[r_index] != 0)
continue;
adata (abfd).local_got_offsets[r_index] = sgot->size;
}
sgot->size += BYTES_IN_WORD;
if (info->shared
|| (h != NULL
&& (h->flags & SUNOS_DEF_DYNAMIC) != 0
&& (h->flags & SUNOS_DEF_REGULAR) == 0))
srel->size += RELOC_EXT_SIZE;
continue;
}
if (! r_extern)
{
if (info->shared)
{
if (dynobj == NULL)
{
if (! sunos_create_dynamic_sections (abfd, info, TRUE))
return FALSE;
dynobj = sunos_hash_table (info)->dynobj;
splt = bfd_get_section_by_name (dynobj, ".plt");
sgot = bfd_get_section_by_name (dynobj, ".got");
srel = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
}
srel->size += RELOC_EXT_SIZE;
}
continue;
}
if (h->root.root.type != bfd_link_hash_defined
&& h->root.root.type != bfd_link_hash_defweak
&& h->root.root.type != bfd_link_hash_undefined)
continue;
if (r_type != RELOC_JMP_TBL
&& ! info->shared
&& ((h->flags & SUNOS_DEF_DYNAMIC) == 0
|| (h->flags & SUNOS_DEF_REGULAR) != 0))
continue;
if (r_type == RELOC_JMP_TBL
&& ! info->shared
&& (h->flags & SUNOS_DEF_DYNAMIC) == 0
&& (h->flags & SUNOS_DEF_REGULAR) == 0)
{
continue;
}
if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
continue;
if (dynobj == NULL)
{
if (! sunos_create_dynamic_sections (abfd, info, FALSE))
return FALSE;
dynobj = sunos_hash_table (info)->dynobj;
splt = bfd_get_section_by_name (dynobj, ".plt");
sgot = bfd_get_section_by_name (dynobj, ".got");
srel = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
if (sgot->size == 0)
sgot->size = BYTES_IN_WORD;
sunos_hash_table (info)->got_needed = TRUE;
}
BFD_ASSERT (r_type == RELOC_JMP_TBL
|| info->shared
|| (h->flags & SUNOS_REF_REGULAR) != 0);
BFD_ASSERT (r_type == RELOC_JMP_TBL
|| info->shared
|| h->plt_offset != 0
|| ((h->root.root.type == bfd_link_hash_defined
|| h->root.root.type == bfd_link_hash_defweak)
? (h->root.root.u.def.section->owner->flags
& DYNAMIC) != 0
: (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
if (r_type != RELOC_JMP_TBL
&& h->root.root.type == bfd_link_hash_undefined)
srel->size += RELOC_EXT_SIZE;
else if (r_type != RELOC_JMP_TBL
&& (h->root.root.u.def.section->flags & SEC_CODE) == 0)
{
bfd *sub;
srel->size += RELOC_EXT_SIZE;
if ((h->flags & SUNOS_DEF_REGULAR) == 0)
{
sub = h->root.root.u.def.section->owner;
h->root.root.type = bfd_link_hash_undefined;
h->root.root.u.undef.abfd = sub;
}
}
else
{
if (h->plt_offset == 0)
{
if (splt->size == 0)
splt->size = SPARC_PLT_ENTRY_SIZE;
h->plt_offset = splt->size;
if ((h->flags & SUNOS_DEF_REGULAR) == 0)
{
if (h->root.root.type == bfd_link_hash_undefined)
h->root.root.type = bfd_link_hash_defined;
h->root.root.u.def.section = splt;
h->root.root.u.def.value = splt->size;
}
splt->size += SPARC_PLT_ENTRY_SIZE;
if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
srel->size += RELOC_EXT_SIZE;
}
if (info->shared && r_type != RELOC_JMP_TBL)
srel->size += RELOC_EXT_SIZE;
}
}
return TRUE;
}
static bfd_boolean
sunos_scan_relocs (struct bfd_link_info *info,
bfd *abfd,
asection *sec,
bfd_size_type rel_size)
{
void * relocs;
void * free_relocs = NULL;
if (rel_size == 0)
return TRUE;
if (! info->keep_memory)
relocs = free_relocs = bfd_malloc (rel_size);
else
{
struct aout_section_data_struct *n;
bfd_size_type amt = sizeof (struct aout_section_data_struct);
n = bfd_alloc (abfd, amt);
if (n == NULL)
relocs = NULL;
else
{
set_aout_section_data (sec, n);
relocs = bfd_malloc (rel_size);
aout_section_data (sec)->relocs = relocs;
}
}
if (relocs == NULL)
return FALSE;
if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
|| bfd_bread (relocs, rel_size, abfd) != rel_size)
goto error_return;
if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
{
if (! sunos_scan_std_relocs (info, abfd, sec,
(struct reloc_std_external *) relocs,
rel_size))
goto error_return;
}
else
{
if (! sunos_scan_ext_relocs (info, abfd, sec,
(struct reloc_ext_external *) relocs,
rel_size))
goto error_return;
}
if (free_relocs != NULL)
free (free_relocs);
return TRUE;
error_return:
if (free_relocs != NULL)
free (free_relocs);
return FALSE;
}
static bfd_boolean
sunos_scan_dynamic_symbol (struct sunos_link_hash_entry *h, void * data)
{
struct bfd_link_info *info = (struct bfd_link_info *) data;
if (h->root.root.type == bfd_link_hash_warning)
h = (struct sunos_link_hash_entry *) h->root.root.u.i.link;
if ((h->flags & SUNOS_DEF_REGULAR) == 0
&& (h->flags & SUNOS_DEF_DYNAMIC) != 0
&& strcmp (h->root.root.root.string, "__DYNAMIC") != 0)
h->root.written = TRUE;
if ((h->flags & SUNOS_DEF_REGULAR) == 0
&& (h->flags & SUNOS_DEF_DYNAMIC) != 0
&& (h->flags & SUNOS_REF_REGULAR) != 0)
{
if ((h->root.root.type == bfd_link_hash_defined
|| h->root.root.type == bfd_link_hash_defweak)
&& ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
&& h->root.root.u.def.section->output_section == NULL)
{
bfd *sub;
sub = h->root.root.u.def.section->owner;
h->root.root.type = bfd_link_hash_undefined;
h->root.root.u.undef.abfd = sub;
}
}
if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
{
asection *s;
size_t len;
bfd_byte *contents;
unsigned char *name;
unsigned long hash;
bfd *dynobj;
BFD_ASSERT (h->dynindx == -2);
dynobj = sunos_hash_table (info)->dynobj;
h->dynindx = sunos_hash_table (info)->dynsymcount;
++sunos_hash_table (info)->dynsymcount;
len = strlen (h->root.root.root.string);
s = bfd_get_section_by_name (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
contents = bfd_realloc (s->contents, s->size + len + 1);
if (contents == NULL)
return FALSE;
s->contents = contents;
h->dynstr_index = s->size;
strcpy ((char *) contents + s->size, h->root.root.root.string);
s->size += len + 1;
name = (unsigned char *) h->root.root.root.string;
hash = 0;
while (*name != '\0')
hash = (hash << 1) + *name++;
hash &= 0x7fffffff;
hash %= sunos_hash_table (info)->bucketcount;
s = bfd_get_section_by_name (dynobj, ".hash");
BFD_ASSERT (s != NULL);
if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
else
{
bfd_vma next;
next = GET_WORD (dynobj,
(s->contents
+ hash * HASH_ENTRY_SIZE
+ BYTES_IN_WORD));
PUT_WORD (dynobj, s->size / HASH_ENTRY_SIZE,
s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
PUT_WORD (dynobj, h->dynindx, s->contents + s->size);
PUT_WORD (dynobj, next, s->contents + s->size + BYTES_IN_WORD);
s->size += HASH_ENTRY_SIZE;
}
}
return TRUE;
}
bfd_boolean
bfd_sunos_size_dynamic_sections (bfd *output_bfd,
struct bfd_link_info *info,
asection **sdynptr,
asection **sneedptr,
asection **srulesptr)
{
bfd *dynobj;
bfd_size_type dynsymcount;
struct sunos_link_hash_entry *h;
asection *s;
size_t bucketcount;
bfd_size_type hashalloc;
size_t i;
bfd *sub;
*sdynptr = NULL;
*sneedptr = NULL;
*srulesptr = NULL;
if (info->relocatable)
return TRUE;
if (output_bfd->xvec != &MY(vec))
return TRUE;
for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
{
if ((sub->flags & DYNAMIC) == 0
&& sub->xvec == output_bfd->xvec)
{
if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
exec_hdr (sub)->a_trsize)
|| ! sunos_scan_relocs (info, sub, obj_datasec (sub),
exec_hdr (sub)->a_drsize))
return FALSE;
}
}
dynobj = sunos_hash_table (info)->dynobj;
dynsymcount = sunos_hash_table (info)->dynsymcount;
if (! sunos_hash_table (info)->dynamic_sections_needed
&& ! sunos_hash_table (info)->got_needed)
return TRUE;
h = sunos_link_hash_lookup (sunos_hash_table (info),
"__GLOBAL_OFFSET_TABLE_", FALSE, FALSE, FALSE);
if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
{
h->flags |= SUNOS_DEF_REGULAR;
if (h->dynindx == -1)
{
++sunos_hash_table (info)->dynsymcount;
h->dynindx = -2;
}
h->root.root.type = bfd_link_hash_defined;
h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
s = bfd_get_section_by_name (dynobj, ".got");
BFD_ASSERT (s != NULL);
if (s->size >= 0x1000)
h->root.root.u.def.value = 0x1000;
else
h->root.root.u.def.value = 0;
sunos_hash_table (info)->got_base = h->root.root.u.def.value;
}
if (sunos_hash_table (info)->dynamic_sections_needed)
{
*sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
s = *sdynptr;
BFD_ASSERT (s != NULL);
s->size = (sizeof (struct external_sun4_dynamic)
+ EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
+ sizeof (struct external_sun4_dynamic_link));
s = bfd_get_section_by_name (dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
s->size = dynsymcount * sizeof (struct external_nlist);
s->contents = bfd_alloc (output_bfd, s->size);
if (s->contents == NULL && s->size != 0)
return FALSE;
if (dynsymcount >= 4)
bucketcount = dynsymcount / 4;
else if (dynsymcount > 0)
bucketcount = dynsymcount;
else
bucketcount = 1;
s = bfd_get_section_by_name (dynobj, ".hash");
BFD_ASSERT (s != NULL);
hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
s->contents = bfd_zalloc (dynobj, hashalloc);
if (s->contents == NULL && dynsymcount > 0)
return FALSE;
for (i = 0; i < bucketcount; i++)
PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
s->size = bucketcount * HASH_ENTRY_SIZE;
sunos_hash_table (info)->bucketcount = bucketcount;
sunos_hash_table (info)->dynsymcount = 0;
sunos_link_hash_traverse (sunos_hash_table (info),
sunos_scan_dynamic_symbol,
(void *) info);
BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
s = bfd_get_section_by_name (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
if ((s->size & 7) != 0)
{
bfd_size_type add;
bfd_byte *contents;
add = 8 - (s->size & 7);
contents = bfd_realloc (s->contents, s->size + add);
if (contents == NULL)
return FALSE;
memset (contents + s->size, 0, (size_t) add);
s->contents = contents;
s->size += add;
}
}
s = bfd_get_section_by_name (dynobj, ".plt");
BFD_ASSERT (s != NULL);
if (s->size != 0)
{
s->contents = bfd_alloc (dynobj, s->size);
if (s->contents == NULL)
return FALSE;
switch (bfd_get_arch (dynobj))
{
case bfd_arch_sparc:
memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
break;
case bfd_arch_m68k:
memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
break;
default:
abort ();
}
}
s = bfd_get_section_by_name (dynobj, ".dynrel");
if (s->size != 0)
{
s->contents = bfd_alloc (dynobj, s->size);
if (s->contents == NULL)
return FALSE;
}
s->reloc_count = 0;
s = bfd_get_section_by_name (dynobj, ".got");
s->contents = bfd_alloc (dynobj, s->size);
if (s->contents == NULL)
return FALSE;
*sneedptr = bfd_get_section_by_name (dynobj, ".need");
*srulesptr = bfd_get_section_by_name (dynobj, ".rules");
return TRUE;
}
static bfd_boolean
sunos_link_dynamic_object (struct bfd_link_info *info ATTRIBUTE_UNUSED,
bfd *abfd ATTRIBUTE_UNUSED)
{
return TRUE;
}
static bfd_boolean
sunos_write_dynamic_symbol (bfd *output_bfd,
struct bfd_link_info *info,
struct aout_link_hash_entry *harg)
{
struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
int type;
bfd_vma val;
asection *s;
struct external_nlist *outsym;
if (h->plt_offset != 0)
{
bfd *dynobj;
asection *splt;
bfd_byte *p;
bfd_vma r_address;
dynobj = sunos_hash_table (info)->dynobj;
splt = bfd_get_section_by_name (dynobj, ".plt");
p = splt->contents + h->plt_offset;
s = bfd_get_section_by_name (dynobj, ".dynrel");
r_address = (splt->output_section->vma
+ splt->output_offset
+ h->plt_offset);
switch (bfd_get_arch (output_bfd))
{
case bfd_arch_sparc:
if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
{
bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
bfd_put_32 (output_bfd,
(SPARC_PLT_ENTRY_WORD1
+ (((- (h->plt_offset + 4) >> 2)
& 0x3fffffff))),
p + 4);
bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
p + 8);
}
else
{
val = (h->root.root.u.def.section->output_section->vma
+ h->root.root.u.def.section->output_offset
+ h->root.root.u.def.value);
bfd_put_32 (output_bfd,
SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
p);
bfd_put_32 (output_bfd,
SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
p + 4);
bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
}
break;
case bfd_arch_m68k:
if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
abort ();
bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
bfd_put_16 (output_bfd, (bfd_vma) s->reloc_count, p + 6);
r_address += 2;
break;
default:
abort ();
}
if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
{
BFD_ASSERT (h->dynindx >= 0);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
< s->size);
p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
{
struct reloc_std_external *srel;
srel = (struct reloc_std_external *) p;
PUT_WORD (output_bfd, r_address, srel->r_address);
if (bfd_header_big_endian (output_bfd))
{
srel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
srel->r_index[2] = (bfd_byte) (h->dynindx);
srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
| RELOC_STD_BITS_JMPTABLE_BIG);
}
else
{
srel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
srel->r_index[0] = (bfd_byte)h->dynindx;
srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
| RELOC_STD_BITS_JMPTABLE_LITTLE);
}
}
else
{
struct reloc_ext_external *erel;
erel = (struct reloc_ext_external *) p;
PUT_WORD (output_bfd, r_address, erel->r_address);
if (bfd_header_big_endian (output_bfd))
{
erel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
erel->r_index[2] = (bfd_byte)h->dynindx;
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_BIG
| (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_BIG));
}
else
{
erel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
erel->r_index[0] = (bfd_byte)h->dynindx;
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_LITTLE
| (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
}
PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
}
++s->reloc_count;
}
}
if (h->dynindx < 0)
return TRUE;
switch (h->root.root.type)
{
default:
case bfd_link_hash_new:
abort ();
return TRUE;
case bfd_link_hash_undefined:
type = N_UNDF | N_EXT;
val = 0;
break;
case bfd_link_hash_defined:
case bfd_link_hash_defweak:
{
asection *sec;
asection *output_section;
sec = h->root.root.u.def.section;
output_section = sec->output_section;
BFD_ASSERT (bfd_is_abs_section (output_section)
|| output_section->owner == output_bfd);
if (h->plt_offset != 0
&& (h->flags & SUNOS_DEF_REGULAR) == 0)
{
type = N_UNDF | N_EXT;
val = 0;
}
else
{
if (output_section == obj_textsec (output_bfd))
type = (h->root.root.type == bfd_link_hash_defined
? N_TEXT
: N_WEAKT);
else if (output_section == obj_datasec (output_bfd))
type = (h->root.root.type == bfd_link_hash_defined
? N_DATA
: N_WEAKD);
else if (output_section == obj_bsssec (output_bfd))
type = (h->root.root.type == bfd_link_hash_defined
? N_BSS
: N_WEAKB);
else
type = (h->root.root.type == bfd_link_hash_defined
? N_ABS
: N_WEAKA);
type |= N_EXT;
val = (h->root.root.u.def.value
+ output_section->vma
+ sec->output_offset);
}
}
break;
case bfd_link_hash_common:
type = N_UNDF | N_EXT;
val = h->root.root.u.c.size;
break;
case bfd_link_hash_undefweak:
type = N_WEAKU;
val = 0;
break;
case bfd_link_hash_indirect:
case bfd_link_hash_warning:
return TRUE;
}
s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
outsym = ((struct external_nlist *)
(s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
H_PUT_8 (output_bfd, type, outsym->e_type);
H_PUT_8 (output_bfd, 0, outsym->e_other);
H_PUT_16 (output_bfd, 0, outsym->e_desc);
PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
PUT_WORD (output_bfd, val, outsym->e_value);
return TRUE;
}
static bfd_boolean
sunos_check_dynamic_reloc (struct bfd_link_info *info,
bfd *input_bfd,
asection *input_section,
struct aout_link_hash_entry *harg,
void * reloc,
bfd_byte *contents ATTRIBUTE_UNUSED,
bfd_boolean *skip,
bfd_vma *relocationp)
{
struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
bfd *dynobj;
bfd_boolean baserel;
bfd_boolean jmptbl;
bfd_boolean pcrel;
asection *s;
bfd_byte *p;
long indx;
*skip = FALSE;
dynobj = sunos_hash_table (info)->dynobj;
if (h != NULL
&& h->plt_offset != 0
&& (info->shared
|| (h->flags & SUNOS_DEF_REGULAR) == 0))
{
asection *splt;
splt = bfd_get_section_by_name (dynobj, ".plt");
*relocationp = (splt->output_section->vma
+ splt->output_offset
+ h->plt_offset);
}
if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
{
struct reloc_std_external *srel;
srel = (struct reloc_std_external *) reloc;
if (bfd_header_big_endian (input_bfd))
{
baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
}
else
{
baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
}
}
else
{
struct reloc_ext_external *erel;
int r_type;
erel = (struct reloc_ext_external *) reloc;
if (bfd_header_big_endian (input_bfd))
r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
>> RELOC_EXT_BITS_TYPE_SH_BIG);
else
r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
>> RELOC_EXT_BITS_TYPE_SH_LITTLE);
baserel = (r_type == RELOC_BASE10
|| r_type == RELOC_BASE13
|| r_type == RELOC_BASE22);
jmptbl = r_type == RELOC_JMP_TBL;
pcrel = (r_type == RELOC_DISP8
|| r_type == RELOC_DISP16
|| r_type == RELOC_DISP32
|| r_type == RELOC_WDISP30
|| r_type == RELOC_WDISP22);
}
if (baserel)
{
bfd_vma *got_offsetp;
asection *sgot;
if (h != NULL)
got_offsetp = &h->got_offset;
else if (adata (input_bfd).local_got_offsets == NULL)
got_offsetp = NULL;
else
{
struct reloc_std_external *srel;
int r_index;
srel = (struct reloc_std_external *) reloc;
if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
{
if (bfd_header_big_endian (input_bfd))
r_index = ((srel->r_index[0] << 16)
| (srel->r_index[1] << 8)
| srel->r_index[2]);
else
r_index = ((srel->r_index[2] << 16)
| (srel->r_index[1] << 8)
| srel->r_index[0]);
}
else
{
struct reloc_ext_external *erel;
erel = (struct reloc_ext_external *) reloc;
if (bfd_header_big_endian (input_bfd))
r_index = ((erel->r_index[0] << 16)
| (erel->r_index[1] << 8)
| erel->r_index[2]);
else
r_index = ((erel->r_index[2] << 16)
| (erel->r_index[1] << 8)
| erel->r_index[0]);
}
got_offsetp = adata (input_bfd).local_got_offsets + r_index;
}
BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
sgot = bfd_get_section_by_name (dynobj, ".got");
if ((*got_offsetp & 1) == 0)
{
if (h == NULL
|| (! info->shared
&& ((h->flags & SUNOS_DEF_DYNAMIC) == 0
|| (h->flags & SUNOS_DEF_REGULAR) != 0)))
PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
else
PUT_WORD (dynobj, 0, sgot->contents + *got_offsetp);
if (info->shared
|| (h != NULL
&& (h->flags & SUNOS_DEF_DYNAMIC) != 0
&& (h->flags & SUNOS_DEF_REGULAR) == 0))
{
s = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
< s->size);
p = (s->contents
+ s->reloc_count * obj_reloc_entry_size (dynobj));
if (h != NULL)
indx = h->dynindx;
else
indx = 0;
if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
{
struct reloc_std_external *srel;
srel = (struct reloc_std_external *) p;
PUT_WORD (dynobj,
(*got_offsetp
+ sgot->output_section->vma
+ sgot->output_offset),
srel->r_address);
if (bfd_header_big_endian (dynobj))
{
srel->r_index[0] = (bfd_byte) (indx >> 16);
srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[2] = (bfd_byte)indx;
if (h == NULL)
srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG;
else
srel->r_type[0] =
(RELOC_STD_BITS_EXTERN_BIG
| RELOC_STD_BITS_BASEREL_BIG
| RELOC_STD_BITS_RELATIVE_BIG
| (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
}
else
{
srel->r_index[2] = (bfd_byte) (indx >> 16);
srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[0] = (bfd_byte)indx;
if (h == NULL)
srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE;
else
srel->r_type[0] =
(RELOC_STD_BITS_EXTERN_LITTLE
| RELOC_STD_BITS_BASEREL_LITTLE
| RELOC_STD_BITS_RELATIVE_LITTLE
| (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
}
}
else
{
struct reloc_ext_external *erel;
erel = (struct reloc_ext_external *) p;
PUT_WORD (dynobj,
(*got_offsetp
+ sgot->output_section->vma
+ sgot->output_offset),
erel->r_address);
if (bfd_header_big_endian (dynobj))
{
erel->r_index[0] = (bfd_byte) (indx >> 16);
erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[2] = (bfd_byte)indx;
if (h == NULL)
erel->r_type[0] =
RELOC_32 << RELOC_EXT_BITS_TYPE_SH_BIG;
else
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_BIG
| (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
}
else
{
erel->r_index[2] = (bfd_byte) (indx >> 16);
erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[0] = (bfd_byte)indx;
if (h == NULL)
erel->r_type[0] =
RELOC_32 << RELOC_EXT_BITS_TYPE_SH_LITTLE;
else
erel->r_type[0] =
(RELOC_EXT_BITS_EXTERN_LITTLE
| (RELOC_GLOB_DAT
<< RELOC_EXT_BITS_TYPE_SH_LITTLE));
}
PUT_WORD (dynobj, 0, erel->r_addend);
}
++s->reloc_count;
}
*got_offsetp |= 1;
}
*relocationp = (sgot->vma
+ (*got_offsetp &~ (bfd_vma) 1)
- sunos_hash_table (info)->got_base);
return TRUE;
}
if (! sunos_hash_table (info)->dynamic_sections_needed)
return TRUE;
if (! info->shared)
{
if (h == NULL
|| h->dynindx == -1
|| h->root.root.type != bfd_link_hash_undefined
|| (h->flags & SUNOS_DEF_REGULAR) != 0
|| (h->flags & SUNOS_DEF_DYNAMIC) == 0
|| (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
return TRUE;
}
else
{
if (h != NULL
&& (h->dynindx == -1
|| jmptbl
|| strcmp (h->root.root.root.string,
"__GLOBAL_OFFSET_TABLE_") == 0))
return TRUE;
}
s = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size);
p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
memcpy (p, reloc, obj_reloc_entry_size (dynobj));
if (h != NULL)
indx = h->dynindx;
else
indx = 0;
if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
{
struct reloc_std_external *srel;
srel = (struct reloc_std_external *) p;
PUT_WORD (dynobj,
(GET_WORD (dynobj, srel->r_address)
+ input_section->output_section->vma
+ input_section->output_offset),
srel->r_address);
if (bfd_header_big_endian (dynobj))
{
srel->r_index[0] = (bfd_byte) (indx >> 16);
srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[2] = (bfd_byte)indx;
}
else
{
srel->r_index[2] = (bfd_byte) (indx >> 16);
srel->r_index[1] = (bfd_byte) (indx >> 8);
srel->r_index[0] = (bfd_byte)indx;
}
}
else
{
struct reloc_ext_external *erel;
erel = (struct reloc_ext_external *) p;
PUT_WORD (dynobj,
(GET_WORD (dynobj, erel->r_address)
+ input_section->output_section->vma
+ input_section->output_offset),
erel->r_address);
if (bfd_header_big_endian (dynobj))
{
erel->r_index[0] = (bfd_byte) (indx >> 16);
erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[2] = (bfd_byte)indx;
}
else
{
erel->r_index[2] = (bfd_byte) (indx >> 16);
erel->r_index[1] = (bfd_byte) (indx >> 8);
erel->r_index[0] = (bfd_byte)indx;
}
if (pcrel && h != NULL)
{
PUT_WORD (dynobj,
(GET_WORD (dynobj, erel->r_addend)
- (input_section->output_section->vma
+ input_section->output_offset
- input_section->vma)),
erel->r_addend);
}
}
++s->reloc_count;
if (h != NULL)
*skip = TRUE;
return TRUE;
}
static bfd_boolean
sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info)
{
bfd *dynobj;
asection *o;
asection *s;
asection *sdyn;
if (! sunos_hash_table (info)->dynamic_sections_needed
&& ! sunos_hash_table (info)->got_needed)
return TRUE;
dynobj = sunos_hash_table (info)->dynobj;
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
BFD_ASSERT (sdyn != NULL);
s = bfd_get_section_by_name (dynobj, ".need");
if (s != NULL && s->size != 0)
{
file_ptr filepos;
bfd_byte *p;
filepos = s->output_section->filepos + s->output_offset;
p = s->contents;
while (1)
{
bfd_vma val;
PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
val = GET_WORD (dynobj, p + 12);
if (val == 0)
break;
PUT_WORD (dynobj, val + filepos, p + 12);
p += 16;
}
}
s = bfd_get_section_by_name (dynobj, ".got");
BFD_ASSERT (s != NULL);
if (info->shared || sdyn->size == 0)
PUT_WORD (dynobj, 0, s->contents);
else
PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
s->contents);
for (o = dynobj->sections; o != NULL; o = o->next)
{
if ((o->flags & SEC_HAS_CONTENTS) != 0
&& o->contents != NULL)
{
BFD_ASSERT (o->output_section != NULL
&& o->output_section->owner == abfd);
if (! bfd_set_section_contents (abfd, o->output_section,
o->contents,
(file_ptr) o->output_offset,
o->size))
return FALSE;
}
}
if (sdyn->size > 0)
{
struct external_sun4_dynamic esd;
struct external_sun4_dynamic_link esdl;
file_ptr pos;
PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
PUT_WORD (dynobj,
sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
esd.ldd);
PUT_WORD (dynobj,
(sdyn->output_section->vma
+ sdyn->output_offset
+ sizeof esd
+ EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
esd.ld);
if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
(file_ptr) sdyn->output_offset,
(bfd_size_type) sizeof esd))
return FALSE;
PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
s = bfd_get_section_by_name (dynobj, ".need");
if (s == NULL || s->size == 0)
PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
else
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_need);
s = bfd_get_section_by_name (dynobj, ".rules");
if (s == NULL || s->size == 0)
PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
else
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_rules);
s = bfd_get_section_by_name (dynobj, ".got");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
esdl.ld_got);
s = bfd_get_section_by_name (dynobj, ".plt");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
esdl.ld_plt);
PUT_WORD (dynobj, s->size, esdl.ld_plt_sz);
s = bfd_get_section_by_name (dynobj, ".dynrel");
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
== s->size);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_rel);
s = bfd_get_section_by_name (dynobj, ".hash");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_hash);
s = bfd_get_section_by_name (dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_stab);
PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
esdl.ld_buckets);
s = bfd_get_section_by_name (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_symbols);
PUT_WORD (dynobj, s->size, esdl.ld_symb_size);
PUT_WORD (dynobj,
BFD_ALIGN (obj_textsec (abfd)->size, 0x2000),
esdl.ld_text);
pos = sdyn->output_offset;
pos += sizeof esd + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE;
if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
pos, (bfd_size_type) sizeof esdl))
return FALSE;
abfd->flags |= DYNAMIC;
}
return TRUE;
}