aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-11-23 04:28:44 +0100
committerTristan Gingold <tgingold@free.fr>2018-11-23 04:29:21 +0100
commitf2c4cfadb13dd5eef1979069317e5c6ee224c908 (patch)
tree501db6bae01657d120a033f3ff2414b011e9135e /src/grt
parent3d81a74f66c2440ebde7efc64415d6c5510e94ee (diff)
downloadghdl-f2c4cfadb13dd5eef1979069317e5c6ee224c908.tar.gz
ghdl-f2c4cfadb13dd5eef1979069317e5c6ee224c908.tar.bz2
ghdl-f2c4cfadb13dd5eef1979069317e5c6ee224c908.zip
Add --max-stack-alloc option, check stack allocation of complex object.
Fix #692
Diffstat (limited to 'src/grt')
-rw-r--r--src/grt/grt-lib.adb13
-rw-r--r--src/grt/grt-lib.ads8
-rw-r--r--src/grt/grt-options.adb16
3 files changed, 37 insertions, 0 deletions
diff --git a/src/grt/grt-lib.adb b/src/grt/grt-lib.adb
index 7597bcfc4..0bb9c2e36 100644
--- a/src/grt/grt-lib.adb
+++ b/src/grt/grt-lib.adb
@@ -275,6 +275,19 @@ package body Grt.Lib is
return Ghdl_I64_Exp_1 (V, E);
end Ghdl_I64_Exp;
+ procedure Ghdl_Check_Stack_Allocation (Size : Ghdl_Index_Type)
+ is
+ Bt : Backtrace_Addrs;
+ begin
+ if Size >= Max_Stack_Allocation then
+ Save_Backtrace (Bt, 1);
+ Error_S ("declaration of a too large object (");
+ Diag_C (Natural (Size / 1024));
+ Diag_C (" KB)");
+ Error_E_Call_Stack (Bt);
+ end if;
+ end Ghdl_Check_Stack_Allocation;
+
function C_Malloc (Size : Ghdl_Index_Type) return Ghdl_Ptr;
pragma Import (C, C_Malloc, "malloc");
diff --git a/src/grt/grt-lib.ads b/src/grt/grt-lib.ads
index 646cdd5fb..167ea98e5 100644
--- a/src/grt/grt-lib.ads
+++ b/src/grt/grt-lib.ads
@@ -70,6 +70,11 @@ package Grt.Lib is
function Ghdl_I32_Exp (V : Ghdl_I32; E : Std_Integer) return Ghdl_I32;
function Ghdl_I64_Exp (V : Ghdl_I64; E : Std_Integer) return Ghdl_I64;
+ -- Called before allocation of large (complex) objects.
+ procedure Ghdl_Check_Stack_Allocation (Size : Ghdl_Index_Type);
+
+ Max_Stack_Allocation : Ghdl_Index_Type := 128 * 1024;
+
function Ghdl_Malloc (Size : Ghdl_Index_Type) return Ghdl_Ptr;
-- Allocate and clear SIZE bytes.
@@ -122,6 +127,9 @@ private
"__ghdl_direction_check_failed");
pragma Export (C, Ghdl_Program_Error, "__ghdl_program_error");
+ pragma Export (C, Ghdl_Check_Stack_Allocation,
+ "__ghdl_check_stack_allocation");
+
pragma Export (C, Ghdl_Malloc, "__ghdl_malloc");
pragma Export (C, Ghdl_Malloc0, "__ghdl_malloc0");
pragma Export (C, Ghdl_Deallocate, "__ghdl_deallocate");
diff --git a/src/grt/grt-options.adb b/src/grt/grt-options.adb
index 5b154e4a5..d93ad9e58 100644
--- a/src/grt/grt-options.adb
+++ b/src/grt/grt-options.adb
@@ -56,6 +56,7 @@ package body Grt.Options is
P (" X is expressed as a time value, without spaces: 1ns, ps...");
P (" --stop-delta=X stop the simulation cycle after X delta");
P (" --expect-failure invert exit status");
+ P (" --max-stack-alloc=X error if variables are larger than X KB");
P (" --no-run do not simulate, only elaborate");
P (" --unbuffered disable buffering on stdout, stderr and");
P (" files opened in write or append mode (TEXTIO).");
@@ -272,6 +273,21 @@ package body Grt.Options is
Warning ("option --stack-size is deprecated");
elsif Len >= 17 and then Option (1 .. 17) = "--stack-max-size=" then
Warning ("option --stack-max-size is deprecated");
+ elsif Len >= 18 and then Option (1 .. 18) = "--max-stack-alloc=" then
+ declare
+ Ok : Boolean;
+ Pos : Natural;
+ Val : Integer_64;
+ begin
+ Extract_Integer (Option (19 .. Len), Ok, Val, Pos);
+ if not Ok or else Pos <= Len then
+ Error_S ("bad value in '");
+ Diag_C (Option);
+ Error_E ("'");
+ else
+ Lib.Max_Stack_Allocation := Ghdl_Index_Type (Val * 1024);
+ end if;
+ end;
elsif Len >= 11 and then Option (1 .. 11) = "--activity=" then
if Option (12 .. Len) = "none" then
Flag_Activity := Activity_None;