Marc BARBIER
Marc BARBIER

Reputation: 1

Running a dlsym function with high risk of segfault

Hi im trying to open libraries (openMPI & IntelMPI) (.so) files to list all of thoses present in my system and get their version.

so i made some code to list of versions of openMPI and IntelMPI present on my system. the thing is that for IntelMPI 2018 calling MPI_Init will cause a segfault most likely it's because it's the version for C++.

on versions that segfaults on MPI_Init i can usually call MPI_Get_version without getting a segfault. On version that doesn't calling MPI_Get_version will get me an error that stop the execution of my program.

is there a way to run a function created by dlsym and catch the segfault thrown by MPI_Init or to prevent MPI_Get_version from stopping the process?

here is a snipped of my code loading the library.

    this->opened_dll = dlopen(path.string().c_str(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND );
    if(this->opened_dll == nullptr) {
        throw std::exception();
    }

    this->dll_MPI_Get_library_version = reinterpret_cast<MPI_Get_library_version>(dlsym(this->opened_dll, "MPI_Get_library_version"));
    this->dll_MPI_Get_version = reinterpret_cast<MPI_Get_version>(dlsym(this->opened_dll, "MPI_Get_version"));
    reinterpret_cast<MPI_Init>(dlsym(this->opened_dll, "MPI_Init"))(nullptr, nullptr);

when MPI_Init cause a segfault it's handle isn't null. i should check all return values but for now i just wanted to see if it's possible at all. my debugger tells me none of these values are at nullptr so that's that.

try/catching as expected does nothing since it's c code and exceptions doesn't exists in c.

i might try forking my process so i only crash the fork by that will force me to have communication to get the valid values back.

Upvotes: 0

Views: 99

Answers (0)

Related Questions