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: [RFC] Default ld -r should not combine .init_array sections


On Fri, Feb 26, 2010 at 12:30 AM, Jie Zhang <jie@codesourcery.com> wrote:
> On 02/26/2010 12:30 AM, H.J. Lu wrote:
>>
>> On Thu, Feb 25, 2010 at 8:05 AM, Jie Zhang<jie@codesourcery.com> ?wrote:
>>>
>>> We found this issue on arm-none-eabi target. The default ld -r combines
>>> .init_array.* sections. Such that priority information recorded in
>>> section
>>> name will be lost. When the object file from the output of "ld -r" is
>>> linked
>>> into the final executable, the static constructors will do initialization
>>> in
>>> wrong order.
>>>
>>> For example:
>>>
>>> $ cat a.cpp
>>> #include<stdio.h>
>>>
>>> class A
>>> {
>>> public:
>>> ?A() {
>>> ? ?printf ("A\n");
>>> ?}
>>> };
>>>
>>> A a __attribute__ ((init_priority (1000)));
>>>
>>> $ cat b.cpp
>>> #include<stdio.h>
>>>
>>> class B
>>> {
>>> public:
>>> ?B() {
>>> ? ?printf ("B\n");
>>> ?}
>>> };
>>>
>>> B b __attribute__ ((init_priority (2000)));
>>>
>>> int main ()
>>> {
>>> ?return 0;
>>> }
>>>
>>> #include<stdio.h>
>>>
>>> class C
>>> {
>>> public:
>>> ?C() {
>>> ? ?printf ("C\n");
>>> ?}
>>> };
>>>
>>> C c __attribute__ ((init_priority (3000)));
>>>
>>> $ arm-none-eabi-g++ -o m a.cpp b.cpp c.cpp
>>> $ arm-none-eabi-run m
>>> A
>>> B
>>> C
>>>
>>> But
>>>
>>> $ arm-none-eabi-g++ -c a.cpp b.cpp c.cpp
>>> $ arm-none-eabi-ld -r -o ac.o a.o c.o
>>> $ arm-none-eabi-g++ -o m ac.o b.o
>>> $ arm-none-eabi-run m
>>> B
>>> A
>>> C
>>>
>>> With the attach patch, we can get the expected result. This patch also do
>>> the same thing for .fini_array sections. Any comments?
>>>
>>>
>>
>> Please include a generic testcase.
>>
> Here is a new version with testcase and ChangeLog entry.
>

I think you can use assembly input and .d file for testcase. There
is no need for a complete new cdtest2.exp.


-- 
H.J.


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