1717
1818#include < llvm/IR/Module.h>
1919
20- #include < filesystem>
21-
2220#ifdef _GNU_SOURCE
2321#include < dlfcn.h>
24-
25- static char X;
26- static std::string getLoadedLibraryPath () {
27- Dl_info Info;
28- if (dladdr (&X, &Info)) {
29- return Info.dli_fname ;
30- }
31- return {};
32- }
22+ static char X; // Dummy symbol, used as an anchor for `dlinfo` below.
3323#endif // _GNU_SOURCE
3424
3525static constexpr auto InvalidDPCPPRoot = " <invalid>" ;
36- static constexpr auto JITLibraryName = " libsycl-jit.so" ;
26+ static constexpr auto JITLibraryPathSuffix = " /lib/ libsycl-jit.so" ;
3727
3828static const std::string &getDPCPPRoot () {
3929 thread_local std::string DPCPPRoot;
@@ -44,13 +34,12 @@ static const std::string &getDPCPPRoot() {
4434 DPCPPRoot = InvalidDPCPPRoot;
4535
4636#ifdef _GNU_SOURCE
47- std::filesystem::path LoadedLibraryPath = getLoadedLibraryPath ();
48- if (!LoadedLibraryPath.empty () && LoadedLibraryPath.is_absolute () &&
49- LoadedLibraryPath.filename () == JITLibraryName &&
50- LoadedLibraryPath.has_parent_path ()) {
51- if (auto LibDirectoryPath = LoadedLibraryPath.parent_path ();
52- LibDirectoryPath.filename () == " lib" ) {
53- DPCPPRoot = LibDirectoryPath.parent_path ();
37+ Dl_info Info;
38+ if (dladdr (&X, &Info)) {
39+ std::string LoadedLibraryPath = Info.dli_fname ;
40+ auto Pos = LoadedLibraryPath.rfind (JITLibraryPathSuffix);
41+ if (Pos != std::string::npos) {
42+ DPCPPRoot = LoadedLibraryPath.substr (0 , Pos);
5443 }
5544 }
5645#endif // _GNU_SOURCE
0 commit comments