PATCH: Don't check relocations against reloc sections
H.J. Lu
hjl.tools@gmail.com
Fri Apr 13 16:34:00 GMT 2012
On Thu, Apr 12, 2012 at 7:56 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Apr 12, 2012 at 6:45 PM, Alan Modra <amodra@gmail.com> wrote:
>> On Thu, Apr 12, 2012 at 11:37:05AM -0700, H.J. Lu wrote:
>>> @@ -10370,6 +10370,15 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
>>> for (o = abfd->sections; o != NULL; o = o->next)
>>> {
>>> struct bfd_elf_section_data *esdo = elf_section_data (o);
>>> +
>>> + if (esdo->this_hdr.sh_type == SHT_REL
>>> + || esdo->this_hdr.sh_type == SHT_RELA)
>>> + {
>>> + /* There should be no relocations against reloc sections. */
>>> + BFD_ASSERT (!(o->flags & SEC_RELOC) && o->reloc_count == 0);
>>> + continue;
>>> + }
>>> +
>>> o->reloc_count = 0;
>>>
>>> for (p = o->map_head.link_order; p != NULL; p = p->next)
>>
>> This doesn't look to be correct. Code below this point does more than
>> just count relocs. Try this instead.
>>
>> Index: bfd/elflink.c
>> ===================================================================
>> RCS file: /cvs/src/src/bfd/elflink.c,v
>> retrieving revision 1.436
>> diff -u -p -r1.436 elflink.c
>> --- bfd/elflink.c 12 Apr 2012 07:35:04 -0000 1.436
>> +++ bfd/elflink.c 13 Apr 2012 01:43:23 -0000
>> @@ -10396,7 +10396,13 @@ bfd_elf_final_link (bfd *abfd, struct bf
>> if (sec->flags & SEC_MERGE)
>> merged = TRUE;
>>
>> - if (info->relocatable || info->emitrelocations)
>> + if (esdo->this_hdr.sh_type == SHT_REL
>> + || esdo->this_hdr.sh_type == SHT_RELA)
>> + /* Some backends use reloc_count in relocation sections
>> + to count particular types of relocs. Of course,
>> + reloc sections themselves can't have relocations. */
>> + reloc_count = 0;
>> + else if (info->relocatable || info->emitrelocations)
>> reloc_count = sec->reloc_count;
>> else if (bed->elf_backend_count_relocs)
>> reloc_count = (*bed->elf_backend_count_relocs) (info, sec);
>>
>
> It works.
Here is the patch with a testcase. OK to install?
Thanks.
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ld-pr13947.patch
Type: application/octet-stream
Size: 2134 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20120413/e52c8cd0/attachment.obj>
More information about the Binutils
mailing list