diff --git a/include/verilated.cpp b/include/verilated.cpp index cbb10ad58..1a0377f11 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -3128,12 +3128,21 @@ void Verilated::stackCheck(QData needSize) VL_MT_UNSAFE { if (haveSize == RLIM_INFINITY) haveSize = 0; } // VL_PRINTF_MT("-Info: stackCheck(%" PRIu64 ") have %" PRIu64 "\n", needSize, haveSize); - // Check for 1.5x need, but suggest 2x so small model increase won't cause warning - // if the user follows the suggestions - if (VL_UNLIKELY(haveSize && needSize && haveSize < (needSize + needSize / 2))) { - VL_PRINTF_MT("%%Warning: System has stack size %" PRIu64 " kb" - " which may be too small; suggest 'ulimit -s %" PRIu64 "' or larger\n", - haveSize / 1024, (needSize * 2) / 1024); + // Check and request for 1.5x need. This is automated so the user doesn't need to do anything. + QData requestSize = needSize + needSize / 2; + if (VL_UNLIKELY(haveSize && needSize && haveSize < requestSize)) { + // Try to increase the stack limit to the requested size + rlim.rlim_cur = requestSize; + if ( +#ifdef _VL_TEST_RLIMIT_FAIL + true || +#endif + setrlimit(RLIMIT_STACK, &rlim)) { + VL_PRINTF_MT("%%Warning: System has stack size %" PRIu64 " kb" + " which may be too small; failed to request more" + " using 'ulimit -s %" PRIu64 "'\n", + haveSize / 1024, requestSize); + } } #else (void)needSize; // Unused argument diff --git a/test_regress/t/t_stack_check.pl b/test_regress/t/t_stack_check.pl index 934833563..2cf86f001 100755 --- a/test_regress/t/t_stack_check.pl +++ b/test_regress/t/t_stack_check.pl @@ -16,6 +16,5 @@ compile( execute(); -file_grep($Self->{run_log_filename}, qr/.*%Warning: System has stack size/); ok(1); 1; diff --git a/test_regress/t/t_stack_check_fail.pl b/test_regress/t/t_stack_check_fail.pl new file mode 100755 index 000000000..a2ef01d76 --- /dev/null +++ b/test_regress/t/t_stack_check_fail.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2024 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +top_filename("t/t_stack_check.v"); + +scenarios(vlt => 1); + +compile( + verilator_flags2 => ['--binary --debug-stack-check', '--CFLAGS', '"-D_VL_TEST_RLIMIT_FAIL"'], + ); + +execute(); + +file_grep($Self->{run_log_filename}, qr/.*%Warning: System has stack size/); +ok(1); +1;