Skip to content

Commit

Permalink
Check that entry points are recognized by dladdr
Browse files Browse the repository at this point in the history
This is to check if snapshot save will work.
  • Loading branch information
drmeister committed Jul 1, 2024
1 parent bce1c6d commit ffd0a02
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/clasp/core/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,9 @@ namespace core {
typedef gctools::return_type (*bytecode_trampoline_function)(unsigned char* pc, core::T_O* closure, size_t nargs, core::T_O** args);
extern bytecode_trampoline_function bytecode_trampoline;


void maybe_verify_dladdr( core::ClaspXepFunction& entryPoints,
core::T_sp code,
core::FunctionDescription_sp functionDescription,
gctools::GatherObjects* gatherP );
}; // namespace core
3 changes: 2 additions & 1 deletion include/clasp/gctools/memoryManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,8 @@ struct GatherObjects {
std::set<BaseHeader_s*> _Marked;
MarkNode* _Stack;
std::map<BaseHeader_s*, std::vector<uintptr_t>> _corruptObjects;

std::set<void*> _uniqueEntryPoints;
std::set<void*> _uniqueEntryPointsFailedDladdr;
GatherObjects(RoomVerbosity v) : _Verbosity(v), _Stack(NULL){};

MarkNode* popMarkStack() {
Expand Down
24 changes: 24 additions & 0 deletions src/core/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THE SOFTWARE.
// #define DEBUG_LEVEL_FULL
#include <clasp/core/foundation.h>
#include <clasp/gctools/snapshotSaveLoad.h>
#include <clasp/gctools/memoryManagement.h>
#include <clasp/core/lisp.h>
#include <clasp/core/array.h>
#include <clasp/core/symbolTable.h>
Expand Down Expand Up @@ -764,4 +765,27 @@ Function_sp FunctionCell_O::fdefinition() const {
}
}


void maybe_verify_dladdr( core::ClaspXepFunction& entryPoints,
core::T_sp code,
core::FunctionDescription_sp functionDescription,
gctools::GatherObjects* gatherP ) {
if (gc::IsA<llvmo::Library_sp>(code)) {
for (size_t ii = 0; ii < ClaspXepFunction::Entries; ++ii) {
Dl_info info;
void* address = (void*)entryPoints._EntryPoints[ii].load();
if (gatherP->_uniqueEntryPoints.count(address)==0) {
gatherP->_uniqueEntryPoints.insert(address);
int ret = dladdr((void*)address, &info);
if (ret == 0) {
gatherP->_uniqueEntryPointsFailedDladdr.insert(address);
printf("%s:%d:%s During object scan entry point %p could not be resolved using dladdr\n",
__FILE__, __LINE__, __FUNCTION__, (void*)address);
}
}
}
}
}


}; // namespace core
20 changes: 20 additions & 0 deletions src/gctools/boehmGarbageCollection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ THE SOFTWARE.
#include <clasp/gctools/boehmGarbageCollection.h>
#include <clasp/gctools/gcFunctions.h>
#include <clasp/core/debugger.h>
#include <clasp/core/function.h>
#include <clasp/core/compiler.h>
#include <clasp/gctools/snapshotSaveLoad.h>

Expand All @@ -62,6 +63,7 @@ static size_t invalidHeaderTotalSize = 0;

extern "C" {
void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
gctools::GatherObjects* gatherP = (gctools::GatherObjects*)client_data;
gctools::GCStampEnum stamp;
if (ptr->_badge_stamp_wtag_mtag.consObjectP()) {
stamp = (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_CONS);
Expand All @@ -72,6 +74,19 @@ void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
}
}
size_t sz = objectSize(ptr);
if (stamp == (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_core__SimpleFun_O)) {
core::SimpleFun_O* fun = HeaderPtrToGeneralPtr<core::SimpleFun_O>(ptr);
core::maybe_verify_dladdr( fun->_EntryPoints,
fun->_Code,
fun->_FunctionDescription,
gatherP );
} else if (stamp == (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_core__SimpleCoreFun_O)) {
core::SimpleCoreFun_O* fun = HeaderPtrToGeneralPtr<core::SimpleCoreFun_O>(ptr);
core::maybe_verify_dladdr( fun->_EntryPoints,
fun->_Code,
fun->_FunctionDescription,
gatherP );
}
gctools::ReachableClassMap::iterator it = static_ReachableClassKinds->find(stamp);
if (it == static_ReachableClassKinds->end()) {
gctools::ReachableClass reachableClass(stamp);
Expand All @@ -82,6 +97,7 @@ void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
}
#if 0
if (stamp==(gctools::GCStampEnum)(gctools::STAMPWTAG_core__Symbol_O>>gctools::Header_s::wtag_width)) {
#error "ptr is a base pointer - it cant be cast to Symbol_O"
core::Symbol_O* sym = (core::Symbol_O*)ptr;
printf("%s:%d symbol %s\n", __FILE__, __LINE__, sym->formattedName(true).c_str());
}
Expand Down Expand Up @@ -554,6 +570,10 @@ void clasp_gc_room(std::ostringstream& OutputStream, RoomVerbosity verbosity) {
OutputStream << "Total number of Libraries: " << std::setw(12) << cl__length(_lisp->_Roots._AllLibraries) << '\n';
OutputStream << "Total number of ObjectFiles: " << std::setw(12) << cl__length(_lisp->_Roots._AllObjectFiles) << '\n';
OutputStream << "Total number of CodeBlocks: " << std::setw(12) << cl__length(_lisp->_Roots._AllCodeBlocks) << '\n';
OutputStream << "Unique entry points: " << std::setw(12) << gatherObjects._uniqueEntryPoints.size() << '\n';
if (gatherObjects._uniqueEntryPointsFailedDladdr.size()>0) {
OutputStream << "Unique entry points failed dladdr: " << std::setw(12) << gatherObjects._uniqueEntryPointsFailedDladdr.size() << '\n';
}
delete static_ReachableClassKinds;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gctools/snapshotSaveLoad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define DEBUG_LEVEL_FULL

//#define DEBUG_ENTRY_POINTS 1
#define DEBUG_ENTRY_POINTS 1

// #include <llvm/Support/system_error.h>
#include <dlfcn.h>
Expand Down

0 comments on commit ffd0a02

Please sign in to comment.