Skip to content

Commit

Permalink
Try to fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jun 6, 2016
1 parent 2130ed7 commit 878d665
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class JuliaJITEventListener: public JITEventListener
uint64_t SectionAddrCheck = 0; // assert that all of the Sections are at the same location
uint8_t *UnwindData = NULL;
#if defined(_CPU_X86_64_)
uint64_t SectionLoadOffset = 1; // The real offset shouldn't be 1.
uint8_t *catchjmp = NULL;
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
StringRef sName;
Expand Down Expand Up @@ -396,6 +397,10 @@ class JuliaJITEventListener: public JITEventListener
#endif
Addr -= SectionAddr - SectionLoadAddr;
*pAddr = (uint8_t*)Addr;
if (SectionLoadOffset != 1)
assert(SectionLoadOffset == SectionAddr - SectionLoadAddr);
else
SectionLoadOffset = SectionAddr - SectionLoadAddr;
if (SectionAddrCheck)
assert(SectionAddrCheck == SectionLoadAddr);
else
Expand All @@ -405,20 +410,22 @@ class JuliaJITEventListener: public JITEventListener
assert(catchjmp);
assert(UnwindData);
assert(SectionAddrCheck);
catchjmp[0] = 0x48;
catchjmp[1] = 0xb8; // mov RAX, QWORD PTR [&_seh_exception_handle]
*(uint64_t*)(&catchjmp[2]) = (uint64_t)&_seh_exception_handler;
catchjmp[10] = 0xff;
catchjmp[11] = 0xe0; // jmp RAX
UnwindData[0] = 0x09; // version info, UNW_FLAG_EHANDLER
UnwindData[1] = 4; // size of prolog (bytes)
UnwindData[2] = 2; // count of unwind codes (slots)
UnwindData[3] = 0x05; // frame register (rbp) = rsp
UnwindData[4] = 4; // second instruction
UnwindData[5] = 0x03; // mov RBP, RSP
UnwindData[6] = 1; // first instruction
UnwindData[7] = 0x50; // push RBP
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionAddrCheck); // relative location of catchjmp
assert(SectionLoadOffset != 1);
catchjmp[SectionLoadOffset] = 0x48;
catchjmp[SectionLoadOffset + 1] = 0xb8; // mov RAX, QWORD PTR [&_seh_exception_handle]
*(uint64_t*)(&catchjmp[SectionLoadOffset + 2]) =
(uint64_t)&_seh_exception_handler;
catchjmp[SectionLoadOffset + 10] = 0xff;
catchjmp[SectionLoadOffset + 11] = 0xe0; // jmp RAX
UnwindData[SectionLoadOffset] = 0x09; // version info, UNW_FLAG_EHANDLER
UnwindData[SectionLoadOffset + 1] = 4; // size of prolog (bytes)
UnwindData[SectionLoadOffset + 2] = 2; // count of unwind codes (slots)
UnwindData[SectionLoadOffset + 3] = 0x05; // frame register (rbp) = rsp
UnwindData[SectionLoadOffset + 4] = 4; // second instruction
UnwindData[SectionLoadOffset + 5] = 0x03; // mov RBP, RSP
UnwindData[SectionLoadOffset + 6] = 1; // first instruction
UnwindData[SectionLoadOffset + 7] = 0x50; // push RBP
*(DWORD*)&UnwindData[SectionLoadOffset + 8] = (DWORD)(catchjmp - (uint8_t*)SectionAddrCheck); // relative location of catchjmp
#endif // defined(_OS_X86_64_)
#endif // defined(_OS_WINDOWS_)

Expand Down

0 comments on commit 878d665

Please sign in to comment.