Skip to content

Commit ffd0a02

Browse files
committed
Check that entry points are recognized by dladdr
This is to check if snapshot save will work.
1 parent bce1c6d commit ffd0a02

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

include/clasp/core/function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,9 @@ namespace core {
564564
typedef gctools::return_type (*bytecode_trampoline_function)(unsigned char* pc, core::T_O* closure, size_t nargs, core::T_O** args);
565565
extern bytecode_trampoline_function bytecode_trampoline;
566566

567+
568+
void maybe_verify_dladdr( core::ClaspXepFunction& entryPoints,
569+
core::T_sp code,
570+
core::FunctionDescription_sp functionDescription,
571+
gctools::GatherObjects* gatherP );
567572
}; // namespace core

include/clasp/gctools/memoryManagement.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ struct GatherObjects {
13261326
std::set<BaseHeader_s*> _Marked;
13271327
MarkNode* _Stack;
13281328
std::map<BaseHeader_s*, std::vector<uintptr_t>> _corruptObjects;
1329-
1329+
std::set<void*> _uniqueEntryPoints;
1330+
std::set<void*> _uniqueEntryPointsFailedDladdr;
13301331
GatherObjects(RoomVerbosity v) : _Verbosity(v), _Stack(NULL){};
13311332

13321333
MarkNode* popMarkStack() {

src/core/function.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ THE SOFTWARE.
2727
// #define DEBUG_LEVEL_FULL
2828
#include <clasp/core/foundation.h>
2929
#include <clasp/gctools/snapshotSaveLoad.h>
30+
#include <clasp/gctools/memoryManagement.h>
3031
#include <clasp/core/lisp.h>
3132
#include <clasp/core/array.h>
3233
#include <clasp/core/symbolTable.h>
@@ -764,4 +765,27 @@ Function_sp FunctionCell_O::fdefinition() const {
764765
}
765766
}
766767

768+
769+
void maybe_verify_dladdr( core::ClaspXepFunction& entryPoints,
770+
core::T_sp code,
771+
core::FunctionDescription_sp functionDescription,
772+
gctools::GatherObjects* gatherP ) {
773+
if (gc::IsA<llvmo::Library_sp>(code)) {
774+
for (size_t ii = 0; ii < ClaspXepFunction::Entries; ++ii) {
775+
Dl_info info;
776+
void* address = (void*)entryPoints._EntryPoints[ii].load();
777+
if (gatherP->_uniqueEntryPoints.count(address)==0) {
778+
gatherP->_uniqueEntryPoints.insert(address);
779+
int ret = dladdr((void*)address, &info);
780+
if (ret == 0) {
781+
gatherP->_uniqueEntryPointsFailedDladdr.insert(address);
782+
printf("%s:%d:%s During object scan entry point %p could not be resolved using dladdr\n",
783+
__FILE__, __LINE__, __FUNCTION__, (void*)address);
784+
}
785+
}
786+
}
787+
}
788+
}
789+
790+
767791
}; // namespace core

src/gctools/boehmGarbageCollection.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ THE SOFTWARE.
3838
#include <clasp/gctools/boehmGarbageCollection.h>
3939
#include <clasp/gctools/gcFunctions.h>
4040
#include <clasp/core/debugger.h>
41+
#include <clasp/core/function.h>
4142
#include <clasp/core/compiler.h>
4243
#include <clasp/gctools/snapshotSaveLoad.h>
4344

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

6364
extern "C" {
6465
void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
66+
gctools::GatherObjects* gatherP = (gctools::GatherObjects*)client_data;
6567
gctools::GCStampEnum stamp;
6668
if (ptr->_badge_stamp_wtag_mtag.consObjectP()) {
6769
stamp = (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_CONS);
@@ -72,6 +74,19 @@ void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
7274
}
7375
}
7476
size_t sz = objectSize(ptr);
77+
if (stamp == (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_core__SimpleFun_O)) {
78+
core::SimpleFun_O* fun = HeaderPtrToGeneralPtr<core::SimpleFun_O>(ptr);
79+
core::maybe_verify_dladdr( fun->_EntryPoints,
80+
fun->_Code,
81+
fun->_FunctionDescription,
82+
gatherP );
83+
} else if (stamp == (gctools::GCStampEnum)STAMP_UNSHIFT_WTAG(gctools::STAMPWTAG_core__SimpleCoreFun_O)) {
84+
core::SimpleCoreFun_O* fun = HeaderPtrToGeneralPtr<core::SimpleCoreFun_O>(ptr);
85+
core::maybe_verify_dladdr( fun->_EntryPoints,
86+
fun->_Code,
87+
fun->_FunctionDescription,
88+
gatherP );
89+
}
7590
gctools::ReachableClassMap::iterator it = static_ReachableClassKinds->find(stamp);
7691
if (it == static_ReachableClassKinds->end()) {
7792
gctools::ReachableClass reachableClass(stamp);
@@ -82,6 +97,7 @@ void callback_reachable_object(gctools::BaseHeader_s* ptr, void* client_data) {
8297
}
8398
#if 0
8499
if (stamp==(gctools::GCStampEnum)(gctools::STAMPWTAG_core__Symbol_O>>gctools::Header_s::wtag_width)) {
100+
#error "ptr is a base pointer - it cant be cast to Symbol_O"
85101
core::Symbol_O* sym = (core::Symbol_O*)ptr;
86102
printf("%s:%d symbol %s\n", __FILE__, __LINE__, sym->formattedName(true).c_str());
87103
}
@@ -554,6 +570,10 @@ void clasp_gc_room(std::ostringstream& OutputStream, RoomVerbosity verbosity) {
554570
OutputStream << "Total number of Libraries: " << std::setw(12) << cl__length(_lisp->_Roots._AllLibraries) << '\n';
555571
OutputStream << "Total number of ObjectFiles: " << std::setw(12) << cl__length(_lisp->_Roots._AllObjectFiles) << '\n';
556572
OutputStream << "Total number of CodeBlocks: " << std::setw(12) << cl__length(_lisp->_Roots._AllCodeBlocks) << '\n';
573+
OutputStream << "Unique entry points: " << std::setw(12) << gatherObjects._uniqueEntryPoints.size() << '\n';
574+
if (gatherObjects._uniqueEntryPointsFailedDladdr.size()>0) {
575+
OutputStream << "Unique entry points failed dladdr: " << std::setw(12) << gatherObjects._uniqueEntryPointsFailedDladdr.size() << '\n';
576+
}
557577
delete static_ReachableClassKinds;
558578
}
559579

src/gctools/snapshotSaveLoad.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#define DEBUG_LEVEL_FULL
77

8-
//#define DEBUG_ENTRY_POINTS 1
8+
#define DEBUG_ENTRY_POINTS 1
99

1010
// #include <llvm/Support/system_error.h>
1111
#include <dlfcn.h>

0 commit comments

Comments
 (0)