Skip to content

Commit 713a5b1

Browse files
committed
debuginfo: fix offset to UnwindData on Win64
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)
1 parent df259f2 commit 713a5b1

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/cgmemmgr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static void unmap_page(void *ptr, size_t size)
6464
enum class Prot : int {
6565
RW = PAGE_READWRITE,
6666
RX = PAGE_EXECUTE,
67-
RO = PAGE_READONLY
67+
RO = PAGE_READONLY,
68+
NO = PAGE_NOACCESS
6869
};
6970

7071
static void protect_page(void *ptr, size_t size, Prot flags)
@@ -81,7 +82,8 @@ static void protect_page(void *ptr, size_t size, Prot flags)
8182
enum class Prot : int {
8283
RW = PROT_READ | PROT_WRITE,
8384
RX = PROT_READ | PROT_EXEC,
84-
RO = PROT_READ
85+
RO = PROT_READ,
86+
NO = PROT_NONE
8587
};
8688

8789
static void protect_page(void *ptr, size_t size, Prot flags)
@@ -640,7 +642,7 @@ class DualMapAllocator : public ROAllocator<exec> {
640642
unmap_page((void*)block.wr_ptr, block.total);
641643
}
642644
else {
643-
protect_page((void*)block.wr_ptr, block.total, Prot::RO);
645+
protect_page((void*)block.wr_ptr, block.total, Prot::NO);
644646
block.state = SplitPtrBlock::WRInit;
645647
}
646648
}

src/debuginfo.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
131131
tbl->BeginAddress = (DWORD)(Code - Section);
132132
tbl->EndAddress = (DWORD)(Code - Section + Size);
133133
tbl->UnwindData = (DWORD)(UnwindData - Section);
134+
assert(Code >= Section && Code + Size <= Section + Allocated);
135+
assert(UnwindData >= Section && UnwindData <= Section + Allocated);
134136
#else // defined(_CPU_X86_64_)
135137
Section += (uintptr_t)Code;
136138
mod_size = Size;
@@ -306,20 +308,13 @@ class JuliaJITEventListener: public JITEventListener
306308
uint8_t *catchjmp = NULL;
307309
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
308310
StringRef sName = cantFail(sym_iter.getName());
309-
uint8_t **pAddr = NULL;
310-
if (sName.equals("__UnwindData")) {
311-
pAddr = &UnwindData;
312-
}
313-
else if (sName.equals("__catchjmp")) {
314-
pAddr = &catchjmp;
315-
}
316-
if (pAddr) {
311+
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
317312
uint64_t Addr = cantFail(sym_iter.getAddress());
318313
auto Section = cantFail(sym_iter.getSection());
319314
assert(Section != EndSection && Section->isText());
320315
uint64_t SectionAddr = Section->getAddress();
321-
sName = cantFail(Section->getName());
322-
uint64_t SectionLoadAddr = getLoadAddress(sName);
316+
StringRef secName = cantFail(Section->getName());
317+
uint64_t SectionLoadAddr = getLoadAddress(secName);
323318
assert(SectionLoadAddr);
324319
if (SectionAddrCheck) // assert that all of the Sections are at the same location
325320
assert(SectionAddrCheck == SectionAddr &&
@@ -331,7 +326,12 @@ class JuliaJITEventListener: public JITEventListener
331326
SectionWriteCheck = (uintptr_t)lookupWriteAddressFor(memmgr,
332327
(void*)SectionLoadAddr);
333328
Addr += SectionWriteCheck - SectionLoadAddr;
334-
*pAddr = (uint8_t*)Addr;
329+
if (sName.equals("__UnwindData")) {
330+
UnwindData = (uint8_t*)Addr;
331+
}
332+
else if (sName.equals("__catchjmp")) {
333+
catchjmp = (uint8_t*)Addr;
334+
}
335335
}
336336
}
337337
assert(catchjmp);
@@ -354,6 +354,7 @@ class JuliaJITEventListener: public JITEventListener
354354
UnwindData[6] = 1; // first instruction
355355
UnwindData[7] = 0x50; // push RBP
356356
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
357+
UnwindData -= SectionWriteCheck - SectionLoadCheck;
357358
#endif // defined(_OS_X86_64_)
358359
#endif // defined(_OS_WINDOWS_)
359360

0 commit comments

Comments
 (0)