changes for C++ constructors on psim

JP Bonn rtemsmail at jpbonn.eioMAIL.com
Wed May 5 22:08:40 UTC 2004


This is against the 4.6.1 release.  I plan on making a formal patch but
it'll be a little bit.  These changes make the cdtest program, including
iostreams, work on psim. There are also changes to cdtest that are
independent of the psim changes that allow it to compile if iostreams
are used.

I wanted someone who understand RTEMS to check that I was setting flags
in the proper files. The linker script changes are the same as some of
the other bsps.

=======================================================================

diff -N -P -r -c rtems-4.6.1/c/src/lib/libbsp/powerpc/psim/bsp_specs
rtems-4.6.1.mod/c/src/lib/libbsp/powerpc/psim/bsp_specs
*** rtems-4.6.1/c/src/lib/libbsp/powerpc/psim/bsp_specs	Fri Aug 22
11:50:48 2003
--- rtems-4.6.1.mod/c/src/lib/libbsp/powerpc/psim/bsp_specs	Tue May  4
14:14:06 2004
***************
*** 10,21 ****
  %{!qnolinkcmds: -T linkcmds%s}}}
  
  *startfile:
! %{!qrtems: %(old_startfile)} %{!nostdlib: %{qrtems:  ecrti%O%s \
  %{!qrtems_debug: start.o%s} \
  %{qrtems_debug: start_g.o%s}}}
  
  *endfile:
! %{!qrtems: %(old_endfile)} %{qrtems: ecrtn%O%s}
  
  *link:
  %{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -e _start -u __vectors}
--- 10,21 ----
  %{!qnolinkcmds: -T linkcmds%s}}}
  
  *startfile:
! %{!qrtems: %(old_startfile)} %{!nostdlib: %{qrtems:  ecrti%O%s
crtbegin%O%s \
  %{!qrtems_debug: start.o%s} \
  %{qrtems_debug: start_g.o%s}}}
  
  *endfile:
! %{!qrtems: %(old_endfile)} %{qrtems: crtend%O%s ecrtn%O%s}
  
  *link:
  %{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -e _start -u __vectors}
diff -N -P -r -c
rtems-4.6.1/c/src/lib/libbsp/powerpc/psim/startup/linkcmds
rtems-4.6.1.mod/c/src/lib/libbsp/powerpc/psim/startup/linkcmds
*** rtems-4.6.1/c/src/lib/libbsp/powerpc/psim/startup/linkcmds	Tue Dec
16 16:17:19 2003
--- rtems-4.6.1.mod/c/src/lib/libbsp/powerpc/psim/startup/linkcmds	Tue
May  4 14:14:06 2004
***************
*** 122,132 ****
    PROVIDE (_GOT2_END_ = .);
  
    PROVIDE (__CTOR_LIST__ = .);
!   .ctors	  : { *(.ctors) 	} >RAM
    PROVIDE (__CTOR_END__ = .);
  
    PROVIDE (__DTOR_LIST__ = .);
!   .dtors	  : { *(.dtors) 	} >RAM
    PROVIDE (__DTOR_END__ = .);
  
    PROVIDE (__FIXUP_START__ = .);
--- 122,157 ----
    PROVIDE (_GOT2_END_ = .);
  
    PROVIDE (__CTOR_LIST__ = .);
!   .ctors          :
!   {
!     /* gcc uses crtbegin.o to find the start of
!        the constructors, so we make sure it is
!        first.  Because this is a wildcard, it
!        doesn't matter if the user does not
!        actually link against crtbegin.o; the
!        linker won't look for a file to match a
!        wildcard.  The wildcard also means that it
!        doesn't matter which directory crtbegin.o
!        is in.  */
!     KEEP (*crtbegin.o(.ctors))
!     /* We don't want to include the .ctor section from
!        from the crtend.o file until after the sorted ctors.
!        The .ctor section from the crtend file contains the
!        end of ctors marker and it must be last */
!     KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
!     KEEP (*(SORT(.ctors.*)))
!     KEEP (*(.ctors))
!   } > RAM
    PROVIDE (__CTOR_END__ = .);
  
    PROVIDE (__DTOR_LIST__ = .);
!   .dtors          :
!   {
!     KEEP (*crtbegin.o(.dtors))
!     KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
!     KEEP (*(SORT(.dtors.*)))
!     KEEP (*(.dtors))
!   } > RAM
    PROVIDE (__DTOR_END__ = .);
  
    PROVIDE (__FIXUP_START__ = .);
