Skip to content

Commit 5415546

Browse files
authored
[svsim] Use -no_save instead of ASLR workarounds (#4845)
For the internal installation of VCS and RHEL, our simulations do not work due to VCS' save/restore functionality which will launch a simulation, detect if ASLR is present, and then kill the simulation and relaunch it with ASLR disabled. The workaround employed here has been empirically shown to be problematic for at least one user (#4837). Drop the ASLR workaround and add the runtime option `-no_save` which turns off VCS save/restore functionality. svsim doesn't support this and it's ill advised to use non-standard workarounds. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 7ff7fce commit 5415546

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

svsim/src/main/resources/simulation-driver.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
#include <strings.h>
3838
#include <unistd.h>
3939

40-
#ifdef SVSIM_BACKEND_ENGAGES_IN_ASLR_SHENANIGANS
41-
#include <sys/personality.h>
42-
#endif
43-
4440
#ifdef SVSIM_ENABLE_VERILATOR_SUPPORT
4541
#include "verilated-sources/VsvsimTestbench__Dpi.h"
4642
#define DPI_TASK_RETURN_TYPE int
@@ -188,8 +184,6 @@ static struct {
188184

189185
const char *simulationTraceFilepath = NULL;
190186

191-
bool aslrShenanigansDetected = false;
192-
193187
// Track any outstanding commands that are executing while `run_simulation` is
194188
// called. This will be cleared by `simulation_final` before termination.
195189
//
@@ -862,10 +856,6 @@ static bool processCommand() {
862856
}
863857

864858
DPI_TASK_RETURN_TYPE simulation_body() {
865-
if (state.aslrShenanigansDetected) {
866-
failWithError("Backend did not relaunch the executable with ASLR disabled "
867-
"as expected.");
868-
}
869859
/// If we have made it to `simulation_body`, there were no errors on startup
870860
/// and the first thing we do is send a READY message.
871861
sendReady();
@@ -930,16 +920,6 @@ DPI_TASK_RETURN_TYPE simulation_final() {
930920

931921
int main(int argc, const char *argv[]) {
932922

933-
#ifdef SVSIM_BACKEND_ENGAGES_IN_ASLR_SHENANIGANS
934-
if (!(personality(0xffffffff) & ADDR_NO_RANDOMIZE)) {
935-
// See note in `Workspace.scala` on
936-
// SVSIM_BACKEND_ENGAGES_IN_ASLR_SHENANIGANS
937-
state.aslrShenanigansDetected = true;
938-
simulation_main(argc, argv);
939-
failWithError("simulation_main returned.");
940-
}
941-
#endif
942-
943923
// Remap `stdin` and `stdout` so we can use the original `stdin` and `stdout`
944924
// for commands and messages.
945925
int stdinCopy = dup(STDIN_FILENO);

svsim/src/main/scala/Backend.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@ final object Backend {
213213
/** Verilator does not currently support delay (`#delay`) in DPI functions, so we omit the SystemVerilog definition of the `run_simulation` function and instead provide a C implementation.
214214
*/
215215
val supportsDelayInPublicFunctions = "SVSIM_BACKEND_SUPPORTS_DELAY_IN_PUBLIC_FUNCTIONS"
216-
217-
/** VCS first checks whether address-space layout randomization (ASLR) is enabled, and if it is, _helpfully_ relaunches this executable with ASLR disabled. Unfortunately, this causes code executed prior to `simulation_main` to be executed twice, which is problematic, especially since we redirect `stdin` and `stdout`.
218-
*/
219-
val backendEngagesInASLRShenanigans = "SVSIM_BACKEND_ENGAGES_IN_ASLR_SHENANIGANS"
220216
}
221217

222218
object Exceptions {

svsim/src/main/scala/vcs/Backend.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ final class Backend(
378378
Seq(
379379
// Enable VCS support
380380
s"-D${svsim.Backend.HarnessCompilationFlags.enableVCSSupport}",
381-
// VCS engages in ASLR shenanigans
382-
s"-D${svsim.Backend.HarnessCompilationFlags.backendEngagesInASLRShenanigans}",
383381
)
384382
)),
385383
).collect {
@@ -422,6 +420,14 @@ final class Backend(
422420
backendSpecificSettings.simulationSettings.coverageDirectory.map(_.toFlags).getOrElse(Seq.empty),
423421
backendSpecificSettings.simulationSettings.coverageName.map(_.toFlags).getOrElse(Seq.empty),
424422
commonSettings.simulationSettings.plusArgs.map(_.simulatorFlags),
423+
// In order to support save/restore functionality, VCS will detect if
424+
// Address Space Layout Randomization (ASLR) is ocurring when the
425+
// simulation starts. If it is, then VCS will relaunch the simulation
426+
// with ASLR turned off. This double-launch confuses svsim. To avoid
427+
// this, and because svsim doesn't support save/restore functionality,
428+
// we turn off VCS save/restore features. The simulation binary will
429+
// then only run once.
430+
Seq("-no_save")
425431
).flatten,
426432
environment = environment
427433
)

0 commit comments

Comments
 (0)