PATCH: PR ld/13909: PR ld/12570 causes eh_frame_hdr section to be sometimes too large

H.J. Lu hjl.tools@gmail.com
Wed May 23 12:19:00 GMT 2012


On Wed, May 23, 2012 at 4:59 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, May 22, 2012 at 9:38 PM, Alan Modra <amodra@gmail.com> wrote:
>> On Tue, May 22, 2012 at 09:16:22AM -0700, H.J. Lu wrote:
>>>       * elf-eh-frame.c (_bfd_elf_maybe_strip_eh_frame_hdr): Ignore
>>>       .eh_frame section created by linker.
>>
>> We do need this here.
>>
>>        * elf-eh-frame.c (_bfd_elf_maybe_strip_eh_frame_hdr): Handle
>>        BFDs with multiple .eh_frame sections.
>>
>> Index: bfd/elf-eh-frame.c
>> ===================================================================
>> RCS file: /cvs/src/src/bfd/elf-eh-frame.c,v
>> retrieving revision 1.88
>> diff -u -p -r1.88 elf-eh-frame.c
>> --- bfd/elf-eh-frame.c  24 Apr 2012 05:12:30 -0000      1.88
>> +++ bfd/elf-eh-frame.c  23 May 2012 04:08:28 -0000
>> @@ -1278,7 +1278,11 @@ _bfd_elf_maybe_strip_eh_frame_hdr (struc
>>        /* Count only sections which have at least a single CIE or FDE.
>>           There cannot be any CIE or FDE <= 8 bytes.  */
>>        o = bfd_get_section_by_name (abfd, ".eh_frame");
>> -       if (o && o->size > 8 && !bfd_is_abs_section (o->output_section))
>> +       while (o != NULL
>> +              && (o->size <= 8
>> +                  || bfd_is_abs_section (o->output_section)))
>> +         o = bfd_get_next_section_by_name (o);
>> +       if (o != NULL)
>>          break;
>>       }
>>
>
> Shouldn't we ignore linker created .eh_frame section?
> Current trunk gave me:
>
> [hjl@gnu-6 pr13909]$ cat dummy.S
> [hjl@gnu-6 pr13909]$ ./ld -m elf_i386 -shared --eh-frame-hdr -o z.so
> dummy.o -shared -lc
> [hjl@gnu-6 pr13909]$ readelf -S z.so
> There are 10 section headers, starting at offset 0x1fc:
>
> Section Headers:
>  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
>  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
>  [ 1] .hash             HASH            000000b4 0000b4 000024 04   A  2   0  4
>  [ 2] .dynsym           DYNSYM          000000d8 0000d8 000040 10   A  3   1  4
>  [ 3] .dynstr           STRTAB          00000118 000118 000023 00   A  0   0  1
>  [ 4] .eh_frame_hdr     PROGBITS        0000013c 00013c 00000c 00   A  0   0  4
>  [ 5] .eh_frame         PROGBITS        00000148 000148 000000 00   A  0   0  4
>  [ 6] .dynamic          DYNAMIC         00001148 000148 000060 08  WA  3   0  4
>  [ 7] .shstrtab         STRTAB          00000000 0001a8 000052 00      0   0  1
>  [ 8] .symtab           SYMTAB          00000000 00038c 0000c0 10      9   9  4
>  [ 9] .strtab           STRTAB          00000000 00044c 000038 00      0   0  1
> Key to Flags:
>  W (write), A (alloc), X (execute), M (merge), S (strings)
>  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
>  O (extra OS processing required) o (OS specific), p (processor specific)
> [hjl@gnu-6 pr13909]$
>

This works for me.

-- 
H.J.
---
diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
index 685540c..32714bb 100644
--- a/bfd/elf-eh-frame.c
+++ b/bfd/elf-eh-frame.c
@@ -1280,6 +1280,7 @@ _bfd_elf_maybe_strip_eh_frame_hdr (struct
bfd_link_info *info)
 	o = bfd_get_section_by_name (abfd, ".eh_frame");
 	while (o != NULL
 	       && (o->size <= 8
+		   || (o->flags & SEC_LINKER_CREATED) != 0
 		   || bfd_is_abs_section (o->output_section)))
 	  o = bfd_get_next_section_by_name (o);
 	if (o != NULL)



More information about the Binutils mailing list