***************
*** 142,147 ****
--- 167,174 ----
    .got.plt	  : { *(.got.plt) 	} >RAM
    PROVIDE (_GOT_END_ = .);
    PROVIDE (__GOT_END__ = .);
+ 
+   .jcr            : { KEEP (*(.jcr)) } > RAM
  
    /* We want the small data sections together, so single-instruction
offsets
       can access them all, and initialized data all before
uninitialized, so
diff -N -P -r -c rtems-4.6.1/c/src/tests/samples/cdtest/main.cc
rtems-4.6.1.mod/c/src/tests/samples/cdtest/main.cc
*** rtems-4.6.1/c/src/tests/samples/cdtest/main.cc	Thu Sep  4 11:46:30 2003
--- rtems-4.6.1.mod/c/src/tests/samples/cdtest/main.cc	Tue May  4
14:14:06 2004
***************
*** 29,37 ****
  #include <stdio.h>
  #include <stdlib.h>
  #ifdef RTEMS_TEST_IO_STREAM
! #include <iostream.h>
  #endif
  
  extern "C" 
  {
  #include <tmacros.h>
--- 29,47 ----
  #include <stdio.h>
  #include <stdlib.h>
  #ifdef RTEMS_TEST_IO_STREAM
! #include <iostream>
  #endif
  
+ 
+ void my_ctor (void) __attribute__ ((constructor));
+ void
+ my_ctor (void)
+ {
+ 	                printf ("hello before main()\n");
+ }
+ 
+ 
+ 
  extern "C" 
  {
  #include <tmacros.h>
***************
*** 134,141 ****
  
  
  
! AClass foo( "GLOBAL" );
! BClass foobar( "GLOBAL" );
  
  void
  cdtest(void)
--- 144,151 ----
  
  
  
! AClass fooAClass( "GLOBAL fooAClass" );
! BClass fooBClass( "GLOBAL fooBClass" );
  
  void
  cdtest(void)
***************
*** 144,150 ****
      BClass bleak;
  
  #ifdef RTEMS_TEST_IO_STREAM
!     cout << "Testing a C++ I/O stream" << endl;
  #else
      printf("IO Stream not tested\n");
  #endif
--- 154,160 ----
      BClass bleak;
  
  #ifdef RTEMS_TEST_IO_STREAM
!     std::cout << "Testing a C++ I/O stream" << std::endl;
  #else
      printf("IO Stream not tested\n");
  #endif
diff -N -P -r -c rtems-4.6.1/make/custom/psim.cfg
rtems-4.6.1.mod/make/custom/psim.cfg
*** rtems-4.6.1/make/custom/psim.cfg	Tue May 14 08:51:29 2002
--- rtems-4.6.1.mod/make/custom/psim.cfg	Tue May  4 14:25:24 2004
***************
*** 15,27 ****
  #  This contains the compiler options necessary to select the CPU model
  #  and (hopefully) optimize for it. 
  #
! CPU_CFLAGS = -mcpu=603e -D_OLD_EXCEPTIONS -Dppc603e
  #-ffunction-sections
  
  # optimize flag: typically -0, could use -O4 or -fast
  # -O4 is ok for RTEMS
  # NOTE: some level of -O may be actually required by inline assembler
  CFLAGS_OPTIMIZE_V=-O4 -fno-keep-inline-functions
  
  define make-exe
  	$(LINK.c) $(AM_CFLAGS) $(AM_LDFLAGS) -o $(basename $@).exe \
--- 15,35 ----
  #  This contains the compiler options necessary to select the CPU model
  #  and (hopefully) optimize for it. 
  #
! CPU_CFLAGS = -mcpu=603e -D_OLD_EXCEPTIONS -Dppc603e -D__USE_INIT_FINI__
  #-ffunction-sections
  
  # optimize flag: typically -0, could use -O4 or -fast
  # -O4 is ok for RTEMS
  # NOTE: some level of -O may be actually required by inline assembler
  CFLAGS_OPTIMIZE_V=-O4 -fno-keep-inline-functions
+ 
+ define make-exe
+ 	$(LINK.c) $(AM_CFLAGS) $(AM_LDFLAGS) -o $(basename $@).exe \
+ 	    $(LINK_OBJS) $(LINK_LIBS)
+ 	$(NM) -g -n $@ > $(basename $@).num
+ 	$(SIZE) $@
+ endef
+ 
  
  define make-exe
  	$(LINK.c) $(AM_CFLAGS) $(AM_LDFLAGS) -o $(basename $@).exe \


-------------------------------
The best kept secret in e-mail.
http://eioMAIL.com



More information about the users mailing list