/* BFD backend for SunOS binaries.
Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012
+ Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
#define TARGETNAME "a.out-sunos-big"
the tokens. */
#define MY(OP) CONCAT2 (sunos_big_,OP)
+#include "sysdep.h"
#include "bfd.h"
#include "bfdlink.h"
#include "libaout.h"
ret = bfd_malloc (amt);
if (ret == NULL)
return NULL;
- if (! NAME (aout, link_hash_table_init) (&ret->root, abfd,
- sunos_link_hash_newfunc))
+ if (!NAME (aout, link_hash_table_init) (&ret->root, abfd,
+ sunos_link_hash_newfunc,
+ sizeof (struct sunos_link_hash_entry)))
{
free (ret);
return NULL;
/* The .dynamic section holds the basic dynamic information: the
sun4_dynamic structure, the dynamic debugger information, and
the sun4_dynamic_link structure. */
- s = bfd_make_section (abfd, ".dynamic");
+ s = bfd_make_section_anyway_with_flags (abfd, ".dynamic", flags);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .got section holds the global offset table. The address
is put in the ld_got field. */
- s = bfd_make_section (abfd, ".got");
+ s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .plt section holds the procedure linkage table. The
address is put in the ld_plt field. */
- s = bfd_make_section (abfd, ".plt");
+ s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags | SEC_CODE);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .dynrel section holds the dynamic relocs. The address is
put in the ld_rel field. */
- s = bfd_make_section (abfd, ".dynrel");
+ s = bfd_make_section_anyway_with_flags (abfd, ".dynrel",
+ flags | SEC_READONLY);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .hash section holds the dynamic hash table. The address
is put in the ld_hash field. */
- s = bfd_make_section (abfd, ".hash");
+ s = bfd_make_section_anyway_with_flags (abfd, ".hash",
+ flags | SEC_READONLY);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .dynsym section holds the dynamic symbols. The address
is put in the ld_stab field. */
- s = bfd_make_section (abfd, ".dynsym");
+ s = bfd_make_section_anyway_with_flags (abfd, ".dynsym",
+ flags | SEC_READONLY);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
/* The .dynstr section holds the dynamic symbol string table.
The address is put in the ld_symbols field. */
- s = bfd_make_section (abfd, ".dynstr");
+ s = bfd_make_section_anyway_with_flags (abfd, ".dynstr",
+ flags | SEC_READONLY);
if (s == NULL
- || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return FALSE;
dynobj = sunos_hash_table (info)->dynobj;
- s = bfd_get_section_by_name (dynobj, ".got");
+ s = bfd_get_linker_section (dynobj, ".got");
if (s->size == 0)
s->size = BYTES_IN_WORD;
bfd *dynobj;
struct sunos_dynamic_info *dinfo;
unsigned long need;
- asection **ps;
/* Make sure we have all the required sections. */
- if (info->hash->creator == abfd->xvec)
+ if (info->output_bfd->xvec == abfd->xvec)
{
if (! sunos_create_dynamic_sections (abfd, info,
((abfd->flags & DYNAMIC) != 0
want, because that one still implies that the section takes up
space in the output file. If this is the first object we have
seen, we must preserve the dynamic sections we just created. */
- for (ps = &abfd->sections; *ps != NULL; )
+ if (abfd != dynobj)
+ abfd->sections = NULL;
+ else
{
- if (abfd != dynobj || ((*ps)->flags & SEC_LINKER_CREATED) == 0)
- bfd_section_list_remove (abfd, ps);
- else
- ps = &(*ps)->next;
+ asection *s;
+
+ for (s = abfd->sections; s != NULL; s = s->next)
+ {
+ if ((s->flags & SEC_LINKER_CREATED) == 0)
+ bfd_section_list_remove (abfd, s);
+ }
}
/* The native linker seems to just ignore dynamic objects when -r is
/* There's no hope of using a dynamic object which does not exactly
match the format of the output file. */
- if (info->hash->creator != abfd->xvec)
+ if (info->output_bfd->xvec != abfd->xvec)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
/* The .need section holds the list of names of shared objets
which must be included at runtime. The address of this
section is put in the ld_need field. */
- asection *s = bfd_make_section (dynobj, ".need");
+ flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY | SEC_READONLY);
+ asection *s = bfd_make_section_with_flags (dynobj, ".need", flags);
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;
}
/* The .rules section holds the path to search for shared
objects. The address of this section is put in the ld_rules
field. */
- asection *s = bfd_make_section (dynobj, ".rules");
+ flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY | SEC_READONLY);
+ asection *s = bfd_make_section_with_flags (dynobj, ".rules", flags);
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 ((abfd->flags & DYNAMIC) != 0
- && abfd->xvec == info->hash->creator
+ && abfd->xvec == info->output_bfd->xvec
&& (h->flags & SUNOS_CONSTRUCTOR) != 0)
/* The existing symbol is a constructor symbol, and this symbol
is from a dynamic object. A constructor symbol is actually a
hashp))
return FALSE;
- if (abfd->xvec == info->hash->creator)
+ if (abfd->xvec == info->output_bfd->xvec)
{
/* Set a flag in the hash table entry indicating the type of
reference or definition we just found. Keep a count of the
bfd_sunos_get_needed_list (bfd *abfd ATTRIBUTE_UNUSED,
struct bfd_link_info *info)
{
- if (info->hash->creator != &MY (vec))
+ if (info->output_bfd->xvec != &MY (vec))
return NULL;
return sunos_hash_table (info)->needed;
}
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");
+ splt = bfd_get_linker_section (dynobj, ".plt");
+ srel = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && srel != NULL);
- sgot = bfd_get_section_by_name (dynobj, ".got");
+ sgot = bfd_get_linker_section (dynobj, ".got");
BFD_ASSERT (sgot != NULL);
if (sgot->size == 0)
sgot->size = BYTES_IN_WORD;
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");
+ splt = bfd_get_linker_section (dynobj, ".plt");
+ sgot = bfd_get_linker_section (dynobj, ".got");
+ srel = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
/* Make sure we have an initial entry in the .got table. */
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");
+ splt = bfd_get_linker_section (dynobj, ".plt");
+ sgot = bfd_get_linker_section (dynobj, ".got");
+ srel = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != 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");
+ splt = bfd_get_linker_section (dynobj, ".plt");
+ sgot = bfd_get_linker_section (dynobj, ".got");
+ srel = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
/* Make sure we have an initial entry in the .got table. */
{
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;
-
/* Set the written flag for symbols we do not want to write out as
part of the regular symbol table. This is all symbols which are
not defined in a regular object file. For some reason symbols
regular symbols includes the debugging symbols, which have
long names and are often duplicated in several object files.
There are no debugging symbols in the dynamic symbols. */
- s = bfd_get_section_by_name (dynobj, ".dynstr");
+ s = bfd_get_linker_section (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
contents = bfd_realloc (s->contents, s->size + len + 1);
if (contents == NULL)
hash &= 0x7fffffff;
hash %= sunos_hash_table (info)->bucketcount;
- s = bfd_get_section_by_name (dynobj, ".hash");
+ s = bfd_get_linker_section (dynobj, ".hash");
BFD_ASSERT (s != NULL);
if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
++sunos_hash_table (info)->dynsymcount;
h->dynindx = -2;
}
+ s = bfd_get_linker_section (dynobj, ".got");
+ BFD_ASSERT (s != NULL);
h->root.root.type = bfd_link_hash_defined;
- h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
+ h->root.root.u.def.section = s;
/* If the .got section is more than 0x1000 bytes, we set
__GLOBAL_OFFSET_TABLE_ to be 0x1000 bytes into the section,
so that 13 bit relocations have a greater chance of working. */
- s = bfd_get_section_by_name (dynobj, ".got");
- BFD_ASSERT (s != NULL);
if (s->size >= 0x1000)
h->root.root.u.def.value = 0x1000;
else
up the dynamic linking information. */
if (sunos_hash_table (info)->dynamic_sections_needed)
{
- *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
+ *sdynptr = bfd_get_linker_section (dynobj, ".dynamic");
/* The .dynamic section is always the same size. */
s = *sdynptr;
symbols. We build the dynamic symbol string table (.dynstr)
in a traversal of the symbol table using
sunos_scan_dynamic_symbol. */
- s = bfd_get_section_by_name (dynobj, ".dynsym");
+ s = bfd_get_linker_section (dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
s->size = dynsymcount * sizeof (struct external_nlist);
s->contents = bfd_alloc (output_bfd, s->size);
bucketcount = dynsymcount;
else
bucketcount = 1;
- s = bfd_get_section_by_name (dynobj, ".hash");
+ s = bfd_get_linker_section (dynobj, ".hash");
BFD_ASSERT (s != NULL);
hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
s->contents = bfd_zalloc (dynobj, hashalloc);
/* The SunOS native linker seems to align the total size of the
symbol strings to a multiple of 8. I don't know if this is
important, but it can't hurt much. */
- s = bfd_get_section_by_name (dynobj, ".dynstr");
+ s = bfd_get_linker_section (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
if ((s->size & 7) != 0)
{
/* Now that we have worked out the sizes of the procedure linkage
table and the dynamic relocs, allocate storage for them. */
- s = bfd_get_section_by_name (dynobj, ".plt");
+ s = bfd_get_linker_section (dynobj, ".plt");
BFD_ASSERT (s != NULL);
if (s->size != 0)
{
}
}
- s = bfd_get_section_by_name (dynobj, ".dynrel");
+ s = bfd_get_linker_section (dynobj, ".dynrel");
if (s->size != 0)
{
s->contents = bfd_alloc (dynobj, s->size);
s->reloc_count = 0;
/* Make space for the global offset table. */
- s = bfd_get_section_by_name (dynobj, ".got");
+ s = bfd_get_linker_section (dynobj, ".got");
s->contents = bfd_alloc (dynobj, s->size);
if (s->contents == NULL)
return FALSE;
bfd_vma r_address;
dynobj = sunos_hash_table (info)->dynobj;
- splt = bfd_get_section_by_name (dynobj, ".plt");
+ splt = bfd_get_linker_section (dynobj, ".plt");
p = splt->contents + h->plt_offset;
- s = bfd_get_section_by_name (dynobj, ".dynrel");
+ s = bfd_get_linker_section (dynobj, ".dynrel");
r_address = (splt->output_section->vma
+ splt->output_offset
return TRUE;
}
- s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
+ s = bfd_get_linker_section (sunos_hash_table (info)->dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
outsym = ((struct external_nlist *)
(s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
asection *splt;
/* Redirect the relocation to the PLT entry. */
- splt = bfd_get_section_by_name (dynobj, ".plt");
+ splt = bfd_get_linker_section (dynobj, ".plt");
*relocationp = (splt->output_section->vma
+ splt->output_offset
+ h->plt_offset);
BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
- sgot = bfd_get_section_by_name (dynobj, ".got");
+ sgot = bfd_get_linker_section (dynobj, ".got");
/* We set the least significant bit to indicate whether we have
already initialized the GOT entry. */
/* We need to create a GLOB_DAT or 32 reloc to tell the
dynamic linker to fill in this entry in the table. */
- s = bfd_get_section_by_name (dynobj, ".dynrel");
+ s = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
< s->size);
/* It looks like this is a reloc we are supposed to copy. */
- s = bfd_get_section_by_name (dynobj, ".dynrel");
+ s = bfd_get_linker_section (dynobj, ".dynrel");
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size);
dynobj = sunos_hash_table (info)->dynobj;
- sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+ sdyn = bfd_get_linker_section (dynobj, ".dynamic");
BFD_ASSERT (sdyn != NULL);
/* Finish up the .need section. The linker emulation code filled it
/* The first entry in the .got section is the address of the
dynamic information, unless this is a shared library. */
- s = bfd_get_section_by_name (dynobj, ".got");
+ s = bfd_get_linker_section (dynobj, ".got");
BFD_ASSERT (s != NULL);
if (info->shared || sdyn->size == 0)
PUT_WORD (dynobj, 0, s->contents);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_rules);
- s = bfd_get_section_by_name (dynobj, ".got");
+ s = bfd_get_linker_section (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");
+ s = bfd_get_linker_section (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");
+ s = bfd_get_linker_section (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");
+ s = bfd_get_linker_section (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");
+ s = bfd_get_linker_section (dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_stab);
PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
esdl.ld_buckets);
- s = bfd_get_section_by_name (dynobj, ".dynstr");
+ s = bfd_get_linker_section (dynobj, ".dynstr");
BFD_ASSERT (s != NULL);
PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
esdl.ld_symbols);