@@ -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