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