@@ -313,11 +313,10 @@ class JuliaJITEventListener: public JITEventListener
313
313
#endif
314
314
315
315
#if defined(_OS_WINDOWS_)
316
- uint64_t SectionAddrCheck = 0 ;
317
- uint64_t SectionLoadCheck = 0 ;
318
- uint64_t SectionWriteCheck = 0 ;
316
+ uint64_t SectionAddrCheck = 0 ; // assert that all of the Sections are at the same location
319
317
uint8_t *UnwindData = NULL ;
320
318
#if defined(_CPU_X86_64_)
319
+ uint64_t SectionLoadOffset = 1 ; // The real offset shouldn't be 1.
321
320
uint8_t *catchjmp = NULL ;
322
321
for (const object::SymbolRef &sym_iter : debugObj.symbols ()) {
323
322
StringRef sName = cantFail (sym_iter.getName ());
@@ -339,38 +338,41 @@ class JuliaJITEventListener: public JITEventListener
339
338
Section->getName (sName );
340
339
#endif
341
340
uint64_t SectionLoadAddr = getLoadAddress (sName );
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;
349
- if (memmgr)
350
- SectionWriteCheck = (uintptr_t )lookupWriteAddressFor (memmgr,
351
- (void *)SectionLoadAddr);
352
- Addr += SectionWriteCheck - SectionLoadAddr;
341
+ Addr -= SectionAddr - SectionLoadAddr;
353
342
*pAddr = (uint8_t *)Addr;
343
+ if (SectionAddrCheck)
344
+ assert (SectionAddrCheck == SectionLoadAddr);
345
+ else
346
+ SectionAddrCheck = SectionLoadAddr;
347
+ 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;
354
355
}
355
356
}
356
357
assert (catchjmp);
357
358
assert (UnwindData);
358
359
assert (SectionAddrCheck);
359
- assert (SectionLoadCheck);
360
- catchjmp[0 ] = 0x48 ;
361
- catchjmp[1 ] = 0xb8 ; // mov RAX, QWORD PTR [&__julia_personality]
362
- *(uint64_t *)(&catchjmp[2 ]) = (uint64_t )&__julia_personality;
363
- catchjmp[10 ] = 0xff ;
364
- catchjmp[11 ] = 0xe0 ; // jmp RAX
365
- UnwindData[0 ] = 0x09 ; // version info, UNW_FLAG_EHANDLER
366
- UnwindData[1 ] = 4 ; // size of prolog (bytes)
367
- UnwindData[2 ] = 2 ; // count of unwind codes (slots)
368
- UnwindData[3 ] = 0x05 ; // frame register (rbp) = rsp
369
- UnwindData[4 ] = 4 ; // second instruction
370
- UnwindData[5 ] = 0x03 ; // mov RBP, RSP
371
- UnwindData[6 ] = 1 ; // first instruction
372
- UnwindData[7 ] = 0x50 ; // push RBP
373
- *(DWORD*)&UnwindData[8 ] = (DWORD)(catchjmp - (uint8_t *)SectionWriteCheck); // relative location of catchjmp
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
374
376
#endif // defined(_OS_X86_64_)
375
377
#endif // defined(_OS_WINDOWS_)
376
378
@@ -398,10 +400,9 @@ class JuliaJITEventListener: public JITEventListener
398
400
size_t Size = sym_size.second ;
399
401
#if defined(_OS_WINDOWS_)
400
402
if (SectionAddrCheck)
401
- assert (SectionAddrCheck == SectionAddr &&
402
- SectionLoadCheck == SectionLoadAddr);
403
- SectionAddrCheck = SectionAddr;
404
- SectionLoadCheck = SectionLoadAddr;
403
+ assert (SectionAddrCheck == SectionLoadAddr);
404
+ else
405
+ SectionAddrCheck = SectionLoadAddr;
405
406
create_PRUNTIME_FUNCTION (
406
407
(uint8_t *)(uintptr_t )Addr, (size_t )Size, sName ,
407
408
(uint8_t *)(uintptr_t )SectionLoadAddr, (size_t )SectionSize, UnwindData);
0 commit comments