Exceptions in ARM

Mike none at none.com
Wed Jan 8 15:46:02 PST 2014


On Wednesday, 8 January 2014 at 19:13:36 UTC, Timo Sintonen wrote:
> On Wednesday, 8 January 2014 at 15:52:25 UTC, Johannes Pfau 
> wrote:
>
>>
>> Stupid question, but are C++ exceptions working for you? I 
>> think we
>> don't change anything inthe compiler related to exception 
>> handling, so
>> if C++ worked and D didn't it could only be a problem with the 
>> runtime
>> code?
>
> I have never used c++ in this platform and I do not know what 
> it would require. Some commercial toolsets use gcc as backend 
> but I do not know if they have c++.

I use C++ exceptions on an STM32F4 (ARM Cortex-M4F) with the GNU 
Tools for ARM Embedded Processors 
(https://launchpad.net/gcc-arm-embedded).  To get it to work, 
however, I had to make changes to my linker script.  Here's the 
linker script I'm currently using:

/*******************************************************
Memory Spaces Definitions
*********************************************************/
MEMORY
{
   CCRAM    (rxw) : ORIGIN = 0x10000000, LENGTH =  64k
   RAM      (rxw) : ORIGIN = 0x20000000, LENGTH = 128k
   FLASH    (rx)  : ORIGIN = 0x08000000, LENGTH = 1024k
}

/******************************************************
higher address of the user mode stack
*********************************************************/
_estack = ORIGIN(CCRAM) + LENGTH(CCRAM);

/********************************************************
  Section Definitions
**********************************************************/
SECTIONS
{
	.ccm (NOLOAD) :
	{
	. = ALIGN(4);
         *(.ccm)
	. = ALIGN(4);
	} >CCRAM

     .isr_vector :                       /* for Cortex devices, 
the beginning of the startup code is stored in the .isr_vector 
section, which goes to FLASH */
     {
	. = ALIGN(4);
         KEEP(*(.isr_vector))            /* Startup code */
	. = ALIGN(4);
     } >FLASH


     .text :                             /* the program code is 
stored in the .text section, which goes to Flash */
     {
	    . = ALIGN(4);
         *(.text)                        /* remaining code */
         *(.text.*)                      /* remaining code */
         *(.rodata)                      /* read-only data 
(constants) */
         *(.rodata*)
         *(.glue_7)
         *(.glue_7t)

		*(.eh_frame)                    /* C++ Exception Handling */
		
		. = ALIGN(4);                   /* now make sure we keep the 
C++ constructors */
		KEEP (*(.init))
		. = ALIGN(4);
		KEEP (*(.fini))

		. = ALIGN(4);
		__preinit_array_start = .;
		KEEP (*(.preinit_array))
		__preinit_array_end = .;

		. = ALIGN(4);
		__init_array_start = .;
		KEEP (*(SORT(.init_array.*)))
		KEEP (*(.init_array))
		__init_array_end = .;

		. = ALIGN(4);
		__fini_array_start = .;
		KEEP (*(.fini_array))
		KEEP (*(SORT(.fini_array.*)))
		__fini_array_end = .;

		. = ALIGN(0x4);
		KEEP (*crtbegin.o(.ctors))
		KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
		KEEP (*(SORT(.ctors.*)))
		KEEP (*crtend.o(.ctors))

		. = ALIGN(0x4);
		KEEP (*crtbegin.o(.dtors))
		KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
		KEEP (*(SORT(.dtors.*)))
		KEEP (*crtend.o(.dtors))

	    . = ALIGN(4);
         _etext = .;
     } >FLASH
	
     .ARM.extab :
     {
         *(.ARM.extab* .gnu.linkonce.armextab.*)
     } >FLASH

	
     .ARM :
     {
         __exidx_start = .;
         *(.ARM.exidx*)
         __exidx_end = .;
     } >FLASH

	
     _sidata = .;                       /* This is used by the 
startup in order to initialize the .data secion */


	/******************************************************
	 This is the initialized data section.  It is one task of the
	 startup to copy the initial values from FLASH to RAM.
	******************************************************/
     .data  : AT ( _sidata )
     {
	    . = ALIGN(4);
         _sdata = . ;                                        /* 
This is used by the startup in order to initialize the .data 
secion */
         _data = . ;

         *(.data)
         *(.data.*)
         *(.RAMtext)

	    . = ALIGN(4);
	
		_edata = . ;                                        /* This is 
used by the startup in order to initialize the .data secion */
     } >RAM

     _eidata = _sidata + (_edata - _sdata);                  
/*calculate end address of idata*/

     _lastdataromaddress = ORIGIN(FLASH) + LENGTH(FLASH);    
/*check that idata remains in FLASH region*/
     ___toobig___ = ( _eidata > _lastdataromaddress) ? 1 : 0 ;
     ___toobigmsg___ = ( ___toobig___ ) ? "!!!!!!!!! FLASH IS FULL 
!!!!!!!!!" : 0 ;


	/*****************************************************
	 This is the uninitialized data section
	**********************************************/
     .bss :
     {
	    . = ALIGN(4);
         _sbss = .;          /* This is used by the startup in 
order to initialize the .bss secion */
         _bss = .;

         *(.bss)
         *(.bss*)
         *(COMMON)

	    . = ALIGN(4);
	
    	    _ebss = . ;         /* This is used by the startup in 
order to initialize the .bss secion */
     } >RAM

     PROVIDE ( end = _ebss );
     PROVIDE ( _end = _ebss );


/************************************************************
  Discard debug info
******************************************************/
     /DISCARD/ :
     {
         libc.a ( * )
         libm.a ( * )
         libgcc.a ( * )
		libstdc++.a ( * )
		libsupc++.a ( * )
     }

     .ARM.attributes 0 : { *(.ARM.attributes) }
}



More information about the D.gnu mailing list