This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


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

Re: Bug in newlib/libgloss/m68k/*.ld ?


Greg Allen wrote:
> 
> I spent the last few days finding this one...
> 
> I compiled gcc and newlib, and set out to test the compiler for my
> embedded
> 68332 board.  About half the time it worked, and the other half it
> crashed
> on startup.
> 
> After much investigation (with no debugger or logic analyzer), I
> located
> the problem:
> 
> Whenever the end of the .text section was long aligned, things were
> great:
> __CTOR_LIST__ = 0x00805FD0;
> __CTOR_LIST__[0] = 0x00000001;
> __CTOR_LIST__[1] = 0x008006DE;
> __CTOR_LIST__[2] = 0x00000000;
> 
> However, if it was not long-aligned, the linker inserts zeros to make
> the
> .ctors section long-aligned, which messes up the __CTOR_LIST__, and
> causes
> __do_global_ctors() from __main() in libgcc.a to crash.
> __CTOR_LIST__ = 0x00805FD2;
> __CTOR_LIST__[0] = 0x00000001;
> __CTOR_LIST__[1] = 0x00000080;
> __CTOR_LIST__[2] = 0x06DE0000;
> __CTOR_LIST__[3] = 0x00000000;
> 
> By simply adding the line below to the linker command file (which
> aligns
> the __CTOR_LIST__), the problem is solved.  (I started with bcc.ld)
> 
> SECTIONS
> {
>   .text :
>   {
>     *(.text)
>     _etext = .;
>     . = ALIGN(4); // <----------------------- added this line
>     __CTOR_LIST__ = .;
>     LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
>     *(.ctors)
>     LONG(0)
>     __CTOR_END__ = .;
> ---------------- (much more cut out) ----------------
> 
> However, the real question is, how can I be the first to encounter
> this?!
> 
> Surely lots of people out there are using this stuff, and I'm not the
> first
> to have this problem?!
> 
> All of the linker files in newlib-1.7.1/libgloss/m68k/ (bcc.ld,
> idp.ld,
> mvme135.ld, mvme162lx.ld) have this problem.
> 
> Am I doing something else wrong to cause this problem?
> 
> Camments, suggestions, other experiences...?
> -Greg
> 

I also found the problem. I had a gdb monitor up and running, so did not
take to long to find.

I added a comment to the linker command file not to remove the align :-)

Chris