From 2f1f2f6eb6f4060d2e5125c28014cc7c8dc1f740 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 11 Feb 2022 17:21:17 -0500 Subject: [PATCH 1/3] 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. --- src/cgmemmgr.cpp | 8 +++++--- src/debuginfo.cpp | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index fcaf77ed6e0b9..6a1b0e041b81d 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -64,7 +64,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) @@ -81,7 +82,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) @@ -647,7 +649,7 @@ class DualMapAllocator : public ROAllocator { 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; } } diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 8436e4bcc4103..a5c77de320803 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -124,6 +124,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; @@ -265,20 +267,13 @@ class JITObjectRegistry uint8_t *catchjmp = NULL; for (const object::SymbolRef &sym_iter : Object.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(); - sName = cantFail(Section->getName()); - uint64_t SectionLoadAddr = getLoadAddress(sName); + StringRef secName = cantFail(Section->getName()); + uint64_t SectionLoadAddr = getLoadAddress(secName); assert(SectionLoadAddr); if (SectionAddrCheck) // assert that all of the Sections are at the same location assert(SectionAddrCheck == SectionAddr && @@ -288,8 +283,13 @@ class JITObjectRegistry SectionWriteCheck = SectionLoadAddr; if (lookupWriteAddress) SectionWriteCheck = (uintptr_t)lookupWriteAddress((void*)SectionLoadAddr); - Addr += SectionWriteCheck - SectionLoadAddr; - *pAddr = (uint8_t*)Addr; + Addr += SectionWriteCheck - SectionLoadCheck; + if (sName.equals("__UnwindData")) { + UnwindData = (uint8_t*)Addr; + } + else if (sName.equals("__catchjmp")) { + catchjmp = (uint8_t*)Addr; + } } } assert(catchjmp); @@ -312,6 +312,7 @@ class JITObjectRegistry 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_) From 0c44d238e8abff11916af336c3c3013ca2d5fd3b Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 11 Feb 2022 17:22:19 -0500 Subject: [PATCH 2/3] build,win: workaround for echo sometimes interpreting \\ from tr --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a6a1587bcdc90..6b7504b653871 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ $(BUILDROOT)/doc/_build/html/en/index.html: $(shell find $(BUILDROOT)/base $(BUI julia-symlink: julia-cli-$(JULIA_BUILD_MODE) ifeq ($(OS),WINNT) - @echo '@"%~dp0\'"$$(echo $(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE)) | tr / '\\')"\" '%*' > $(BUILDROOT)/julia.bat + echo '@"%~dp0/'"$$(echo '$(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE))')"'" %*' | tr / '\\' > $(BUILDROOT)/julia.bat chmod a+x $(BUILDROOT)/julia.bat else ifndef JULIA_VAGRANT_BUILD From cac90b570e73e4e2f726b18a18001344b79f8340 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sat, 12 Feb 2022 23:54:48 -0500 Subject: [PATCH 3/3] win,debug: add missing jl_refresh_dbg_module_list call Because we might not have synchronized the list again yet. --- src/debuginfo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index a5c77de320803..de02b06139935 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -1100,6 +1100,7 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip static IMAGEHLP_LINE64 frame_info_line; DWORD dwDisplacement = 0; uv_mutex_lock(&jl_in_stackwalk); + jl_refresh_dbg_module_list(); DWORD64 dwAddress = pointer; frame_info_line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); if (SymGetLineFromAddr64(GetCurrentProcess(), dwAddress, &dwDisplacement, &frame_info_line)) {