Skip to content

Commit f5ab4fd

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 f99cf7c commit f5ab4fd

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/cgmemmgr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static void unmap_page(void *ptr, size_t size)
6262
enum class Prot : int {
6363
RW = PAGE_READWRITE,
6464
RX = PAGE_EXECUTE,
65-
RO = PAGE_READONLY
65+
RO = PAGE_READONLY,
66+
NO = PAGE_NOACCESS
6667
};
6768

6869
static void protect_page(void *ptr, size_t size, Prot flags)
@@ -79,7 +80,8 @@ static void protect_page(void *ptr, size_t size, Prot flags)
7980
enum class Prot : int {
8081
RW = PROT_READ | PROT_WRITE,
8182
RX = PROT_READ | PROT_EXEC,
82-
RO = PROT_READ
83+
RO = PROT_READ,
84+
NO = PROT_NONE
8385
};
8486

8587
static void protect_page(void *ptr, size_t size, Prot flags)
@@ -623,7 +625,7 @@ class DualMapAllocator : public ROAllocator<exec> {
623625
unmap_page((void*)block.wr_ptr, block.total);
624626
}
625627
else {
626-
protect_page((void*)block.wr_ptr, block.total, Prot::RO);
628+
protect_page((void*)block.wr_ptr, block.total, Prot::NO);
627629
block.state = SplitPtrBlock::WRInit;
628630
}
629631
}

src/debuginfo.cpp

Lines changed: 14 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;
@@ -321,24 +323,18 @@ class JuliaJITEventListener: public JITEventListener
321323
uint8_t *catchjmp = NULL;
322324
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
323325
StringRef sName = cantFail(sym_iter.getName());
324-
uint8_t **pAddr = NULL;
325-
if (sName.equals("__UnwindData")) {
326-
pAddr = &UnwindData;
327-
}
328-
else if (sName.equals("__catchjmp")) {
329-
pAddr = &catchjmp;
330-
}
331-
if (pAddr) {
326+
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
332327
uint64_t Addr = cantFail(sym_iter.getAddress());
333328
auto Section = cantFail(sym_iter.getSection());
334329
assert(Section != EndSection && Section->isText());
335330
uint64_t SectionAddr = Section->getAddress();
336331
#if JL_LLVM_VERSION >= 100000
337-
sName = cantFail(Section->getName());
332+
StringRef secName = cantFail(Section->getName());
338333
#else
339-
Section->getName(sName);
334+
StringRef secName;
335+
Section->getName(secName);
340336
#endif
341-
uint64_t SectionLoadAddr = getLoadAddress(sName);
337+
uint64_t SectionLoadAddr = getLoadAddress(secName);
342338
assert(SectionLoadAddr);
343339
if (SectionAddrCheck) // assert that all of the Sections are at the same location
344340
assert(SectionAddrCheck == SectionAddr &&
@@ -351,6 +347,12 @@ class JuliaJITEventListener: public JITEventListener
351347
(void*)SectionLoadAddr);
352348
Addr += SectionWriteCheck - SectionLoadAddr;
353349
*pAddr = (uint8_t*)Addr;
350+
if (sName.equals("__UnwindData")) {
351+
UnwindData = (uint8_t*)Addr;
352+
}
353+
else if (sName.equals("__catchjmp")) {
354+
catchjmp = (uint8_t*)Addr;
355+
}
354356
}
355357
}
356358
assert(catchjmp);
@@ -373,6 +375,7 @@ class JuliaJITEventListener: public JITEventListener
373375
UnwindData[6] = 1; // first instruction
374376
UnwindData[7] = 0x50; // push RBP
375377
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
378+
UnwindData -= SectionWriteCheck - SectionLoadCheck;
376379
#endif // defined(_OS_X86_64_)
377380
#endif // defined(_OS_WINDOWS_)
378381

0 commit comments

Comments
 (0)