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: .eh_frame optimization question


Alan Modra wrote:
On Mon, Dec 25, 2006 at 10:59:43PM +0800, Jie Zhang wrote:
I'm looking at a bug of bfin port ld. With ELF FD-PIC ABI, bfin ld
will generate a relocation of type R_BFIN_FUNCDESC against symbol
__gxx_personality_v0 in .eh_frame section when compiling C++ program.
The number of such relocations are counted in size_dynamic_sections ()
and the size of the corresponding section are calculated at that time.
__gxx_personality_v0 is used in the CIE entry of the .eh_frame.
However, it's possible that .eh_frame optimization discards all FDE
entries which use the CIE entry, so the CIE entry can be eliminated,
too. Thus when bfinfdpic_relocate_section () is going to generating
the relocation for each section, it will find some relocations are
lost.

So my question is: Is it possible to add a backend hook, which can be
used by port, like bfin, to tell ld not optimize away CIE entry even
there is no FDE use it? Or is there a better way to fix it?

Other ports handle this situation by emitting an R_*_NONE reloc, typically reloc number 0. Can you do the same?

_bfd_elf_section_offset will return -1 or -2 to indicate that a
dynamic reloc is not needed.

Thanks for your reply. Actually, bfin port handles this situation as other ports. But some specific .eh_frame sections are not handled in this way. So I spent some time to find out why. The cause is that these specific .eh_frame sections are empty after optimization and are removed by setting SEC_EXCLUDE. Thus ld doesn't get a chance to change the dynamic relocations of the removed .eh_frame entries to R_*_NONE type. This patch fixes it. Any comment?


Jie
	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't remove
	empty .eh_frame section.

Index: elf-eh-frame.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-eh-frame.c,v
retrieving revision 1.53
diff -u -p -r1.53 elf-eh-frame.c
--- elf-eh-frame.c	21 Nov 2006 11:25:16 -0000	1.53
+++ elf-eh-frame.c	3 Jan 2007 07:25:57 -0000
@@ -927,8 +927,15 @@ _bfd_elf_discard_section_eh_frame
   /* Resize the sec as needed.  */
   sec->rawsize = sec->size;
   sec->size = offset;
-  if (sec->size == 0)
-    sec->flags |= SEC_EXCLUDE;
+
+  /* Previously, there was the following code to remove empty .eh_frame section.
+     
+     if (sec->size == 0)
+       sec->flags |= SEC_EXCLUDE;
+
+     But we cannot remove empty .eh_frame section. Otherwise, the dynamic
+     relocations of the .eh_frame section would have no chance to be changed
+     to R_*_NONE relocation.  */
 
   free (ehbuf);
   if (ecies)

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