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: PR ld/12730: regression] crash when allocating in a static constructor


On Fri, May 6, 2011 at 6:23 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 5, 2011 at 7:12 AM, Alan Modra <amodra@gmail.com> wrote:
>> On Thu, May 05, 2011 at 06:26:15AM -0700, H.J. Lu wrote:
>>> On Thu, May 5, 2011 at 1:27 AM, Alan Modra <amodra@gmail.com> wrote:
>>> > On Wed, May 04, 2011 at 10:18:32PM -0700, H.J. Lu wrote:
>>> >> When we put .ctors into .init_array, we have to reverse copy .ctors secton.
>>> >> Otherwise, constructor function may not work with C++ run-time library
>>> >> correctly. ?OK for trunk?
>>> >
>>> > What about .dtors? ?You have the same problem there. ?I suspect, but
>>>
>>> You are right. ?Here is the updated patch to handle .dtors sections
>>> with the updated testcase. ?OK for trunk?
>>
>> No.
>>
>>> > haven't verified, that .ctors.* and .dtors.* also need reversing. ?If
>>> > that is true then it would be better to do your reversing trick for
>>> > anything going to the .init_array output section that isn't named
>>> > .init_array* and similarly for .fini_array.
>>
>> Are you sure there is no need to reverse .ctors.* and .dtors.*?
>>
>> The reason I recommended testing the output section is that limits
>> section reversal to that particular output section. ?I will not
>> approve a patch that ignores this recommendation. ?You also should
>> remove reverse_copy_ctors. ?That's plain wrong. ?Consider people
>> linking using a custom (old) script that does not put .ctors into
>> .init_array.
>>
>>> > You also need to reverse any dynamic relocations applying to the
>>> > sections you are reversing.
>>>
>>> It isn't a problem since we apply relocations on the input sections
>>> first and copy relocated input sections to output where I reverse
>>> copy .ctors/.dtors sections if needed.
>>
>> Try compiling your testcase as a PIE or shared lib on a target that
>> uses RELA. ?I haven't tried it, but I think the dynamic RELATIVE
>> relocs you'll get in .ctors will undo your section reversing.
>>
>
> I will fix it.
>

How about this patch?

Thanks.



-- 
H.J.
---
bfd/

2011-05-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12730
	* elf-bfd.h (_bfd_elf_section_reloc_offset): New.

	* elf.c (_bfd_elf_section_reloc_offset): New.

	* elf64-x86-64.c (elf_x86_64_relocate_section): Call
	_bfd_elf_section_reloc_offset instead of
	_bfd_elf_section_offset.
	* elfxx-ia64.c (elfNN_ia64_install_dyn_reloc): Likewise.

	* elflink.c (elf_link_input_bfd): Reverse copy .ctors/.dtors
	sections if needed.  Call _bfd_elf_section_reloc_offset instead
	of _bfd_elf_section_offset.

	* section.c (SEC_ELF_REVERSE_COPY): New.
	* bfd-in2.h: Regenerated.

ld/testsuite/

2011-05-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12730
	* ld-elf/elf.exp (array_tests): Add pr12730".
	(array_tests_pie): New.
	(array_tests_static): Add -static for ""static init array mixed".
	Add "static pr12730".  Run array_tests_pie for Linux.

	* ld-elf/init-mixed.c (ctor65535): Renamed to ...
	(ctor65535a): This.
	(ctor65535b): New.
	(ctors65535): Remove ctor65535.  Add ctor65535b and ctor65535a.
	(dtor65535): Renamed to ...
	(dtor65535a): This.
	(dtor65535b): New.
	(dtors65535): Remove dtor65535.  Add dtor65535b and dtor65535a.

	* ld-elf/pr12730.cc: New.
	* ld-elf/pr12730.out: Likewise.

Attachment: binutils-pr12730-3.patch
Description: Text document


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