Skip to content

Commit 8255502

Browse files
[SYCL] Remove some OSUtil::* funcs from ABI under -fpreview-breaking-changes (#16177)
These are used internally in the DSO and don't need to be exposed outside. `OSUtil::getDirName` will become `static` inside single TU under the `-fpreview-breaking-changes` flag and `private` for the time being without the flag (to make sure no new uses will be added outside the TU). `OSUtil::getCurrentDSODir` is used in several TUs, so simply make it `__SYCL_DLL_LOCAL` to remove from exported symbols during the next ABI-breaking window.
1 parent 86e9ad2 commit 8255502

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

sycl/include/sycl/detail/os_util.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ namespace detail {
4242

4343
/// Groups the OS-dependent services.
4444
class __SYCL_EXPORT OSUtil {
45+
#if !defined(__INTEL_PREVIEW_BREAKING_CHANGES)
46+
#ifdef _WIN32
47+
// Access control is part of the mangling on Windows, have to preserve this
48+
// for backward ABI compatibility.
4549
public:
46-
/// Returns an absolute path to a directory where the object was found.
47-
static std::string getCurrentDSODir();
48-
50+
#endif
4951
/// Returns a directory component of a path.
5052
static std::string getDirName(const char *Path);
53+
#endif
54+
55+
public:
56+
/// Returns an absolute path to a directory where the object was found.
57+
#if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
58+
__SYCL_DLL_LOCAL
59+
#endif
60+
static std::string getCurrentDSODir();
5161

5262
#ifdef __SYCL_RT_OS_WINDOWS
5363
static constexpr const char *DirSep = "\\";

sycl/source/detail/os_util.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
6969
return Addr >= Start && Addr < End;
7070
}
7171

72+
#if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
73+
static std::string getDirName(const char *Path)
74+
#else
75+
std::string OSUtil::getDirName(const char *Path)
76+
#endif
77+
{
78+
std::string Tmp(Path);
79+
// dirname(3) needs a writable C string: a null-terminator is written where a
80+
// path should split.
81+
size_t TruncatedSize = strlen(dirname(const_cast<char *>(Tmp.c_str())));
82+
Tmp.resize(TruncatedSize);
83+
return Tmp;
84+
}
85+
7286
/// Returns an absolute path to a directory where the object was found.
7387
std::string OSUtil::getCurrentDSODir() {
7488
// Examine /proc/self/maps and find where this function (getCurrendDSODir)
@@ -130,21 +144,12 @@ std::string OSUtil::getCurrentDSODir() {
130144
char Path[PATH_MAX];
131145
Stream.getline(Path, PATH_MAX - 1);
132146
Path[PATH_MAX - 1] = '\0';
133-
return OSUtil::getDirName(Path);
147+
return getDirName(Path);
134148
}
135149
assert(false && "Unable to find the current function in /proc/self/maps");
136150
return "";
137151
}
138152

139-
std::string OSUtil::getDirName(const char *Path) {
140-
std::string Tmp(Path);
141-
// dirname(3) needs a writable C string: a null-terminator is written where a
142-
// path should split.
143-
size_t TruncatedSize = strlen(dirname(const_cast<char *>(Tmp.c_str())));
144-
Tmp.resize(TruncatedSize);
145-
return Tmp;
146-
}
147-
148153
#elif defined(__SYCL_RT_OS_WINDOWS)
149154

150155
/// Returns an absolute path where the object was found.
@@ -169,6 +174,7 @@ std::string OSUtil::getCurrentDSODir() {
169174
return Path;
170175
}
171176

177+
#if !defined(__INTEL_PREVIEW_BREAKING_CHANGES)
172178
std::string OSUtil::getDirName(const char *Path) {
173179
std::string Tmp(Path);
174180
// Remove trailing directory separators
@@ -181,6 +187,7 @@ std::string OSUtil::getDirName(const char *Path) {
181187
// If no directory separator is present return initial path like dirname does
182188
return Tmp;
183189
}
190+
#endif
184191

185192
#elif defined(__SYCL_RT_OS_DARWIN)
186193
std::string OSUtil::getCurrentDSODir() {

sycl/source/detail/persistent_device_code_cache.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ namespace sycl {
2424
inline namespace _V1 {
2525
namespace detail {
2626

27-
/* This is temporary solution until std::filesystem is available when SYCL RT
28-
* is moved to c++17 standard*/
29-
std::string getDirName(const char *Path);
30-
3127
/* The class manages inter-process synchronization:
3228
* - Path passed to the constructor is appended with .lock and used as lock
3329
* file.

sycl/tools/sycl-trace/collector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sycl::detail::SpinLock GlobalLock;
1818

1919
bool HasZEPrinter = false;
2020

21-
std::string getCurrentDSODir() {
21+
static std::string getCurrentDSODir() {
2222
auto CurrentFunc = reinterpret_cast<const void *>(&getCurrentDSODir);
2323
Dl_info Info;
2424
int RetCode = dladdr(CurrentFunc, &Info);

sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static OSModuleHandle getOSModuleHandle(const void *VirtAddr) {
6565

6666
// cribbed from sycl/source/detail/os_util.cpp
6767
/// Returns an absolute path where the object was found.
68-
std::wstring getCurrentDSODir() {
68+
static std::wstring getCurrentDSODir() {
6969
wchar_t Path[MAX_PATH];
7070
auto Handle = getOSModuleHandle(reinterpret_cast<void *>(&getCurrentDSODir));
7171
DWORD Ret = GetModuleFileName(

0 commit comments

Comments
 (0)