symbols.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "symbols.h"
  2. #include <util/generic/yexception.h>
  3. #include <util/generic/vector.h>
  4. #include <util/generic/singleton.h>
  5. #include <util/generic/utility.h>
  6. #include <util/system/dynlib.h>
  7. #include <util/string/builder.h>
  8. #include <library/cpp/iterator/zip.h>
  9. #define LOADSYM(name, type) {name = (TId<type>::R*)L->SymOptional(#name);}
  10. const TInfinibandSymbols* IBSym() {
  11. struct TSymbols: TInfinibandSymbols {
  12. TSymbols() {
  13. auto lib = std::make_unique<TDynamicLibrary>();
  14. TVector<TString> catchedExceptions;
  15. TVector<TString> paths = {"/usr/lib/libibverbs.so", "libibverbs.so", "libibverbs.so.1"};
  16. for (auto path : paths) {
  17. try {
  18. lib->Open(path.c_str());
  19. L.Reset(lib.release());
  20. DOVERBS(LOADSYM)
  21. return;
  22. } catch (std::exception& ex) {
  23. catchedExceptions.emplace_back(ex.what());
  24. }
  25. }
  26. Y_ABORT_UNLESS(paths.size() == catchedExceptions.size());
  27. TStringBuilder builder;
  28. builder << "Cannot open any shared library. Reasons:\n";
  29. for (const auto& [reason, path] : Zip(catchedExceptions, paths)) {
  30. builder << "Path: " << path << " Reason: " << reason << "\n";
  31. }
  32. ythrow yexception() << builder;
  33. }
  34. THolder<TDynamicLibrary> L;
  35. };
  36. return SingletonWithPriority<TSymbols, 100>();
  37. }
  38. const TRdmaSymbols* RDSym() {
  39. struct TSymbols: TRdmaSymbols {
  40. TSymbols() {
  41. L.Reset(new TDynamicLibrary("/usr/lib/librdmacm.so"));
  42. DORDMA(LOADSYM)
  43. }
  44. THolder<TDynamicLibrary> L;
  45. };
  46. return SingletonWithPriority<TSymbols, 100>();
  47. }
  48. const TMlx5Symbols* M5Sym() {
  49. struct TSymbols: TMlx5Symbols {
  50. TSymbols() {
  51. L.Reset(new TDynamicLibrary("/usr/lib/libmlx5.so"));
  52. DOMLX5(LOADSYM)
  53. }
  54. THolder<TDynamicLibrary> L;
  55. };
  56. return SingletonWithPriority<TSymbols, 100>();
  57. }
  58. #undef LOADSYM