PATCH: PR ld/11937: ld --build-id crash with non-ELF input
H.J. Lu
hjl.tools@gmail.com
Sat Aug 21 22:32:00 GMT 2010
On Sat, Aug 21, 2010 at 12:08 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Aug 20, 2010 at 9:28 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Aug 20, 2010 at 8:16 AM, Pedro Alves <pedro@codesourcery.com> wrote:
>>> On Friday 20 August 2010 16:00:30, Nick Clifton wrote:
>>>> Whilst working on another bug I came across a seg-fault in the
>>>> _after_open() function in elf32.em. If the target is not an ELF
>>>> binary then get_elf_backend_data will return NULL, but the code was
>>>> not checking for this. Fixed by applying the following patch.
>>>
>>> (...)
>>>
>>>> bed = get_elf_backend_data (abfd);
>>>> ! if (bed == NULL)
>>>> ! s = NULL;
>>>> ! else
>>>> ! s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
>>>> ! bed->dynamic_sec_flags
>>>> ! | SEC_READONLY);
>>>
>>> Is it valid to call get_elf_backend_data on a non-elf bfd at all?
>>>
>>> #define get_elf_backend_data(abfd) \
>>> xvec_get_elf_backend_data ((abfd)->xvec)
>>>
>>> #define bfd_mach_o_get_backend_data(abfd) \
>>> ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
>>>
>>> .#define coff_backend_info(abfd) \
>>> . ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
>>>
>>> It appears that for other flavours, it may happen to return
>>> something undefined.
>>>
>>> Shouldn't that check be something like
>>> bfd_get_flavour (abfd) != bfd_target_elf_flavour instead?
>>>
>>
>> I agree. The patch doesn't look right to me. Nick, if you can
>> provide a testcase, I will look into it.
>>
>
> I opened a bug report:
>
> http://sourceware.org/bugzilla/show_bug.cgi?id=11937
>
Here is a patch. OK to install?
--
H.J.
---
2010-08-21 H.J. Lu <hongjiu.lu@intel.com>
PR ld/11937
* emultempl/elf32.em (_after_open): Find an ELF input for
--build-id and --eh-frame-hdr.
-------------- next part --------------
2010-08-21 H.J. Lu <hongjiu.lu@intel.com>
PR ld/11937
* emultempl/elf32.em (_after_open): Find an ELF input for
--build-id and --eh-frame-hdr.
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 2decd18..bf4359d 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1065,7 +1065,11 @@ gld${EMULATION_NAME}_after_open (void)
asection *s;
bfd_size_type size;
- abfd = link_info.input_bfds;
+ /* Find an ELF input. */
+ for (abfd = link_info.input_bfds;
+ abfd != (bfd *) NULL; abfd = abfd->link_next)
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ break;
if (abfd == NULL)
{
@@ -1120,33 +1124,38 @@ gld${EMULATION_NAME}_after_open (void)
if (link_info.eh_frame_hdr
&& !link_info.traditional_format)
{
- bfd *abfd;
+ bfd *abfd, *elfbfd = NULL;
+ bfd_boolean warn_eh_frame = FALSE;
asection *s;
for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
{
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ elfbfd = abfd;
s = bfd_get_section_by_name (abfd, ".eh_frame");
- if (s && s->size > 8 && !bfd_is_abs_section (s->output_section))
- break;
+ if (s && s->size > 8 && !bfd_is_abs_section (s->output_section))
+ warn_eh_frame = TRUE;
+ if (elfbfd && warn_eh_frame)
+ break;
}
- if (abfd)
+ if (elfbfd)
{
const struct elf_backend_data *bed;
- bed = get_elf_backend_data (abfd);
- if (bed == NULL)
- s = NULL;
- else
- s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
- bed->dynamic_sec_flags
- | SEC_READONLY);
+ bed = get_elf_backend_data (elfbfd);
+ s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
+ bed->dynamic_sec_flags
+ | SEC_READONLY);
if (s != NULL
- && bfd_set_section_alignment (abfd, s, 2))
- htab->eh_info.hdr_sec = s;
- else
- einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
- " --eh-frame-hdr ignored.\n");
+ && bfd_set_section_alignment (elfbfd, s, 2))
+ {
+ htab->eh_info.hdr_sec = s;
+ warn_eh_frame = FALSE;
+ }
}
+ if (warn_eh_frame)
+ einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
+ " --eh-frame-hdr ignored.\n");
}
/* Get the list of files which appear in DT_NEEDED entries in
More information about the Binutils
mailing list