RFA: RL78: Add an assertion to detect link time data overflow.

Nicholas Clifton nickc@redhat.com
Fri May 15 14:14:00 GMT 2015


Hi DJ,

> The smallest MSP430 only has 128 bytes of ram, far less than 0x100.
>
> Is there any way we can parameterize that 0x100, instead of
> hard-coding it?

Yes.  Although it turns out to be a little bit more complicated than I 
had originally thought.  The patch below however will allow the user to 
add --defsym __stack_size=<expression> to set a specific stack limit.

OK to apply ?

Cheers
   Nick

diff --git a/libgloss/rl78/rl78-sim.ld b/libgloss/rl78/rl78-sim.ld
index 26d62ac..49442d1 100644
--- a/libgloss/rl78/rl78-sim.ld
+++ b/libgloss/rl78/rl78-sim.ld
@@ -122,10 +122,26 @@ SECTIONS
    } > RAM
    PROVIDE (__bsssize = SIZEOF(.bss));

+  /* The __stack_size value of 0x100 is just a guess, but since it is
+     PROVIDEd the user can override it on the command line.  It has to be
+     set here, rather than inside the .stack section, as symbols defined
+     inside sections are only evaluated during the final phase of the link,
+     long after the ASSERT is checked.  An ASSERT referencing a 
PROVIDED but
+     not yet evaluated symbol will automatically fail.
+
+     FIXME: It would be nice if this value could be automatically set via
+     gcc's -fstack-usage command line option somehow.  */
+  PROVIDE (__stack_size = 0x100);
+
    .stack (ORIGIN (STACK)) :
    {
      PROVIDE (__stack = .);
      *(.stack)
+
+    /* Linker section checking ignores empty sections like
+       this one so we have to have our own test here.  */
+    ASSERT ((__stack > (_end + __stack_size)),
+            "Error: Too much data - no room left for the stack");
    }

    .saddr : {



More information about the Newlib mailing list