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

Greg Allen gallen@arlut.utexas.edu
Tue Jun 24 09:48:00 GMT 1997

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)

  .text :
    _etext = .;
    . = ALIGN(4); // <----------------------- added this line
    __CTOR_LIST__ = .;
    LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
    __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...?

| Gregory E. Allen <gallen@arlut.utexas.edu> |
|       Applied Research Laboratories        |
|     The University of Texas at Austin      |

More information about the crossgcc mailing list