diff --git a/include/clasp/gctools/snapshotSaveLoad.h b/include/clasp/gctools/snapshotSaveLoad.h index 1ee28beee5..12a8c4e291 100644 --- a/include/clasp/gctools/snapshotSaveLoad.h +++ b/include/clasp/gctools/snapshotSaveLoad.h @@ -14,7 +14,7 @@ namespace snapshotSaveLoad { extern bool global_debugSnapshot; extern bool global_InSnapshotLoad; -enum PointerType { UninitializedPointer = 0, EndPointer = 1, FunctionPointer = 2, VtablePointer = 3 }; +enum PointerType { UninitializedPointer = '?', EndPointer = 'E', FunctionPointer = 'f', VtablePointer = 'v' }; struct PointerBase { PointerType _pointerType; @@ -83,19 +83,9 @@ struct Fixup { uintptr_t fixedAddress(bool functionP, uintptr_t* ptrptr, const char* addressName); size_t ensureLibraryRegistered(uintptr_t address); - void registerVtablePointer(size_t libraryIndex, core::T_O* vtablePtrPtr) { - this->_Libraries[libraryIndex]._InternalPointers.emplace_back(VtablePointer, (uintptr_t*)vtablePtrPtr, - *(uintptr_t*)vtablePtrPtr); - }; + void registerVtablePointer(size_t libraryIndex, core::T_O* vtablePtrPtr); - void registerFunctionPointer(size_t libraryIndex, uintptr_t* functionPtrPtr) { - if (libraryIndex > LIBRARY_ID_MAX) { - printf("%s:%d:%s The library id %lu is too large - change the pointer coding scheme to add more bits to the library id\n", - __FILE__, __LINE__, __FUNCTION__, libraryIndex); - abort(); - } - this->_Libraries[libraryIndex]._InternalPointers.emplace_back(FunctionPointer, (uintptr_t*)functionPtrPtr, *functionPtrPtr); - }; + void registerFunctionPointer(size_t libraryIndex, uintptr_t* functionPtrPtr, const char* location); void addAddressName(void* address, std::string name) { if (this->_trackAddressName) { @@ -125,7 +115,7 @@ void clearLibraries(); void encodeEntryPointInLibrary(Fixup* fixup, uintptr_t* ptrptr); void decodeEntryPointInLibrary(Fixup* fixup, uintptr_t* ptrptr); -void encodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp code); +void encodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp code, core::FunctionDescription_sp functionDescription ); void decodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp code); struct LibraryLookup { diff --git a/src/core/function.cc b/src/core/function.cc index c57cf1ac00..360650771d 100644 --- a/src/core/function.cc +++ b/src/core/function.cc @@ -62,7 +62,7 @@ void SimpleFun_O::fixupOneCodePointer(snapshotSaveLoad::Fixup* fixup, void** ptr } } else if (snapshotSaveLoad::operation(fixup) == snapshotSaveLoad::SaveOp) { uintptr_t* ptrptr = (uintptr_t*)&ptr[0]; - snapshotSaveLoad::encodeEntryPoint(fixup, ptrptr, this->_Code); + snapshotSaveLoad::encodeEntryPoint(fixup, ptrptr, this->_Code, this->_FunctionDescription ); } else if (snapshotSaveLoad::operation(fixup) == snapshotSaveLoad::LoadOp) { uintptr_t* ptrptr = (uintptr_t*)&ptr[0]; snapshotSaveLoad::decodeEntryPoint(fixup, ptrptr, this->_Code); @@ -184,7 +184,7 @@ void CoreFun_O::fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup* fixup abort(); } uintptr_t* ptrptr = (uintptr_t*)&ptr[0]; - snapshotSaveLoad::encodeEntryPoint(fixup, ptrptr, this->_Code); + snapshotSaveLoad::encodeEntryPoint(fixup, ptrptr, this->_Code, this->_FunctionDescription ); } else if (snapshotSaveLoad::operation(fixup) == snapshotSaveLoad::LoadOp) { uintptr_t* ptrptr = (uintptr_t*)&ptr[0]; snapshotSaveLoad::decodeEntryPoint(fixup, ptrptr, this->_Code); diff --git a/src/gctools/snapshotSaveLoad.cc b/src/gctools/snapshotSaveLoad.cc index ebaf775c2e..1d34d71b0d 100644 --- a/src/gctools/snapshotSaveLoad.cc +++ b/src/gctools/snapshotSaveLoad.cc @@ -5,6 +5,8 @@ #define DEBUG_LEVEL_FULL +//#define DEBUG_ENTRY_POINTS 1 + // #include #include #include @@ -592,6 +594,30 @@ bool virtualMethodP(uintptr_t* ptrptr) { return false; } + +void Fixup::registerVtablePointer(size_t libraryIndex, core::T_O* vtablePtrPtr) { + this->_Libraries[libraryIndex]._InternalPointers.emplace_back(VtablePointer, (uintptr_t*)vtablePtrPtr, + *(uintptr_t*)vtablePtrPtr); +}; + +void Fixup::registerFunctionPointer(size_t libraryIndex, uintptr_t* functionPtrPtr, const char* location) { + if (libraryIndex > LIBRARY_ID_MAX) { + printf("%s:%d:%s The library id %lu is too large - change the pointer coding scheme to add more bits to the library id\n", + __FILE__, __LINE__, __FUNCTION__, libraryIndex); + abort(); + } + this->_Libraries[libraryIndex]._InternalPointers.emplace_back(FunctionPointer, (uintptr_t*)functionPtrPtr, *functionPtrPtr); +#ifdef DEBUG_ENTRY_POINTS + printf("%s:%d:%s libraryIndex[%lu] functionPtrPtr @%p -> %p location: %s\n", + __FILE__, __LINE__, __FUNCTION__, + libraryIndex, + (void*)functionPtrPtr, + (void*)*functionPtrPtr, + location); +#endif +}; + + uintptr_t Fixup::fixedAddress(bool functionP, uintptr_t* ptrptr, const char* addressName) { uint8_t firstByte; uintptr_t libidx; @@ -714,9 +740,9 @@ uintptr_t encodeEntryPointOffset(uintptr_t address, uintptr_t codeStart, uintptr return offset; } -void encodeEntryPointInLibrary(Fixup* fixup, uintptr_t* ptrptr) { +void encodeEntryPointInLibrary(Fixup* fixup, uintptr_t* ptrptr, const char* location) { size_t libraryIndex = fixup->ensureLibraryRegistered(*ptrptr); - fixup->registerFunctionPointer(libraryIndex, ptrptr); + fixup->registerFunctionPointer(libraryIndex, ptrptr, location); } void decodeEntryPointInLibrary(Fixup* fixup, uintptr_t* ptrptr) { @@ -770,7 +796,7 @@ bool decodeEntryPointForCompiledCode(Fixup* fixup, uintptr_t* ptrptr, llvmo::Obj return true; } -void encodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp codebase) { +void encodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp codebase, core::FunctionDescription_sp functionDescription ) { if (virtualMethodP(ptrptr)) return; if (gc::IsA(codebase)) { @@ -778,12 +804,17 @@ void encodeEntryPoint(Fixup* fixup, uintptr_t* ptrptr, core::T_sp codebase) { if (!encodeEntryPointForCompiledCode(fixup, ptrptr, code)) { // The entry point wasnt into the compiled code // so it must be to one of the libraries - apply that fixup. - encodeEntryPointInLibrary(fixup, ptrptr); + encodeEntryPointInLibrary(fixup, ptrptr,"ObjectFile"); } } else if (gc::IsA(codebase)) { - encodeEntryPointInLibrary(fixup, ptrptr); + encodeEntryPointInLibrary(fixup, ptrptr, "Library"); +#ifdef DEBUG_ENTRY_POINTS + llvmo::Library_sp lib = gc::As(codebase); + printf("%s:%d:%s entryPoint library -> %s\n", __FILE__, __LINE__, __FUNCTION__, lib->_Name->get_std_string().c_str() ); + printf(" function name -> %s\n", _rep_(functionDescription->_functionName).c_str() ); +#endif } else if (gc::IsA(codebase)) { - encodeEntryPointInLibrary(fixup, ptrptr); + encodeEntryPointInLibrary(fixup, ptrptr,"BytecodeModule"); } else { printf("%s:%d:%s The codebase must be a Code_sp or a Library_sp it is %s\n", __FILE__, __LINE__, __FUNCTION__, _rep_(codebase).c_str()); @@ -1512,7 +1543,7 @@ struct prepare_for_snapshot_save_t : public walker_callback_t { // printf("%s:%d:%s [%lu] before target: %lu cast_function@%p: %p\n", __FILE__, __LINE__, __FUNCTION__, ii, // (*edges)[ii].target, &(*edges)[ii].cast, (*edges)[ii].cast); void** ptrptr = (void**)&(*edges)[ii].cast; - encodeEntryPointInLibrary(this->_fixup, (uintptr_t*)ptrptr); + encodeEntryPointInLibrary(this->_fixup, (uintptr_t*)ptrptr,"prepare_for_snapshot_save_t"); } } // Handle them on a case by case basis @@ -2054,7 +2085,7 @@ struct LoadSymbolCallback : public core::SymbolCallback { const char* myName = (const char*)&this->_Library._SymbolBuffer[offset]; if ((namelen == this->_Library._SymbolInfo[ii]._SymbolLength) && (strcmp(name, myName) == 0)) { this->_Library._GroupedPointers[gpindex]._address = start; -#if 0 +#ifdef DEBUG_ENTRY_POINTS printf("%s:%d:%s GroupedPointers[%lu] saved address %p symbol address %p @%p\n name: %s\n", __FILE__, __LINE__, __FUNCTION__, gpindex, @@ -2116,12 +2147,12 @@ struct LoadSymbolCallback : public core::SymbolCallback { } #endif this->_Library._GroupedPointers[gpindex]._address = mysymStart; -#if 0 +#ifdef DEBUG_ENTRY_POINTS printf("%s:%d:%s GroupedPointers[%lu] restored address %p offset: %lu saved symbol address %p @%p\n name: %s\n", __FILE__, __LINE__, __FUNCTION__, gpindex, (void*)dlsymStart, - this->_Library._SymbolInfo[ii]._AddressOffset, + (uintptr_t)this->_Library._SymbolInfo[ii]._AddressOffset, (void*)this->_Library._SymbolInfo[ii]._Address, (void*)&this->_Library._SymbolInfo[ii]._Address, myName); @@ -2160,6 +2191,12 @@ void prepareRelocationTableForSave(Fixup* fixup, SymbolLookup& symbolLookup) { groupPointerIdx = curLib._GroupedPointers.size(); uniques[curLib._InternalPointers[ii]._address] = groupPointerIdx; curLib._GroupedPointers.emplace_back(curLib._InternalPointers[ii]._pointerType, curLib._InternalPointers[ii]._address); +#ifdef DEBUG_ENTRY_POINTS + printf("%s:%d:%s emplace_back into GroupPointers[%lu] -> type: %c @%p\n", __FILE__, __LINE__, __FUNCTION__, + curLib._GroupedPointers.size(), + curLib._InternalPointers[ii]._pointerType, + (void*)curLib._InternalPointers[ii]._address ); +#endif } else { groupPointerIdx = it->second; }