Skip to content

Commit 3c52e71

Browse files
authored
Merge pull request #44134 from JuliaLang/jn/win64-UnwindData
debuginfo: fix offset to UnwindData on Win64
2 parents 6e18a14 + cac90b5 commit 3c52e71

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ $(BUILDROOT)/doc/_build/html/en/index.html: $(shell find $(BUILDROOT)/base $(BUI
4848

4949
julia-symlink: julia-cli-$(JULIA_BUILD_MODE)
5050
ifeq ($(OS),WINNT)
51-
@echo '@"%~dp0\'"$$(echo $(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE)) | tr / '\\')"\" '%*' > $(BUILDROOT)/julia.bat
51+
echo '@"%~dp0/'"$$(echo '$(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE))')"'" %*' | tr / '\\' > $(BUILDROOT)/julia.bat
5252
chmod a+x $(BUILDROOT)/julia.bat
5353
else
5454
ifndef JULIA_VAGRANT_BUILD

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)
@@ -647,7 +649,7 @@ class DualMapAllocator : public ROAllocator<exec> {
647649
unmap_page((void*)block.wr_ptr, block.total);
648650
}
649651
else {
650-
protect_page((void*)block.wr_ptr, block.total, Prot::RO);
652+
protect_page((void*)block.wr_ptr, block.total, Prot::NO);
651653
block.state = SplitPtrBlock::WRInit;
652654
}
653655
}

src/debuginfo.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
124124
tbl->BeginAddress = (DWORD)(Code - Section);
125125
tbl->EndAddress = (DWORD)(Code - Section + Size);
126126
tbl->UnwindData = (DWORD)(UnwindData - Section);
127+
assert(Code >= Section && Code + Size <= Section + Allocated);
128+
assert(UnwindData >= Section && UnwindData <= Section + Allocated);
127129
#else // defined(_CPU_X86_64_)
128130
Section += (uintptr_t)Code;
129131
mod_size = Size;
@@ -265,20 +267,13 @@ class JITObjectRegistry
265267
uint8_t *catchjmp = NULL;
266268
for (const object::SymbolRef &sym_iter : Object.symbols()) {
267269
StringRef sName = cantFail(sym_iter.getName());
268-
uint8_t **pAddr = NULL;
269-
if (sName.equals("__UnwindData")) {
270-
pAddr = &UnwindData;
271-
}
272-
else if (sName.equals("__catchjmp")) {
273-
pAddr = &catchjmp;
274-
}
275-
if (pAddr) {
270+
if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) {
276271
uint64_t Addr = cantFail(sym_iter.getAddress());
277272
auto Section = cantFail(sym_iter.getSection());
278273
assert(Section != EndSection && Section->isText());
279274
uint64_t SectionAddr = Section->getAddress();
280-
sName = cantFail(Section->getName());
281-
uint64_t SectionLoadAddr = getLoadAddress(sName);
275+
StringRef secName = cantFail(Section->getName());
276+
uint64_t SectionLoadAddr = getLoadAddress(secName);
282277
assert(SectionLoadAddr);
283278
if (SectionAddrCheck) // assert that all of the Sections are at the same location
284279
assert(SectionAddrCheck == SectionAddr &&
@@ -288,8 +283,13 @@ class JITObjectRegistry
288283
SectionWriteCheck = SectionLoadAddr;
289284
if (lookupWriteAddress)
290285
SectionWriteCheck = (uintptr_t)lookupWriteAddress((void*)SectionLoadAddr);
291-
Addr += SectionWriteCheck - SectionLoadAddr;
292-
*pAddr = (uint8_t*)Addr;
286+
Addr += SectionWriteCheck - SectionLoadCheck;
287+
if (sName.equals("__UnwindData")) {
288+
UnwindData = (uint8_t*)Addr;
289+
}
290+
else if (sName.equals("__catchjmp")) {
291+
catchjmp = (uint8_t*)Addr;
292+
}
293293
}
294294
}
295295
assert(catchjmp);
@@ -312,6 +312,7 @@ class JITObjectRegistry
312312
UnwindData[6] = 1; // first instruction
313313
UnwindData[7] = 0x50; // push RBP
314314
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
315+
UnwindData -= SectionWriteCheck - SectionLoadCheck;
315316
#endif // defined(_OS_X86_64_)
316317
#endif // defined(_OS_WINDOWS_)
317318

@@ -1099,6 +1100,7 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
10991100
static IMAGEHLP_LINE64 frame_info_line;
11001101
DWORD dwDisplacement = 0;
11011102
uv_mutex_lock(&jl_in_stackwalk);
1103+
jl_refresh_dbg_module_list();
11021104
DWORD64 dwAddress = pointer;
11031105
frame_info_line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
11041106
if (SymGetLineFromAddr64(GetCurrentProcess(), dwAddress, &dwDisplacement, &frame_info_line)) {

0 commit comments

Comments
 (0)