@@ -313,10 +313,11 @@ class JuliaJITEventListener: public JITEventListener
313313#endif
314314
315315#if defined(_OS_WINDOWS_)
316- uint64_t SectionAddrCheck = 0 ; // assert that all of the Sections are at the same location
316+ uint64_t SectionAddrCheck = 0 ;
317+ uint64_t SectionLoadCheck = 0 ;
318+ uint64_t SectionWriteCheck = 0 ;
317319 uint8_t *UnwindData = NULL ;
318320#if defined(_CPU_X86_64_)
319- uint64_t SectionLoadOffset = 1 ; // The real offset shouldn't be 1.
320321 uint8_t *catchjmp = NULL ;
321322 for (const object::SymbolRef &sym_iter : debugObj.symbols ()) {
322323 StringRef sName = cantFail (sym_iter.getName ());
@@ -338,41 +339,40 @@ class JuliaJITEventListener: public JITEventListener
338339 Section->getName (sName );
339340#endif
340341 uint64_t SectionLoadAddr = getLoadAddress (sName );
341- Addr -= SectionAddr - SectionLoadAddr;
342- *pAddr = (uint8_t *)Addr;
343- if (SectionAddrCheck)
344- assert (SectionAddrCheck == SectionLoadAddr);
345- else
346- SectionAddrCheck = SectionLoadAddr;
342+ assert (SectionLoadAddr);
343+ if (SectionAddrCheck) // assert that all of the Sections are at the same location
344+ assert (SectionAddrCheck == SectionAddr &&
345+ SectionLoadCheck == SectionLoadAddr);
346+ SectionAddrCheck = SectionAddr;
347+ SectionLoadCheck = SectionLoadAddr;
348+ SectionWriteCheck = SectionLoadAddr;
347349 if (memmgr)
348- SectionAddr =
349- (uintptr_t )lookupWriteAddressFor (memmgr,
350- (void *)SectionLoadAddr);
351- if (SectionLoadOffset != 1 )
352- assert (SectionLoadOffset == SectionAddr - SectionLoadAddr);
353- else
354- SectionLoadOffset = SectionAddr - SectionLoadAddr;
350+ SectionWriteCheck = (uintptr_t )lookupWriteAddressFor (memmgr,
351+ (void *)SectionLoadAddr);
352+ Addr += SectionWriteCheck - SectionLoadAddr;
353+ *pAddr = (uint8_t *)Addr;
355354 }
356355 }
357356 assert (catchjmp);
358357 assert (UnwindData);
359358 assert (SectionAddrCheck);
360- assert (SectionLoadOffset != 1 );
361- catchjmp[SectionLoadOffset] = 0x48 ;
362- catchjmp[SectionLoadOffset + 1 ] = 0xb8 ; // mov RAX, QWORD PTR [&__julia_personality]
363- *(uint64_t *)(&catchjmp[SectionLoadOffset + 2 ]) =
364- (uint64_t )&__julia_personality;
365- catchjmp[SectionLoadOffset + 10 ] = 0xff ;
366- catchjmp[SectionLoadOffset + 11 ] = 0xe0 ; // jmp RAX
367- UnwindData[SectionLoadOffset] = 0x09 ; // version info, UNW_FLAG_EHANDLER
368- UnwindData[SectionLoadOffset + 1 ] = 4 ; // size of prolog (bytes)
369- UnwindData[SectionLoadOffset + 2 ] = 2 ; // count of unwind codes (slots)
370- UnwindData[SectionLoadOffset + 3 ] = 0x05 ; // frame register (rbp) = rsp
371- UnwindData[SectionLoadOffset + 4 ] = 4 ; // second instruction
372- UnwindData[SectionLoadOffset + 5 ] = 0x03 ; // mov RBP, RSP
373- UnwindData[SectionLoadOffset + 6 ] = 1 ; // first instruction
374- UnwindData[SectionLoadOffset + 7 ] = 0x50 ; // push RBP
375- *(DWORD*)&UnwindData[SectionLoadOffset + 8 ] = (DWORD)(catchjmp - (uint8_t *)SectionAddrCheck); // relative location of catchjmp
359+ assert (SectionLoadCheck);
360+ assert (!memcmp (catchjmp, " \0\0\0\0\0\0\0\0\0\0\0\0 " , 12 ) &&
361+ !memcmp (UnwindData, " \0\0\0\0\0\0\0\0\0\0\0\0 " , 12 ));
362+ catchjmp[0 ] = 0x48 ;
363+ catchjmp[1 ] = 0xb8 ; // mov RAX, QWORD PTR [&__julia_personality]
364+ *(uint64_t *)(&catchjmp[2 ]) = (uint64_t )&__julia_personality;
365+ catchjmp[10 ] = 0xff ;
366+ catchjmp[11 ] = 0xe0 ; // jmp RAX
367+ UnwindData[0 ] = 0x09 ; // version info, UNW_FLAG_EHANDLER
368+ UnwindData[1 ] = 4 ; // size of prolog (bytes)
369+ UnwindData[2 ] = 2 ; // count of unwind codes (slots)
370+ UnwindData[3 ] = 0x05 ; // frame register (rbp) = rsp
371+ UnwindData[4 ] = 4 ; // second instruction
372+ UnwindData[5 ] = 0x03 ; // mov RBP, RSP
373+ UnwindData[6 ] = 1 ; // first instruction
374+ UnwindData[7 ] = 0x50 ; // push RBP
375+ *(DWORD*)&UnwindData[8 ] = (DWORD)(catchjmp - (uint8_t *)SectionWriteCheck); // relative location of catchjmp
376376#endif // defined(_OS_X86_64_)
377377#endif // defined(_OS_WINDOWS_)
378378
@@ -400,9 +400,10 @@ class JuliaJITEventListener: public JITEventListener
400400 size_t Size = sym_size.second ;
401401#if defined(_OS_WINDOWS_)
402402 if (SectionAddrCheck)
403- assert (SectionAddrCheck == SectionLoadAddr);
404- else
405- SectionAddrCheck = SectionLoadAddr;
403+ assert (SectionAddrCheck == SectionAddr &&
404+ SectionLoadCheck == SectionLoadAddr);
405+ SectionAddrCheck = SectionAddr;
406+ SectionLoadCheck = SectionLoadAddr;
406407 create_PRUNTIME_FUNCTION (
407408 (uint8_t *)(uintptr_t )Addr, (size_t )Size, sName ,
408409 (uint8_t *)(uintptr_t )SectionLoadAddr, (size_t )SectionSize, UnwindData);
0 commit comments