* section.c (SEC_LINKER_MARK): Define.

* bfd-in2.h: Rebuild.
	* aoutx.h (NAME(aout,final_link)): Mark sections included in the
	link.
	(aout_link_input_bfd): Don't link unmarked sections.
	* cofflink.c (_bfd_coff_final_link): Mark sections included in the
	link.
	(_bfd_coff_link_input_bfd): Don't link unmarked sections.
	* coff-ppc.c (ppc_bfd_coff_final_link): Mark sections included in
	the link.
	* elflink.h (elf_bfd_final_link): Mark sections included in the
	link.
	(elf_link_input_bfd): Don't link unmarked sections.
	* xcofflink.c (_bfd_xcoff_bfd_final_link): Mark sections included
	in the link.
	(xcoff_link_input_bfd): Don't link unmarked sections.
This commit is contained in:
Ian Lance Taylor 1996-03-27 19:21:19 +00:00
parent cf2e4f5fde
commit 7ec49f9133
8 changed files with 149 additions and 40 deletions

View File

@ -1,5 +1,22 @@
Wed Mar 27 10:43:34 1996 Ian Lance Taylor <ian@cygnus.com>
* section.c (SEC_LINKER_MARK): Define.
* bfd-in2.h: Rebuild.
* aoutx.h (NAME(aout,final_link)): Mark sections included in the
link.
(aout_link_input_bfd): Don't link unmarked sections.
* cofflink.c (_bfd_coff_final_link): Mark sections included in the
link.
(_bfd_coff_link_input_bfd): Don't link unmarked sections.
* coff-ppc.c (ppc_bfd_coff_final_link): Mark sections included in
the link.
* elflink.h (elf_bfd_final_link): Mark sections included in the
link.
(elf_link_input_bfd): Don't link unmarked sections.
* xcofflink.c (_bfd_xcoff_bfd_final_link): Mark sections included
in the link.
(xcoff_link_input_bfd): Don't link unmarked sections.
* coffswap.h (coff_swap_scnhdr_out): Include section name in
overflow error messages.

View File

