Add `--aslr` and `--no-aslr` options.

This commit is contained in:
Wilson Snyder 2025-10-20 19:41:32 -04:00
parent 24e665f38f
commit 61de46cea2
7 changed files with 68 additions and 14 deletions

View File

@ -25,6 +25,7 @@ Verilator 5.041 devel
* Add error on `virtual new` (#6486). [Alex Solomatnikov]
* Add error on ranges with tristate values (#6534). [Alex Solomatnikov]
* Add NORETURN warning on functions without return values (#6534). [Alex Solomatnikov]
* Add `--aslr` and `--no-aslr` options.
* Deprecate sensitivity list on public_flat_rw attributes (#6443). [Geza Lore]
* Deprecate clocker attribute and --clk option (#6463). [Geza Lore]
* Deprecate '--make cmake' option (#6540). [Geza Lore]

View File

@ -28,6 +28,7 @@ autoflush STDOUT 1;
autoflush STDERR 1;
$Debug = 0;
my $opt_aslr;
my $opt_gdb;
my $opt_rr;
my $opt_gdbbt;
@ -56,6 +57,7 @@ if (! GetOptions(
"debug" => \&debug,
# "version!" => \&version, # Also passthru'ed
# Switches
"aslr!" => \$opt_aslr,
"gdb!" => \$opt_gdb,
"gdbbt!" => \$opt_gdbbt,
"quiet!" => \$opt_quiet_exit, # As -quiet implies -quiet-exit
@ -97,7 +99,7 @@ my @quoted_sw = map { sh_escape($_) } @Opt_Verilator_Sw;
if ($opt_gdb) {
# Generic GDB interactive
run (ulimit_stack_unlimited()
. aslr_off()
. aslr(0)
. ($ENV{VERILATOR_GDB} || "gdb")
. " " . verilator_bin()
# Note, uncomment to set breakpoints before running:
@ -114,13 +116,13 @@ if ($opt_gdb) {
} elsif ($opt_rr) {
# Record with rr
run (ulimit_stack_unlimited()
. aslr_off()
. aslr(0)
. "rr record " . verilator_bin()
. " " . join(' ', @quoted_sw));
} elsif ($opt_gdbbt && $Debug) {
# Run under GDB to get gdbbt
run (ulimit_stack_unlimited()
. aslr_off()
. aslr(0)
. "gdb"
. " " . verilator_bin()
. " --batch --quiet --return-child-result"
@ -135,19 +137,19 @@ if ($opt_gdb) {
);
run (ulimit_stack_unlimited()
. aslr_off()
. aslr(0)
. $valgrind_bin
. " " . verilator_bin()
. " " . join(' ', @quoted_sw));
} elsif ($Debug) {
# Debug
run(ulimit_stack_unlimited()
. aslr_off()
. aslr(0)
. verilator_bin()
. " " . join(' ', @quoted_sw));
} else {
# Normal, non gdb
run(ulimit_stack_unlimited() . verilator_bin() . " " . join(' ', @quoted_sw));
run(ulimit_stack_unlimited() . aslr(1) . verilator_bin() . " " . join(' ', @quoted_sw));
}
#----------------------------------------------------------------------
@ -192,13 +194,16 @@ sub gdb_works {
return $status == 0;
}
sub aslr_off {
my $ok = `setarch --addr-no-randomize echo ok 2>/dev/null` || "";
if ($ok =~ /ok/) {
return "setarch --addr-no-randomize ";
} else {
return "";
sub aslr {
my $want_on = shift;
$want_on = $opt_aslr if defined $opt_aslr;
if (!$want_on) {
my $ok = `setarch --addr-no-randomize echo ok 2>/dev/null` || "";
if ($ok =~ /ok/) {
return "setarch --addr-no-randomize ";
}
}
return "";
}
sub ulimit_stack_unlimited {
@ -325,6 +330,7 @@ detailed descriptions of these arguments.
+1800-2012ext+<ext> Use SystemVerilog 2012 with file extension <ext>
+1800-2017ext+<ext> Use SystemVerilog 2017 with file extension <ext>
+1800-2023ext+<ext> Use SystemVerilog 2023 with file extension <ext>
--no-aslr Disable address space layout randomization
--no-assert Disable all assertions
--no-assert-case Disable unique/unique0/priority-case assertions
--autoflush Flush streams after all $displays

View File

@ -88,12 +88,23 @@ Summary:
grammar and other semantic extensions which might not be legal when
set to an older standard.
.. option:: --aslr
.. option:: --no-aslr
Rarely needed - for developer use. With `--aslr`, do not change the
system default as to using Linux address space layout randomization
(ASLR). With `--no-aslr` attempt to disable ASLR. If not specified,
ASLR will be disabled only when using :vlopt:`--debug` (or similar
debug-related options), so that pointers have more deterministic values,
aiding repeatability.
.. option:: --no-assert
Disable all assertions. Implies :vlopt:`--no-assert-case`.
In versions before 5.038, these were disabled by default, and `--assert`
was required to enable assertions.
In versions before 5.038, assertions were disabled by default, and
`--assert` was required to enable assertions.
.. option:: --no-assert-case

View File

@ -531,6 +531,7 @@ architected
args
arrarys
asan
aslr
assertOn
assertcontrol
astgen

View File

@ -1237,6 +1237,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc,
[this](const char* optp) { addLangExt(optp, V3LangCode::L1800_2023); });
// Minus options
DECL_OPTION("-aslr", CbOnOff, [](bool) {}); // Processed only in bin/verilator shell
DECL_OPTION("-assert", CbOnOff, [this](bool flag) {
m_assert = flag;
m_assertCase = flag;

17
test_regress/t/t_flag_aslr.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 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
import vltest_bootstrap
test.scenarios('vlt')
test.top_filename = 't/t_EXAMPLE.v'
test.lint(v_flags2=["--aslr"])
test.passes()

View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 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
import vltest_bootstrap
test.scenarios('vlt')
test.top_filename = 't/t_EXAMPLE.v'
test.lint(v_flags2=["--no-aslr"])
test.passes()