1

I need to check whether my application is accelerated by running under OpenOnload or not. The restriction is that no Onload specific API can be used - app is not linked with Onload extensions library.

How this can be done?

Rost
  • 8,779
  • 28
  • 50
cassini
  • 85
  • 5

2 Answers2

2

OpenOnload can be detected by pre-loaded shared library presence libonload.so.

In this case your application environment will contain LD_PRELOAD=libonload.so string.

Or you can just enumerate all loaded shared libraries and check for libonload.so.

#include <string>
#include <fstream>
#include <iostream>

// Checks is specific SO loaded in current process.
bool is_so_loaded(const std::string& so_name)
{
    const std::string proc_path = "/proc/self/maps";
    std::ifstream proc(proc_path);

    std::string str;
    while (std::getline(proc, str))
    {
        if (str.find(so_name) != std::string::npos) return true;
    }

    return false;
}

int main()
{
    std::cout
        << "Running with OpenOnload: "
        << (is_so_loaded("/libonload.so") ? "Yes" : "No")
        << std::endl;
    return 0;
}
Rost
  • 8,779
  • 28
  • 50
1

Just search the symbol "onload_is_present" using the default shared object search order and if onload is pre-loaded it will return a valid address.

bool IsOnloadPresent()
{
   void* pIsOnloadPresent = dlsym(RTLD_DEFAULT, "onload_is_present");
   if(pIsOnloadPresent == NULL)
       return false;
   return true;
}
Kethiri Sundar
  • 480
  • 2
  • 12