@@ -313,10 +313,11 @@ class JuliaJITEventListener: public JITEventListener
313
313
#endif
314
314
315
315
#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 ;
317
319
uint8_t *UnwindData = NULL ;
318
320
#if defined(_CPU_X86_64_)
319
- uint64_t SectionLoadOffset = 1 ; // The real offset shouldn't be 1.
320
321
uint8_t *catchjmp = NULL ;
321
322
for (const object::SymbolRef &sym_iter : debugObj.symbols ()) {
322
323
StringRef sName = cantFail (sym_iter.getName ());
@@ -338,41 +339,40 @@ class JuliaJITEventListener: public JITEventListener
338
339
Section->getName (sName );
339
340
#endif
340
341
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;
347
349
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;
355
354
}
356
355
}
357
356
assert (catchjmp);
358
357
assert (UnwindData);
359
358
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
376
376
#endif // defined(_OS_X86_64_)
377
377
#endif // defined(_OS_WINDOWS_)
378
378
@@ -400,9 +400,10 @@ class JuliaJITEventListener: public JITEventListener
400
400
size_t Size = sym_size.second ;
401
401
#if defined(_OS_WINDOWS_)
402
402
if (SectionAddrCheck)
403
- assert (SectionAddrCheck == SectionLoadAddr);
404
- else
405
- SectionAddrCheck = SectionLoadAddr;
403
+ assert (SectionAddrCheck == SectionAddr &&
404
+ SectionLoadCheck == SectionLoadAddr);
405
+ SectionAddrCheck = SectionAddr;
406
+ SectionLoadCheck = SectionLoadAddr;
406
407
create_PRUNTIME_FUNCTION (
407
408
(uint8_t *)(uintptr_t )Addr, (size_t )Size, sName ,
408
409
(uint8_t *)(uintptr_t )SectionLoadAddr, (size_t )SectionSize, UnwindData);
0 commit comments