http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28896

--- Comment #25 from Larry Baker <baker at usgs dot gov> 2012-09-10 21:52:34 
UTC ---
Created attachment 28167
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28167
Patches for Sourcery GCC-4.6-2011.09-23 for ColdFire uClinux

These are the patches I am testing.  They are for the Mentor Graphics Sourcery
CodeBench Lite Edition C/C++ compilers for ColdFire uClinux.  The generated
code seems to be fine.

Unfortunately, my test system is not.  And, my assumption that __stack_start
was a good choice for detecting stack overflow does not seem to be working out.
 For my test uClinux executable, stack-overflow.c:

#include <stdio.h>

void overflow( int i ) {

/* Allocate automatic array j[256] so stack limit checking works. */

   int j[256];

/* Stack limit checking tests only whether the stack is large enough for  */
/* the initial stack allocation: saved registers and automatic variables. */
/* Stack limit checking does not test for stack overflow in the body of a */
/* function.  That is what happens when j[] is not present.  When j[] is  */
/* too large, the program will abnormally terminate on its own (illegal   */
/* instruction trap?).  j[256] works.                                      */

   i++;
   printf( "i = %i\n", i );
   overflow( i );

}

int main() {

   overflow( 0 );

   return 0;

}

the stack is allocated 4K (0x1000).  When I hacked the .s file to print out the
stack pointer and __stack start, it shows that there is more than 4K between
the value in the stack pointer and __stack_start:

%sp = 0x405f3ee4
__stack_start = 0x405f08b4

That is not what I was expecting.

Here are the instructions for creating the patched GCC I am using:

$ wget --no-check-certificate
https://sourcery.mentor.com/GNUToolchain/package9493/public/m68k-uclinux/freescale-coldfire-2011.09-23-m68k-uclinux-i686-pc-linux-gnu.tar.bz2
$ tar -xjf freescale-coldfire-2011.09-23-m68k-uclinux-i686-pc-linux-gnu.tar.bz2

$ wget --no-check-certificate
https://sourcery.mentor.com/GNUToolchain/package9493/public/m68k-uclinux/freescale-coldfire-2011.09-23-m68k-uclinux.src.tar.bz2
$ tar -xjf freescale-coldfire-2011.09-23-m68k-uclinux.src.tar.bz2 -O
freescale-coldfire-2011.09-23-m68k-uclinux/gcc-2011.09-23.tar.bz2 | tar -xjf -

$ cd gcc-4.6-2011.09
$ patch -b -p 1 <../gcc-4.6-2011.09-23.patch
$ cd ..

$ ( cd cross-gcc-4.6-2011.09 ; \
  PATH=${PWD}/../freescale-coldfire-2011.09/bin:${PATH/.:/} \
  CC_FOR_BUILD=gcc \
  CC=gcc \
  CXX=g++ \
  AR=ar \
  RANLIB=ranlib \
  AS_FOR_TARGET=m68k-uclinux-as \
  LD_FOR_TARGET=m68k-uclinux-ld \
  AR_FOR_TARGET=m68k-uclinux-ar \
  RANLIB_FOR_TARGET=m68k-uclinux-ranlib \
  NM_FOR_TARGET=m68k-uclinux-nm \
  OBJDUMP_FOR_TARGET=m68k-uclinux-objdump \
  STRIP_FOR_TARGET=m68k-uclinux-strip \
  ${PWD}/../gcc-4.6-2011.09/configure \
     --disable-decimal-float \
     --disable-fixed-point \
     --disable-libffi \
     --disable-libgomp \
     --disable-libmudflap \
     --disable-libquadmath \
     --disable-libssp \
     --disable-libstdcxx-pch \
     --disable-nls \
     --disable-shared \
     --enable-languages=c,c++ \
     --enable-lto \
     --enable-poison-system-directories \
     --enable-threads \
     --prefix=${PWD}/../freescale-coldfire-2011.09 \
     --program-prefix=m68k-uclinux- \
     --target=m68k-uclinux \
     --with-arch=cf \
     --with-gnu-as \
     --with-gnu-ld \
    
--with-build-time-tools=${PWD}/../freescale-coldfire-2011.09/m68k-uclinux/bin \
     --with-host-libstdcxx='-static-libgcc -static-libstdc++ -lm' \
     --with-sysroot=${PWD}/../freescale-coldfire-2011.09/m68k-uclinux/libc )

$ ( cd cross-gcc-4.6-2011.09 ; \
  PATH=${PWD}/../freescale-coldfire-2011.09/bin:${PATH/.:/} \
  make -j4 )

$ ( cd cross-gcc-4.6-2011.09 ; \
  PATH=${PWD}/../freescale-coldfire-2011.09/bin:${PATH/.:/} \
  make install )

$ toolchains/freescale-coldfire-2011.09-patched/bin/m68k-uclinux-gcc -mcpu=5208
-fomit-frame-pointer -fno-common -fno-builtin -fno-dwarf2-cfi-asm -msep-data
-fstack-limit-symbol=__stack_start -o check-stack-overflow stack-overflow.c

Larry Baker

Reply via email to