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

See the CrossGCC FAQ for lots more information.


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: Is this expected gcc behaviour?


On Mon, Aug 02, 2004 at 10:05:30PM -0700, Dan Kegel wrote:
> Yes.   Perhaps if you gave a more realistic example, we
> could help a bit...

I guess I simplified my test case too much.

This code is from RTEMS, and is used in many (most?) board support packages 
for calculating memory sizes. In the linker script, there is a statement:

  _HeapSize = DEFINED(_HeapSize) ? _HeapSize : 0x0;

Which can be overridden at final link time. Elsewhere, the code used
to calculate the size of the heap looks like:

   extern void          *_RamBase;
   extern void          *_HeapSize;
   extern void          *_WorkspaceBase;
   extern unsigned long  work_space_size;

   unsigned long  _M68k_Ramsize;

   void bsp_pretasking_hook(void)
   {
        void         *heapStart;
        unsigned long heapSize = (unsigned long)&_HeapSize;
        unsigned long ramSpace;

        heapStart =  (void *) ((unsigned long)&_WorkspaceBase +
                               work_space_size);
        ramSpace = (unsigned long) &_RamBase + 
                         (_M68k_Ramsize - (unsigned long) heapStart);

        if (heapSize == 0)
            heapSize = ramSpace;
        else if (heapSize > ramSpace)
            rtems_fatal_error_occurred (('H'<<24) | ('E'<<16) | ('A'<<8) | 'P');

        bsp_libc_init(heapStart, heapSize, 0);

   }

This is supposed to set the size of the heap to the size of  all the free memory, if 
no heap size (_HeapSize) is specified.

When I compile with -O1 (or greater), I get

        .file   "test.c"
        .text
        .align  2
        .globl  bsp_pretasking_hook
        .type   bsp_pretasking_hook, @function
    bsp_pretasking_hook:
        move.l %d3,-(%sp)
        move.l %d2,-(%sp)
        move.l #_HeapSize,%d3
        move.l work_space_size,%d2
        add.l #_WorkspaceBase,%d2
        move.l _M68k_Ramsize,%d0
        sub.l %d2,%d0
        add.l #_RamBase,%d0
        cmp.l %d3,%d0
        jbcc .L3
        move.l #1212498256,-(%sp)
        jbsr rtems_fatal_error_occurred
        addq.l #4,%sp
        .align  2
    .L3:
        clr.l -(%sp)
        move.l %d3,-(%sp)
        move.l %d2,-(%sp)
        jbsr bsp_libc_init
        lea (12,%sp),%sp
        move.l (%sp)+,%d2
        move.l (%sp)+,%d3
        rts
        .size   bsp_pretasking_hook, .-bsp_pretasking_hook
        .comm   _M68k_Ramsize,4,2
        .ident  "GCC: (GNU) 3.4.0"

You can see the test (HeapSize == 0) is missing. 

This used to work fine with older compilers, but no longer does with 3.4.0.

Attachment: pgp00000.pgp
Description: PGP signature


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