This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix --gc-sections for MIPS.


Alan Modra wrote:
On Sat, Jul 30, 2005 at 10:43:48PM -0700, David Daney wrote:

* elflink.c (elf_gc_sweep): Set dynsymcount to correct value.


OK.


Well I committed it.


But have now found that it was not sufficient. For C++ programs with exception handling I was still getting the same assertion failures because the dynsymcount was not correct. This new patch seems to fix the assertion failure problem on mipsel-linux.

There is too much logic in _bfd_elf_link_renumber_dynsyms that would have to be kept in sync with elf_gc_sweep_symbol in order to calculate a consistent dynsymcount there.

The new patch just calls _bfd_elf_link_renumber_dynsyms to calculate the value instead of trying to emulate its actions.

Although the link now succeeds with no errors, I am having problems at runtime with undefined symbols. As far as I can tell they are caused by functions being discarded that are referenced by exception handling tables that are retained. It appears that there is code to handle this that does "
/* Keep .gcc_except_table.* if the associated .text.* is
marked. This isn't very nice, but the proper solution,
splitting .eh_frame up and using comdat doesn't pan out
easily due to needing special relocs to handle the
difference of two symbols in separate sections.
Don't keep code sections referenced by .eh_frame. */
"


However I have not been able to generate objects that have .gcc_except_table.* sections. They all seem to have a single .gcc_except_table section that cannot be GCed.

This is using both gcc-3.4.4 and 4.1 from CVS today (both mipsel-linux and i686-pc-linux-gnu). I am compiling like this:

g++ -ffunction-sections -fdata-sections -c l.cc

When I use objdump -h on the resulting l.o I get many .text.* sections (one for each function), but only a single .gcc_except_table.

Q: Is anybody successfully using -ffunction-sections -fdata-sections with --gc-sections and C++ programs?

Q: What compiler do you use?

In any event I think this patch is necessary.


As before, tested on i686-pc-linux-gnu hosted mipsel-linux cross with make -k check. No regressions.


2005-08-00 David Daney <ddaney@avtrex.com>

	* elflink.c (elf_gc_sweep):  Add parameter output_bfd and call
	_bfd_elf_link_renumber_dynsyms to count dynsyms.
	(bfd_elf_gc_sections):  Pass new arameter output_bfd to elf_gc_sweep.

OK to commit?

David Daney.
? bfd/doc/bfd.info
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.185
diff -c -p -r1.185 elflink.c
*** bfd/elflink.c	31 Jul 2005 06:14:15 -0000	1.185
--- bfd/elflink.c	2 Aug 2005 23:25:51 -0000
*************** typedef bfd_boolean (*gc_sweep_hook_fn)
*** 8879,8885 ****
    (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
  
  static bfd_boolean
! elf_gc_sweep (struct bfd_link_info *info, gc_sweep_hook_fn gc_sweep_hook)
  {
    bfd *sub;
  
--- 8879,8887 ----
    (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
  
  static bfd_boolean
! elf_gc_sweep (bfd *output_bfd,
!               struct bfd_link_info *info,
!               gc_sweep_hook_fn gc_sweep_hook)
  {
    bfd *sub;
  
*************** elf_gc_sweep (struct bfd_link_info *info
*** 8940,8955 ****
       static symbol table as well?  */
    {
      int i = 0;
! 
      elf_link_hash_traverse (elf_hash_table (info), elf_gc_sweep_symbol, &i);
  
!     /* There is an unused NULL entry at the head of the table which
!        we must account for in our count.  Unless there weren't any
!        symbols, which means we'll have no table at all.  */
!     if (i != 0)
!       ++i;
! 
!     elf_hash_table (info)->dynsymcount = i;
    }
  
    return TRUE;
--- 8942,8955 ----
       static symbol table as well?  */
    {
      int i = 0;
!     unsigned long j;
!     
      elf_link_hash_traverse (elf_hash_table (info), elf_gc_sweep_symbol, &i);
  
!     /* elf_gc_sweep_symbol does not have the necessary logic to correctly
!        number and count the dynsyms.  We use the proper tool to do this. */
!     _bfd_elf_link_renumber_dynsyms (output_bfd, info, &j);
!    
    }
  
    return TRUE;
*************** bfd_elf_gc_sections (bfd *abfd, struct b
*** 9188,9194 ****
      }
  
    /* ... and mark SEC_EXCLUDE for those that go.  */
!   if (!elf_gc_sweep (info, get_elf_backend_data (abfd)->gc_sweep_hook))
      return FALSE;
  
    return TRUE;
--- 9188,9194 ----
      }
  
    /* ... and mark SEC_EXCLUDE for those that go.  */
!   if (!elf_gc_sweep (abfd, info, get_elf_backend_data (abfd)->gc_sweep_hook))
      return FALSE;
  
    return TRUE;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]