@ -3681,6 +3681,19 @@ NAME(aout,final_link) (abfd, info, callback)
for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
sub->output_has_begun = false;
/* Mark all sections which are to be included in the link. This
will normally be every section. We need to do this so that we
can identify any sections which the linker has decided to not
include. */
for (o = abfd->sections; o != NULL; o = o->next)
{
for (p = o->link_order_head; p != NULL; p = p->next)
{
if (p->type == bfd_indirect_link_order)
p->u.indirect.section->flags |= SEC_LINKER_MARK;
}
}
have_link_order_relocs = false;
for (o = abfd->sections; o != (asection *) NULL; o = o->next)
{
@ -3836,16 +3849,25 @@ aout_link_input_bfd (finfo, input_bfd)
return false;
/* Relocate and write out the sections. These functions use the
symbol map created by aout_link_write_symbols. */
if (! aout_link_input_section (finfo, input_bfd,
obj_textsec (input_bfd),
&finfo->treloff,
exec_hdr (input_bfd)->a_trsize)
|| ! aout_link_input_section (finfo, input_bfd,
obj_datasec (input_bfd),
&finfo->dreloff,
exec_hdr (input_bfd)->a_drsize))
return false;
symbol map created by aout_link_write_symbols. SEC_LINKER_MARK
will be set if these sections are to be included in the link,
which will normally be the case. */
if ((obj_textsec (input_bfd)->flags & SEC_LINKER_MARK) != 0)
{
if (! aout_link_input_section (finfo, input_bfd,
obj_textsec (input_bfd),
&finfo->treloff,
exec_hdr (input_bfd)->a_trsize))
return false;
}
if ((obj_datasec (input_bfd)->flags & SEC_LINKER_MARK) != 0)
{
if (! aout_link_input_section (finfo, input_bfd,
obj_datasec (input_bfd),
&finfo->dreloff,
exec_hdr (input_bfd)->a_drsize))
return false;
}
/* If we are not keeping memory, we don't need the symbols any
longer. We still need them if we are keeping memory, because the
@ -3972,6 +3994,11 @@ aout_link_write_symbols (finfo, input_bfd)
external symbol. */
h = *sym_hash;
/* Use the name from the hash table, in case the symbol was
wrapped. */
if (h != NULL)
name = h->root.root.string;
/* If this is an indirect or warning symbol, then change
hresolve to the base symbol. We also change *sym_hash so
that the relocation routines relocate against the real
@ -4862,16 +4889,19 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
{
const char *name;
name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (h != NULL)
name = h->root.root.string;
else
name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (! ((*finfo->info->callbacks->undefined_symbol)
(finfo->info, name, input_bfd, input_section, r_addr)))
return false;
}
r = MY_final_link_relocate (howto,
input_bfd, input_section,
contents, r_addr, relocation,
(bfd_vma) 0);
input_bfd, input_section,
contents, r_addr, relocation,
(bfd_vma) 0);
}
if (r != bfd_reloc_ok)
@ -5246,16 +5276,19 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
{
const char *name;
name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (h != NULL)
name = h->root.root.string;
else
name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
if (! ((*finfo->info->callbacks->undefined_symbol)
(finfo->info, name, input_bfd, input_section, r_addr)))
return false;
}
r = MY_final_link_relocate (howto_table_ext + r_type,
input_bfd, input_section,
contents, r_addr, relocation,
r_addend);
input_bfd, input_section,
contents, r_addr, relocation,
r_addend);
if (r != bfd_reloc_ok)
{
switch (r)
@ -5330,8 +5363,9 @@ aout_link_reloc_link_order (finfo, o, p)
BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
r_extern = 1;
h = aout_link_hash_lookup (aout_hash_table (finfo->info),
pr->u.name, false, false, true);
h = ((struct aout_link_hash_entry *)
bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
pr->u.name, false, false, true));
if (h != (struct aout_link_hash_entry *) NULL
&& h->indx >= 0)
r_index = h->indx;

View File

@ -333,6 +333,10 @@ typedef struct _symbol_info
short stab_desc; /* Stab desc. */
CONST char *stab_name; /* String for stab type. */
} symbol_info;
/* Get the name of a stabs type code. */
extern const char *bfd_get_stab_name PARAMS ((int));
/* Hash table routines. There is no way to free up a hash table. */
@ -613,7 +617,9 @@ extern boolean bfd_sunos_size_dynamic_sections
/* Linux shared library support routines for the linker. */
extern boolean bfd_linux_size_dynamic_sections
extern boolean bfd_i386linux_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
extern boolean bfd_m68klinux_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
/* mmap hacks */
@ -885,6 +891,10 @@ typedef struct sec
table. */
#define SEC_SORT_ENTRIES 0x80000
/* A mark flag used by some of the linker backends. This
should not be set by application code. */
#define SEC_LINKER_MARK 0x100000
/* End of section flags. */
/* The virtual memory address of the section - where it will be

View File

@ -2745,6 +2745,12 @@ ppc_bfd_coff_final_link (abfd, info)
sec = p->u.indirect.section;
/* Mark all sections which are to be included in the
link. This will normally be every section. We need
to do this so that we can identify any sections which
the linker has decided to not include. */
sec->flags |= SEC_LINKER_MARK;
if (info->strip == strip_none
|| info->strip == strip_some)
o->lineno_count += sec->lineno_count;
@ -2920,7 +2926,7 @@ ppc_bfd_coff_final_link (abfd, info)
if (! sub->output_has_begun)
#endif
{
if (! coff_link_input_bfd (&finfo, sub))
if (! _bfd_coff_link_input_bfd (&finfo, sub))
goto error_return;
sub->output_has_begun = true;
}
@ -2928,7 +2934,7 @@ ppc_bfd_coff_final_link (abfd, info)
else if (p->type == bfd_section_reloc_link_order
|| p->type == bfd_symbol_reloc_link_order)
{
if (! coff_reloc_link_order (abfd, &finfo, o, p))
if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p))
goto error_return;
}
else
@ -2945,14 +2951,14 @@ ppc_bfd_coff_final_link (abfd, info)
bfd* last_one = ppc_get_last();
if (last_one)
{
if (! coff_link_input_bfd (&finfo, last_one))
if (! _bfd_coff_link_input_bfd (&finfo, last_one))
goto error_return;
}
last_one->output_has_begun = true;
}
#endif
/* Free up the buffers used by coff_link_input_bfd. */
/* Free up the buffers used by _bfd_coff_link_input_bfd. */
coff_debug_merge_hash_table_free (&finfo.debug_merge);
debug_merge_allocated = false;
@ -3012,12 +3018,12 @@ ppc_bfd_coff_final_link (abfd, info)
/* Write out the global symbols. */
finfo.failed = false;
coff_link_hash_traverse (coff_hash_table (info), coff_write_global_sym,
coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym,
(PTR) &finfo);
if (finfo.failed)
goto error_return;
/* The outsyms buffer is used by coff_write_global_sym. */
/* The outsyms buffer is used by _bfd_coff_write_global_sym. */
if (finfo.outsyms != NULL)
{
free (finfo.outsyms);

View File

@ -485,13 +485,18 @@ _bfd_coff_final_link (abfd, info)
o->lineno_count = 0;
for (p = o->link_order_head; p != NULL; p = p->next)
{
if (p->type == bfd_indirect_link_order)
{
asection *sec;
sec = p->u.indirect.section;
/* Mark all sections which are to be included in the
link. This will normally be every section. We need
to do this so that we can identify any sections which
the linker has decided to not include. */
sec->flags |= SEC_LINKER_MARK;
if (info->strip == strip_none
|| info->strip == strip_some)
o->lineno_count += sec->lineno_count;
@ -1079,11 +1084,11 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
output_index = syment_base;
outsym = finfo->outsyms;
if (coff_data(output_bfd)->pe)
{
if (!process_embedded_commands (output_bfd, finfo->info, input_bfd))
return false;
}
if (coff_data (output_bfd)->pe)
{
if (! process_embedded_commands (output_bfd, finfo->info, input_bfd))
return false;
}
while (esym < esym_end)
{
@ -1196,9 +1201,9 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
/* Ignore fake names invented by compiler; treat them all as
the same name. */
if (*name == '~' || *name == '.'
if (*name == '~' || *name == '.' || *name == '$'
|| (*name == bfd_get_symbol_leading_char (input_bfd)
&& (name[1] == '~' || name[1] == '.')))
&& (name[1] == '~' || name[1] == '.' || name[1] == '$')))
name = "";
mh = coff_debug_merge_hash_lookup (&finfo->debug_merge, name,
@ -1551,7 +1556,9 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
the index of the next symbol we are going
to include. I don't know if this is
entirely right. */
while (finfo->sym_indices[indx] < 0
while ((finfo->sym_indices[indx] < 0
|| ((bfd_size_type) finfo->sym_indices[indx]
< syment_base))
&& indx < obj_raw_syment_count (input_bfd))
++indx;
if (indx >= obj_raw_syment_count (input_bfd))
@ -1743,6 +1750,12 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
{
bfd_byte *contents;
if ((o->flags & SEC_LINKER_MARK) == 0)
{
/* This section was omitted from the link. */
continue;
}
if ((o->flags & SEC_HAS_CONTENTS) == 0)
{
if ((o->flags & SEC_RELOC) != 0
@ -2126,9 +2139,10 @@ _bfd_coff_reloc_link_order (output_bfd, finfo, output_section, link_order)
{
struct coff_link_hash_entry *h;
h = coff_link_hash_lookup (coff_hash_table (finfo->info),
link_order->u.reloc.p->u.name,
false, false, true);
h = ((struct coff_link_hash_entry *)
bfd_wrapped_link_hash_lookup (output_bfd, finfo->info,
link_order->u.reloc.p->u.name,
false, false, true));
if (h != NULL)
{
if (h->indx >= 0)

View File

@ -1798,6 +1798,12 @@ elf_bfd_final_link (abfd, info)
sec = p->u.indirect.section;
/* Mark all sections which are to be included in the
link. This will normally be every section. We need
to do this so that we can identify any sections which
the linker has decided to not include. */
sec->flags |= SEC_LINKER_MARK;
if (info->relocateable)
o->reloc_count += sec->reloc_count;
@ -2805,6 +2811,12 @@ elf_link_input_bfd (finfo, input_bfd)
/* Relocate the contents of each section. */
for (o = input_bfd->sections; o != NULL; o = o->next)
{
if ((o->flags & SEC_LINKER_MARK) == 0)
{
/* This section was omitted from the link. */
continue;
}
if ((o->flags & SEC_HAS_CONTENTS) == 0)
continue;

View File

@ -1,5 +1,5 @@
/* Object file "section" support for the BFD library.
Copyright (C) 1990, 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
@ -269,6 +269,10 @@ CODE_FRAGMENT
. table. *}
.#define SEC_SORT_ENTRIES 0x80000
.
. {* A mark flag used by some of the linker backends. This
. should not be set by application code. *}
.#define SEC_LINKER_MARK 0x100000
.
. {* End of section flags. *}
.
. {* The virtual memory address of the section - where it will be

View File

@ -3217,6 +3217,12 @@ _bfd_xcoff_bfd_final_link (abfd, info)
sec = p->u.indirect.section;
/* Mark all sections which are to be included in the
link. This will normally be every section. We need
to do this so that we can identify any sections which
the linker has decided to not include. */
sec->flags |= SEC_LINKER_MARK;
if (info->strip == strip_none
|| info->strip == strip_some)
o->lineno_count += sec->lineno_count;
@ -4571,6 +4577,12 @@ xcoff_link_input_bfd (finfo, input_bfd)
{
bfd_byte *contents;
if ((o->flags & SEC_LINKER_MARK) == 0)
{
/* This section was omitted from the link. */
continue;
}
if ((o->flags & SEC_HAS_CONTENTS) == 0
|| o->_raw_size == 0
|| (o->flags & SEC_IN_MEMORY) != 0)