Merge pull request #225 from SChernykh/msvc-debug-fix

Fixed a crash in MSVC Debug and RelWithDebInfo builds
This commit is contained in:
tevador 2021-11-08 19:59:50 +01:00 committed by GitHub
commit f9ae3f2351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions

View File

@ -108,6 +108,9 @@ if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "a
set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2) set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm
COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0 COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0
COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}"

View File

@ -94,22 +94,28 @@ namespace randomx {
constexpr int32_t superScalarHashOffset = RandomXCodeSize; constexpr int32_t superScalarHashOffset = RandomXCodeSize;
const uint8_t* codePrologue = (uint8_t*)&randomx_program_prologue; #if defined(_MSC_VER) && (defined(_DEBUG) || defined (RELWITHDEBINFO))
const uint8_t* codeLoopBegin = (uint8_t*)&randomx_program_loop_begin; #define ADDR(x) ((((uint8_t*)&x)[0] == 0xE9) ? (((uint8_t*)&x) + *(const int32_t*)(((uint8_t*)&x) + 1) + 5) : ((uint8_t*)&x))
const uint8_t* codeLoopLoad = (uint8_t*)&randomx_program_loop_load; #else
const uint8_t* codeProgamStart = (uint8_t*)&randomx_program_start; #define ADDR(x) ((uint8_t*)&x)
const uint8_t* codeReadDataset = (uint8_t*)&randomx_program_read_dataset; #endif
const uint8_t* codeReadDatasetLightSshInit = (uint8_t*)&randomx_program_read_dataset_sshash_init;
const uint8_t* codeReadDatasetLightSshFin = (uint8_t*)&randomx_program_read_dataset_sshash_fin; const uint8_t* codePrologue = ADDR(randomx_program_prologue);
const uint8_t* codeDatasetInit = (uint8_t*)&randomx_dataset_init; const uint8_t* codeLoopBegin = ADDR(randomx_program_loop_begin);
const uint8_t* codeLoopStore = (uint8_t*)&randomx_program_loop_store; const uint8_t* codeLoopLoad = ADDR(randomx_program_loop_load);
const uint8_t* codeLoopEnd = (uint8_t*)&randomx_program_loop_end; const uint8_t* codeProgamStart = ADDR(randomx_program_start);
const uint8_t* codeEpilogue = (uint8_t*)&randomx_program_epilogue; const uint8_t* codeReadDataset = ADDR(randomx_program_read_dataset);
const uint8_t* codeProgramEnd = (uint8_t*)&randomx_program_end; const uint8_t* codeReadDatasetLightSshInit = ADDR(randomx_program_read_dataset_sshash_init);
const uint8_t* codeShhLoad = (uint8_t*)&randomx_sshash_load; const uint8_t* codeReadDatasetLightSshFin = ADDR(randomx_program_read_dataset_sshash_fin);
const uint8_t* codeShhPrefetch = (uint8_t*)&randomx_sshash_prefetch; const uint8_t* codeDatasetInit = ADDR(randomx_dataset_init);
const uint8_t* codeShhEnd = (uint8_t*)&randomx_sshash_end; const uint8_t* codeLoopStore = ADDR(randomx_program_loop_store);
const uint8_t* codeShhInit = (uint8_t*)&randomx_sshash_init; const uint8_t* codeLoopEnd = ADDR(randomx_program_loop_end);
const uint8_t* codeEpilogue = ADDR(randomx_program_epilogue);
const uint8_t* codeProgramEnd = ADDR(randomx_program_end);
const uint8_t* codeShhLoad = ADDR(randomx_sshash_load);
const uint8_t* codeShhPrefetch = ADDR(randomx_sshash_prefetch);
const uint8_t* codeShhEnd = ADDR(randomx_sshash_end);
const uint8_t* codeShhInit = ADDR(randomx_sshash_init);
const int32_t prologueSize = codeLoopBegin - codePrologue; const int32_t prologueSize = codeLoopBegin - codePrologue;
const int32_t loopLoadSize = codeProgamStart - codeLoopLoad; const int32_t loopLoadSize = codeProgamStart - codeLoopLoad;
@ -320,7 +326,7 @@ namespace randomx {
emitByte(0xc0 + pcfg.readReg0); emitByte(0xc0 + pcfg.readReg0);
emit(REX_XOR_RAX_R64); emit(REX_XOR_RAX_R64);
emitByte(0xc0 + pcfg.readReg1); emitByte(0xc0 + pcfg.readReg1);
emit((const uint8_t*)&randomx_prefetch_scratchpad, ((uint8_t*)&randomx_prefetch_scratchpad_end) - ((uint8_t*)&randomx_prefetch_scratchpad)); emit(ADDR(randomx_prefetch_scratchpad), ADDR(randomx_prefetch_scratchpad_end) - ADDR(randomx_prefetch_scratchpad));
memcpy(code + codePos, codeLoopStore, loopStoreSize); memcpy(code + codePos, codeLoopStore, loopStoreSize);
codePos += loopStoreSize; codePos += loopStoreSize;
emit(SUB_EBX); emit(SUB_EBX);