From 2cdc5ea48b61ae22b64418ccfdbefc67c5209d60 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 3 Mar 2024 12:33:11 -0500 Subject: [PATCH] Fix unaligned access in --trace --runtime-debug (#4941). --- include/verilated_trace_imp.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/verilated_trace_imp.h b/include/verilated_trace_imp.h index 794ca4363..0f9de329a 100644 --- a/include/verilated_trace_imp.h +++ b/include/verilated_trace_imp.h @@ -190,13 +190,16 @@ void VerilatedTrace::offloadWorkerThreadMain() { //=== // Rare commands - case VerilatedTraceOffloadCommand::TIME_CHANGE: + case VerilatedTraceOffloadCommand::TIME_CHANGE: { VL_TRACE_OFFLOAD_DEBUG("Command TIME_CHANGE " << top); readp -= 1; // No code in this command, undo increment - emitTimeChange(*reinterpret_cast(readp)); + const uint64_t timeui + = static_cast(*reinterpret_cast(readp)) << 32ULL + | static_cast(*reinterpret_cast(readp + 1)); + emitTimeChange(timeui); readp += 2; continue; - + } case VerilatedTraceOffloadCommand::TRACE_BUFFER: VL_TRACE_OFFLOAD_DEBUG("Command TRACE_BUFFER " << top); readp -= 1; // No code in this command, undo increment @@ -574,7 +577,10 @@ void VerilatedTrace::dump(uint64_t timeui) VL_MT_SAFE_EXCLUD // Tell worker to update time point m_offloadBufferWritep[0] = VerilatedTraceOffloadCommand::TIME_CHANGE; - *reinterpret_cast(m_offloadBufferWritep + 1) = timeui; + *reinterpret_cast(m_offloadBufferWritep + 1) + = static_cast(timeui >> 32ULL); + *reinterpret_cast(m_offloadBufferWritep + 2) + = static_cast(timeui); m_offloadBufferWritep += 3; } else { // Update time point