This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: RFC: Remove empty output sections
On Fri, Mar 18, 2005 at 05:43:00PM +1030, Alan Modra wrote:
> your bfd_alloc's happened to return zeroed memory. I'm seeing this:
>
> 10: 00011a38 0 SECTION LOCAL DEFAULT 19
> 11: 00011a3c 0 SECTION LOCAL DEFAULT 20
> 12: 00000034 143 FUNC GLOBAL DEFAULT UND
>
> Please fix.
I decided to fix this myself, because it was breaking my builds.
* elf-bfd.h (_bfd_elf_link_renumber_dynsyms): Delete.
* elflink.c (_bfd_elf_link_renumber_dynsyms): Make static, add
section_sym_count param, and return number of section symbols.
(bfd_elf_size_dynamic_sections): Clear section symbol area of
.dynsym contents. Don't bother calling swap_symbol_out on the
first all-zero dynsym.
(elf_mark_used_section): Formatting. Avoid twiddling flags in
special sections like bfd_abs_section.
(bfd_elf_gc_sections): Spelling fix.
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.175
diff -u -p -r1.175 elf-bfd.h
--- bfd/elf-bfd.h 3 Mar 2005 20:52:31 -0000 1.175
+++ bfd/elf-bfd.h 18 Mar 2005 12:22:50 -0000
@@ -1592,8 +1592,6 @@ extern bfd_boolean _bfd_elf_create_dynam
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_elf_create_got_section
(bfd *, struct bfd_link_info *);
-extern unsigned long _bfd_elf_link_renumber_dynsyms
- (bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_elfcore_make_pseudosection
(bfd *, char *, size_t, ufile_ptr);
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.137
diff -u -p -r1.137 elflink.c
--- bfd/elflink.c 16 Mar 2005 21:52:40 -0000 1.137
+++ bfd/elflink.c 18 Mar 2005 12:22:59 -0000
@@ -707,8 +707,10 @@ _bfd_elf_link_omit_section_dynsym (bfd *
allocated local dynamic syms, followed by the rest of the global
symbols. */
-unsigned long
-_bfd_elf_link_renumber_dynsyms (bfd *output_bfd, struct bfd_link_info *info)
+static unsigned long
+_bfd_elf_link_renumber_dynsyms (bfd *output_bfd,
+ struct bfd_link_info *info,
+ unsigned long *section_sym_count)
{
unsigned long dynsymcount = 0;
@@ -722,6 +724,7 @@ _bfd_elf_link_renumber_dynsyms (bfd *out
&& !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
elf_section_data (p)->dynindx = ++dynsymcount;
}
+ *section_sym_count = dynsymcount;
elf_link_hash_traverse (elf_hash_table (info),
elf_link_renumber_local_hash_table_dynsyms,
@@ -5273,6 +5272,7 @@ bfd_elf_size_dynamic_sections (bfd *outp
if (elf_hash_table (info)->dynamic_sections_created)
{
bfd_size_type dynsymcount;
+ unsigned long section_sym_count;
asection *s;
size_t bucketcount = 0;
size_t hash_entry_size;
@@ -5639,7 +5639,8 @@ bfd_elf_size_dynamic_sections (bfd *outp
Next come all of the back-end allocated local dynamic syms,
followed by the rest of the global symbols. */
- dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info);
+ dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info,
+ §ion_sym_count);
/* Work out the size of the symbol version section. */
s = bfd_get_section_by_name (dynobj, ".gnu.version");
@@ -5651,7 +5652,8 @@ bfd_elf_size_dynamic_sections (bfd *outp
_bfd_strip_section_from_output (info, s);
/* The DYNSYMCOUNT might have changed if we were going to
output a dynamic symbol table entry for S. */
- dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info);
+ dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info,
+ §ion_sym_count);
}
else
{
@@ -5673,22 +5675,17 @@ bfd_elf_size_dynamic_sections (bfd *outp
s = bfd_get_section_by_name (dynobj, ".dynsym");
BFD_ASSERT (s != NULL);
s->size = dynsymcount * bed->s->sizeof_sym;
- s->contents = bfd_alloc (output_bfd, s->size);
- if (s->contents == NULL && s->size != 0)
- return FALSE;
if (dynsymcount != 0)
{
- Elf_Internal_Sym isym;
+ s->contents = bfd_alloc (output_bfd, s->size);
+ if (s->contents == NULL)
+ return FALSE;
- /* The first entry in .dynsym is a dummy symbol. */
- isym.st_value = 0;
- isym.st_size = 0;
- isym.st_name = 0;
- isym.st_info = 0;
- isym.st_other = 0;
- isym.st_shndx = 0;
- bed->s->swap_symbol_out (output_bfd, &isym, s->contents, 0);
+ /* The first entry in .dynsym is a dummy symbol.
+ Clear all the section syms, in case we don't output them all. */
+ ++section_sym_count;
+ memset (s->contents, 0, section_sym_count * bed->s->sizeof_sym);
}
/* Compute the size of the hashing table. As a side effect this
@@ -9002,17 +8999,17 @@ elf_gc_mark_dynamic_ref_symbol (struct e
static bfd_boolean
elf_mark_used_section (struct elf_link_hash_entry *h,
- void *global ATTRIBUTE_UNUSED)
+ void *data ATTRIBUTE_UNUSED)
{
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
- if ((h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak))
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
{
- asection *s = h->root.u.def.section->output_section;
- if (s)
- s->flags |= SEC_KEEP;
+ asection *s = h->root.u.def.section;
+ if (s != NULL && s->output_section != NULL && s->output_section != s)
+ s->output_section->flags |= SEC_KEEP;
}
return TRUE;
@@ -9032,7 +9029,7 @@ bfd_elf_gc_sections (bfd *abfd, struct b
if (!info->gc_sections)
{
/* If we are called when info->gc_sections is 0, we will mark
- all sections containing global symbols for non-relocable
+ all sections containing global symbols for non-relocatable
link. */
if (!info->relocatable)
elf_link_hash_traverse (elf_hash_table (info),
--
Alan Modra
IBM OzLabs - Linux Technology Centre