@@ -223,11 +223,21 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
223223#endif
224224
225225void JITDebugInfoRegistry::registerJITObject (const object::ObjectFile &Object,
226- std::function<uint64_t (const StringRef &)> getLoadAddress,
227- std::function<void*(void *)> lookupWriteAddress)
226+ std::function<uint64_t (const StringRef &)> getLoadAddress)
228227{
229228 object::section_iterator EndSection = Object.section_end ();
230229
230+ bool anyfunctions = false ;
231+ for (const object::SymbolRef &sym_iter : Object.symbols ()) {
232+ object::SymbolRef::Type SymbolType = cantFail (sym_iter.getType ());
233+ if (SymbolType != object::SymbolRef::ST_Function)
234+ continue ;
235+ anyfunctions = true ;
236+ break ;
237+ }
238+ if (!anyfunctions)
239+ return ;
240+
231241#ifdef _CPU_ARM_
232242 // ARM does not have/use .eh_frame
233243 uint64_t arm_exidx_addr = 0 ;
@@ -281,14 +291,13 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
281291#if defined(_OS_WINDOWS_)
282292 uint64_t SectionAddrCheck = 0 ;
283293 uint64_t SectionLoadCheck = 0 ; (void )SectionLoadCheck;
284- uint64_t SectionWriteCheck = 0 ; (void )SectionWriteCheck;
285294 uint8_t *UnwindData = NULL ;
286295#if defined(_CPU_X86_64_)
287296 uint8_t *catchjmp = NULL ;
288297 for (const object::SymbolRef &sym_iter : Object.symbols ()) {
289298 StringRef sName = cantFail (sym_iter.getName ());
290299 if (sName .equals (" __UnwindData" ) || sName .equals (" __catchjmp" )) {
291- uint64_t Addr = cantFail (sym_iter.getAddress ());
300+ uint64_t Addr = cantFail (sym_iter.getAddress ()); // offset into object (including section offset)
292301 auto Section = cantFail (sym_iter.getSection ());
293302 assert (Section != EndSection && Section->isText ());
294303 uint64_t SectionAddr = Section->getAddress ();
@@ -300,10 +309,7 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
300309 SectionLoadCheck == SectionLoadAddr);
301310 SectionAddrCheck = SectionAddr;
302311 SectionLoadCheck = SectionLoadAddr;
303- SectionWriteCheck = SectionLoadAddr;
304- if (lookupWriteAddress)
305- SectionWriteCheck = (uintptr_t )lookupWriteAddress ((void *)SectionLoadAddr);
306- Addr += SectionWriteCheck - SectionLoadCheck;
312+ Addr += SectionLoadAddr - SectionAddr;
307313 if (sName .equals (" __UnwindData" )) {
308314 UnwindData = (uint8_t *)Addr;
309315 }
@@ -314,25 +320,7 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
314320 }
315321 assert (catchjmp);
316322 assert (UnwindData);
317- assert (SectionAddrCheck);
318323 assert (SectionLoadCheck);
319- assert (!memcmp (catchjmp, " \0\0\0\0\0\0\0\0\0\0\0\0 " , 12 ) &&
320- !memcmp (UnwindData, " \0\0\0\0\0\0\0\0\0\0\0\0 " , 12 ));
321- catchjmp[0 ] = 0x48 ;
322- catchjmp[1 ] = 0xb8 ; // mov RAX, QWORD PTR [&__julia_personality]
323- *(uint64_t *)(&catchjmp[2 ]) = (uint64_t )&__julia_personality;
324- catchjmp[10 ] = 0xff ;
325- catchjmp[11 ] = 0xe0 ; // jmp RAX
326- UnwindData[0 ] = 0x09 ; // version info, UNW_FLAG_EHANDLER
327- UnwindData[1 ] = 4 ; // size of prolog (bytes)
328- UnwindData[2 ] = 2 ; // count of unwind codes (slots)
329- UnwindData[3 ] = 0x05 ; // frame register (rbp) = rsp
330- UnwindData[4 ] = 4 ; // second instruction
331- UnwindData[5 ] = 0x03 ; // mov RBP, RSP
332- UnwindData[6 ] = 1 ; // first instruction
333- UnwindData[7 ] = 0x50 ; // push RBP
334- *(DWORD*)&UnwindData[8 ] = (DWORD)(catchjmp - (uint8_t *)SectionWriteCheck); // relative location of catchjmp
335- UnwindData -= SectionWriteCheck - SectionLoadCheck;
336324#endif // defined(_OS_X86_64_)
337325#endif // defined(_OS_WINDOWS_)
338326
@@ -353,7 +341,7 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
353341 uint64_t SectionAddr = Section->getAddress ();
354342 StringRef secName = cantFail (Section->getName ());
355343 uint64_t SectionLoadAddr = getLoadAddress (secName);
356- Addr -= SectionAddr - SectionLoadAddr ;
344+ Addr += SectionLoadAddr - SectionAddr ;
357345 StringRef sName = cantFail (sym_iter.getName ());
358346 uint64_t SectionSize = Section->getSize ();
359347 size_t Size = sym_size.second ;
@@ -404,10 +392,9 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
404392}
405393
406394void jl_register_jit_object (const object::ObjectFile &Object,
407- std::function<uint64_t (const StringRef &)> getLoadAddress,
408- std::function<void *(void *)> lookupWriteAddress)
395+ std::function<uint64_t (const StringRef &)> getLoadAddress)
409396{
410- getJITDebugRegistry ().registerJITObject (Object, getLoadAddress, lookupWriteAddress );
397+ getJITDebugRegistry ().registerJITObject (Object, getLoadAddress);
411398}
412399
413400// TODO: convert the safe names from aotcomile.cpp:makeSafeName back into symbols
0 commit comments