Skip to content

Commit

Permalink
debuginfo: fix offset to UnwindData on Win64
Browse files Browse the repository at this point in the history
We have 2 copies of this data, and so need to make sure we are pointing
at the correct one for runtime.

(cherry picked from commit 2f1f2f6)
  • Loading branch information
vtjnash committed Feb 24, 2022
1 parent f99cf7c commit 7452018
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ static void unmap_page(void *ptr, size_t size)
enum class Prot : int {
RW = PAGE_READWRITE,
RX = PAGE_EXECUTE,
RO = PAGE_READONLY
RO = PAGE_READONLY,
NO = PAGE_NOACCESS
};

static void protect_page(void *ptr, size_t size, Prot flags)
Expand All @@ -79,7 +80,8 @@ static void protect_page(void *ptr, size_t size, Prot flags)
enum class Prot : int {
RW = PROT_READ | PROT_WRITE,
RX = PROT_READ | PROT_EXEC,
RO = PROT_READ
RO = PROT_READ,
NO = PROT_NONE
};

static void protect_page(void *ptr, size_t size, Prot flags)
Expand Down Expand Up @@ -623,7 +625,7 @@ class DualMapAllocator : public ROAllocator<exec> {
unmap_page((void*)block.wr_ptr, block.total);
}
else {
protect_page((void*)block.wr_ptr, block.total, Prot::RO);
protect_page((void*)block.wr_ptr, block.total, Prot::NO);
block.state = SplitPtrBlock::WRInit;
}
}
Expand Down
26 changes: 14 additions & 12 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
tbl->BeginAddress = (DWORD)(Code - Section);
tbl->EndAddress = (DWORD)(Code - Section + Size);
tbl->UnwindData = (DWORD)(UnwindData - Section);
assert(Code >= Section && Code + Size <= Section + Allocated);
assert(UnwindData >= Section && UnwindData <= Section + Allocated);
#else // defined(_CPU_X86_64_)
Section += (uintptr_t)Code;
mod_size = Size;
Expand Down Expand Up @@ -321,24 +323,18 @@ class JuliaJITEventListener: public JITEventListener
uint8_t *catchjmp = NULL;
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
StringRef sName = cantFail(sym_iter.getName());
uint8_t **pAddr = NULL;
if (sName.equals("__UnwindData")) {
pAddr = &UnwindData;
}
else if (sName.equals("__catchjmp")) {
pAddr = &catchjmp;
}
if (pAddr) {
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
uint64_t Addr = cantFail(sym_iter.getAddress());
auto Section = cantFail(sym_iter.getSection());
assert(Section != EndSection && Section->isText());
uint64_t SectionAddr = Section->getAddress();
#if JL_LLVM_VERSION >= 100000
sName = cantFail(Section->getName());
StringRef secName = cantFail(Section->getName());
#else
Section->getName(sName);
StringRef secName;
Section->getName(secName);
#endif
uint64_t SectionLoadAddr = getLoadAddress(sName);
uint64_t SectionLoadAddr = getLoadAddress(secName);
assert(SectionLoadAddr);
if (SectionAddrCheck) // assert that all of the Sections are at the same location
assert(SectionAddrCheck == SectionAddr &&
Expand All @@ -350,7 +346,12 @@ class JuliaJITEventListener: public JITEventListener
SectionWriteCheck = (uintptr_t)lookupWriteAddressFor(memmgr,
(void*)SectionLoadAddr);
Addr += SectionWriteCheck - SectionLoadAddr;
*pAddr = (uint8_t*)Addr;
if (sName.equals("__UnwindData")) {
UnwindData = (uint8_t*)Addr;
}
else if (sName.equals("__catchjmp")) {
catchjmp = (uint8_t*)Addr;
}
}
}
assert(catchjmp);
Expand All @@ -373,6 +374,7 @@ class JuliaJITEventListener: public JITEventListener
UnwindData[6] = 1; // first instruction
UnwindData[7] = 0x50; // push RBP
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
UnwindData -= SectionWriteCheck - SectionLoadCheck;
#endif // defined(_OS_X86_64_)
#endif // defined(_OS_WINDOWS_)

Expand Down

0 comments on commit 7452018

Please sign in to comment.