Skip to content

Commit f9ae3f2

Browse files
authored
Merge pull request #225 from SChernykh/msvc-debug-fix
Fixed a crash in MSVC Debug and RelWithDebInfo builds
2 parents d589aa2 + bbc9ccc commit f9ae3f2

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "a
108108

109109
set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2)
110110

111+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
112+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
113+
111114
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm
112115
COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0
113116
COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}"

src/jit_compiler_x86.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,28 @@ namespace randomx {
9494

9595
constexpr int32_t superScalarHashOffset = RandomXCodeSize;
9696

97-
const uint8_t* codePrologue = (uint8_t*)&randomx_program_prologue;
98-
const uint8_t* codeLoopBegin = (uint8_t*)&randomx_program_loop_begin;
99-
const uint8_t* codeLoopLoad = (uint8_t*)&randomx_program_loop_load;
100-
const uint8_t* codeProgamStart = (uint8_t*)&randomx_program_start;
101-
const uint8_t* codeReadDataset = (uint8_t*)&randomx_program_read_dataset;
102-
const uint8_t* codeReadDatasetLightSshInit = (uint8_t*)&randomx_program_read_dataset_sshash_init;
103-
const uint8_t* codeReadDatasetLightSshFin = (uint8_t*)&randomx_program_read_dataset_sshash_fin;
104-
const uint8_t* codeDatasetInit = (uint8_t*)&randomx_dataset_init;
105-
const uint8_t* codeLoopStore = (uint8_t*)&randomx_program_loop_store;
106-
const uint8_t* codeLoopEnd = (uint8_t*)&randomx_program_loop_end;
107-
const uint8_t* codeEpilogue = (uint8_t*)&randomx_program_epilogue;
108-
const uint8_t* codeProgramEnd = (uint8_t*)&randomx_program_end;
109-
const uint8_t* codeShhLoad = (uint8_t*)&randomx_sshash_load;
110-
const uint8_t* codeShhPrefetch = (uint8_t*)&randomx_sshash_prefetch;
111-
const uint8_t* codeShhEnd = (uint8_t*)&randomx_sshash_end;
112-
const uint8_t* codeShhInit = (uint8_t*)&randomx_sshash_init;
97+
#if defined(_MSC_VER) && (defined(_DEBUG) || defined (RELWITHDEBINFO))
98+
#define ADDR(x) ((((uint8_t*)&x)[0] == 0xE9) ? (((uint8_t*)&x) + *(const int32_t*)(((uint8_t*)&x) + 1) + 5) : ((uint8_t*)&x))
99+
#else
100+
#define ADDR(x) ((uint8_t*)&x)
101+
#endif
102+
103+
const uint8_t* codePrologue = ADDR(randomx_program_prologue);
104+
const uint8_t* codeLoopBegin = ADDR(randomx_program_loop_begin);
105+
const uint8_t* codeLoopLoad = ADDR(randomx_program_loop_load);
106+
const uint8_t* codeProgamStart = ADDR(randomx_program_start);
107+
const uint8_t* codeReadDataset = ADDR(randomx_program_read_dataset);
108+
const uint8_t* codeReadDatasetLightSshInit = ADDR(randomx_program_read_dataset_sshash_init);
109+
const uint8_t* codeReadDatasetLightSshFin = ADDR(randomx_program_read_dataset_sshash_fin);
110+
const uint8_t* codeDatasetInit = ADDR(randomx_dataset_init);
111+
const uint8_t* codeLoopStore = ADDR(randomx_program_loop_store);
112+
const uint8_t* codeLoopEnd = ADDR(randomx_program_loop_end);
113+
const uint8_t* codeEpilogue = ADDR(randomx_program_epilogue);
114+
const uint8_t* codeProgramEnd = ADDR(randomx_program_end);
115+
const uint8_t* codeShhLoad = ADDR(randomx_sshash_load);
116+
const uint8_t* codeShhPrefetch = ADDR(randomx_sshash_prefetch);
117+
const uint8_t* codeShhEnd = ADDR(randomx_sshash_end);
118+
const uint8_t* codeShhInit = ADDR(randomx_sshash_init);
113119

114120
const int32_t prologueSize = codeLoopBegin - codePrologue;
115121
const int32_t loopLoadSize = codeProgamStart - codeLoopLoad;
@@ -320,7 +326,7 @@ namespace randomx {
320326
emitByte(0xc0 + pcfg.readReg0);
321327
emit(REX_XOR_RAX_R64);
322328
emitByte(0xc0 + pcfg.readReg1);
323-
emit((const uint8_t*)&randomx_prefetch_scratchpad, ((uint8_t*)&randomx_prefetch_scratchpad_end) - ((uint8_t*)&randomx_prefetch_scratchpad));
329+
emit(ADDR(randomx_prefetch_scratchpad), ADDR(randomx_prefetch_scratchpad_end) - ADDR(randomx_prefetch_scratchpad));
324330
memcpy(code + codePos, codeLoopStore, loopStoreSize);
325331
codePos += loopStoreSize;
326332
emit(SUB_EBX);

0 commit comments

Comments
 (0)