]> sourceware.org Git - newlib-cygwin.git/commitdiff
Add a check that the data area does not overrun the stack.
authorNick Clifton <nickc@redhat.com>
Mon, 18 May 2015 13:14:28 +0000 (14:14 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 18 May 2015 13:14:28 +0000 (14:14 +0100)
* msp430/msp430-sim.ld (.stack): Add an assertion to make sure
that the data area does not overrun the stack.  PROVIDE a new
symbol __stack_size to allow the user to set the limit.
* msp430/msp430xl-sim.ld (.stack): Likewise.
* rl78/rl78-sim.ld (.stack): Likewise.
* rl78/rl78.ld (.stack): Likewise.
* rx/rx-sim.ld (.stack): Likewise.
* rx/rx.ld (.stack): Likewise.

libgloss/ChangeLog
libgloss/msp430/msp430-sim.ld
libgloss/msp430/msp430xl-sim.ld
libgloss/rl78/rl78-sim.ld
libgloss/rl78/rl78.ld
libgloss/rx/rx-sim.ld
libgloss/rx/rx.ld

index 5c96c23e8f3f7cc99e9179e096f4472190f328c6..9988189bea60a5992014e047d5ff430b7f9fe21b 100644 (file)
@@ -1,3 +1,14 @@
+2015-05-18  Nick Clifton  <nickc@redhat.com>
+
+       * msp430/msp430-sim.ld (.stack): Add an assertion to make sure
+       that the data area does not overrun the stack.  PROVIDE a new
+       symbol __stack_size to allow the user to set the limit.
+       * msp430/msp430xl-sim.ld (.stack): Likewise.
+       * rl78/rl78-sim.ld (.stack): Likewise.
+       * rl78/rl78.ld (.stack): Likewise.
+       * rx/rx-sim.ld (.stack): Likewise.
+       * rx/rx.ld (.stack): Likewise.
+
 2015-05-05  Nick Clifton  <nickc@redhat.com>
 
        * msp430/msp430.ld: Delete.
index 6147cbe72ecbb6f4b9eb064773375f7fc25e26df..39fb67f7aeeb12419e6c7b7241cadeba36760340 100644 (file)
@@ -175,10 +175,26 @@ SECTIONS
   _end = .;
   PROVIDE (end = .);
 
+  /* 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 (RAM) + LENGTH(RAM)) :
   {
     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");
   }
 
   /* Make sure that .upper sections are not used without -mlarge support.  */
index 1dca58afbc2d62b8e36430ea69b7434d645692a5..d59cdbf48503731dc2e25521f6c1c896cc71aaaf 100644 (file)
@@ -61,7 +61,7 @@ SECTIONS
 
        The same reasoning applies to the absence of definitions for the
        .either.text, .either.data and .either.bss sections as well.  */
-       
+
     . = ALIGN(2);
     *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
     *(.rodata1)
@@ -318,6 +318,17 @@ SECTIONS
     LONG(0);
   } > HIFRAM
 
+  /* 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);
+
   /* Note: We place the stack in HIFRAM because then there is less
      chance that it will collide with allocated data in the RAM region.
      In scripts targeted at real MCUs however it may be better to place
@@ -329,6 +340,11 @@ SECTIONS
   .stack (ORIGIN (HIFRAM) + LENGTH (HIFRAM)) :
   {
     PROVIDE (__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");
   }
 
   .text :
index 26d62ac407f0924b7a94b7a6bd52fd86f5d8f4d5..49442d11e46fb3396e03ce70ac36314ee2fc9554 100644 (file)
@@ -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 : {
index d560b14092d6e0de45659fdf72755e3c5a4050a0..271104af2adcfdf13b19e9a4783371fbf9d776c6 100644 (file)
@@ -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 : {
index b5802c511582d4ffbc3c2a258ec81d5534b49393..a9bbf1fec3ddae4d8e81070a8408a6dddd3c3ff4 100644 (file)
@@ -155,10 +155,26 @@ SECTIONS
   } > RAM
   PROVIDE (__bsssize = SIZEOF(.bss) / 4);
 
+  /* 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");
   } > STACK
 
   /* Providing one of these symbols in your code is sufficient to have
@@ -213,7 +229,7 @@ SECTIONS
   /* DWARF 2 */
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
-  .debug_line     0 : { *(.debug_line) }
+  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }
   .debug_frame    0 : { *(.debug_frame) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
index f56fe01ea16db2eae8e67b4819b1a16b02666666..1a56d8daf8da14aaf9b32da6f36a52cf3a3e6838 100644 (file)
@@ -159,10 +159,26 @@ SECTIONS
   } > RAM
   PROVIDE (__bsssize = SIZEOF(.bss) / 4);
 
+  /* 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");
   }
 
   /* Providing one of these symbols in your code is sufficient to have
@@ -217,7 +233,7 @@ SECTIONS
   /* DWARF 2 */
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
-  .debug_line     0 : { *(.debug_line) }
+  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }
   .debug_frame    0 : { *(.debug_frame) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
This page took 0.043572 seconds and 5 git commands to generate.