Skip to content

Commit 66f4c75

Browse files
Adding DisableDeepBind debug flag
Related-To: NEO-4946 Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent c686fb2 commit 66f4c75

File tree

14 files changed

+96
-8
lines changed

14 files changed

+96
-8
lines changed

opencl/test/unit_test/offline_compiler/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ if(WIN32)
7777
else()
7878
list(APPEND IGDRCL_SRCS_offline_compiler_tests
7979
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_thread_linux.cpp
80+
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
81+
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
8082
)
8183
endif()
8284

opencl/test/unit_test/offline_compiler/segfault_test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2018-2020 Intel Corporation
2+
# Copyright (C) 2018-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -27,6 +27,8 @@ else()
2727
${CMAKE_CURRENT_SOURCE_DIR}/linux/safety_guard_caller_linux.cpp
2828
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
2929
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
30+
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
31+
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
3032
)
3133
endif()
3234

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "shared/source/os_interface/linux/os_library_linux.h"
9+
#include "shared/source/os_interface/linux/sys_calls.h"
10+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
11+
#include "shared/test/common/helpers/variable_backup.h"
912

1013
#include "gtest/gtest.h"
1114

15+
#include <dlfcn.h>
16+
1217
namespace NEO {
1318

19+
namespace SysCalls {
20+
21+
extern int dlOpenFlags;
22+
extern bool dlOpenCalled;
23+
} // namespace SysCalls
24+
1425
TEST(OsLibraryTest, WhenCreatingFullSystemPathThenProperPathIsConstructed) {
1526
auto fullPath = OsLibrary::createFullSystemPath("test");
1627
EXPECT_STREQ("test", fullPath.c_str());
1728
}
1829

30+
TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFlagIsNotPassed) {
31+
32+
DebugManagerStateRestore restorer;
33+
VariableBackup<int> dlOpenFlagsBackup{&NEO::SysCalls::dlOpenFlags, 0};
34+
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
35+
36+
DebugManager.flags.DisableDeepBind.set(1);
37+
auto lib = std::make_unique<Linux::OsLibrary>("abc");
38+
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
39+
EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND);
40+
}
41+
1942
} // namespace NEO

opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstdint>
1414
#include <cstdio>
1515
#include <cstring>
16+
#include <dlfcn.h>
1617
#include <iostream>
1718
#include <stdio.h>
1819
#include <string.h>
@@ -23,6 +24,8 @@ namespace NEO {
2324
namespace SysCalls {
2425
uint32_t closeFuncCalled = 0u;
2526
int closeFuncArgPassed = 0;
27+
int dlOpenFlags = 0;
28+
bool dlOpenCalled = 0;
2629
constexpr int fakeFileDescriptor = 123;
2730
uint32_t vmId = 0;
2831
bool makeFakeDevicePath = false;
@@ -43,6 +46,13 @@ int open(const char *file, int flags) {
4346
}
4447
return 0;
4548
}
49+
50+
void *dlopen(const char *filename, int flag) {
51+
dlOpenFlags = flag;
52+
dlOpenCalled = true;
53+
return ::dlopen(filename, flag);
54+
}
55+
4656
int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
4757
if (fileDescriptor == fakeFileDescriptor) {
4858
if (request == DRM_IOCTL_VERSION) {

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,4 @@ ForceBtpPrefetchMode = -1
214214
OverrideProfilingTimerResolution = -1
215215
PreferCopyEngineForCopyBufferToBuffer = -1
216216
EnableStaticPartitioning = -1
217+
DisableDeepBind = 0

shared/offline_compiler/source/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ else()
8383
list(APPEND CLOC_LIB_SRCS_LIB
8484
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.cpp
8585
${NEO_SHARED_DIRECTORY}/os_interface/linux/os_library_linux.h
86+
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
8687
${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp
88+
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
8789
)
8890
endif()
8991

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/linux/os_library_linux.h"
9+
10+
namespace NEO {
11+
namespace Linux {
12+
void adjustLibraryFlags(int &dlopenFlag) {
13+
}
14+
} // namespace Linux
15+
} // namespace NEO

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,4 @@ DECLARE_DEBUG_VARIABLE(bool, ReturnRawGpuTimestamps, false, "Driver returns raw
230230
DECLARE_DEBUG_VARIABLE(bool, ForcePerDssBackedBufferProgramming, false, "Always program per-DSS memory backed buffer in preamble")
231231
DECLARE_DEBUG_VARIABLE(bool, DisableAtomicForPostSyncs, false, "When enabled, post syncs are not tracked with atomics")
232232
DECLARE_DEBUG_VARIABLE(bool, UseCommandBufferHeaderSizeForWddmQueueSubmission, true, "0: Page size (4096), 1: sizeof(COMMAND_BUFFER_HEADER)")
233+
DECLARE_DEBUG_VARIABLE(bool, DisableDeepBind, false, "Disable passing RTLD_DEEPBIND flag to all dlopen calls.")

shared/source/os_interface/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
4747
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h
4848
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp
4949
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h
50+
${CMAKE_CURRENT_SOURCE_DIR}/os_library_helper.cpp
5051
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.cpp
5152
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.h
5253
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/debug_settings/debug_settings_manager.h"
9+
#include "shared/source/os_interface/linux/os_library_linux.h"
10+
11+
#include <dlfcn.h>
12+
13+
namespace NEO {
14+
namespace Linux {
15+
void adjustLibraryFlags(int &dlopenFlag) {
16+
if (DebugManager.flags.DisableDeepBind.get()) {
17+
dlopenFlag &= ~RTLD_DEEPBIND;
18+
}
19+
}
20+
} // namespace Linux
21+
} // namespace NEO

shared/source/os_interface/linux/os_library_linux.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -8,6 +8,7 @@
88
#include "shared/source/os_interface/linux/os_library_linux.h"
99

1010
#include "shared/source/helpers/debug_helpers.h"
11+
#include "shared/source/os_interface/linux/sys_calls.h"
1112

1213
#include <dlfcn.h>
1314

@@ -32,15 +33,16 @@ namespace Linux {
3233

3334
OsLibrary::OsLibrary(const std::string &name) {
3435
if (name.empty()) {
35-
this->handle = dlopen(0, RTLD_LAZY);
36+
this->handle = SysCalls::dlopen(0, RTLD_LAZY);
3637
} else {
3738
#ifdef SANITIZER_BUILD
38-
constexpr auto dlopenFlag = RTLD_LAZY;
39+
auto dlopenFlag = RTLD_LAZY;
3940
#else
40-
constexpr auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
41+
auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
4142
/* Background: https://github.com/intel/compute-runtime/issues/122 */
4243
#endif
43-
this->handle = dlopen(name.c_str(), dlopenFlag);
44+
adjustLibraryFlags(dlopenFlag);
45+
this->handle = SysCalls::dlopen(name.c_str(), dlopenFlag);
4446
}
4547
}
4648

shared/source/os_interface/linux/os_library_linux.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -11,6 +11,8 @@
1111
namespace NEO {
1212
namespace Linux {
1313

14+
void adjustLibraryFlags(int &dlopenFlag);
15+
1416
class OsLibrary : public NEO::OsLibrary {
1517
private:
1618
void *handle;

shared/source/os_interface/linux/sys_calls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace NEO {
1313
namespace SysCalls {
1414
int close(int fileDescriptor);
1515
int open(const char *file, int flags);
16+
void *dlopen(const char *filename, int flag);
1617
int ioctl(int fileDescriptor, unsigned long int request, void *arg);
1718
int getDevicePath(int deviceFd, char *buf, size_t &bufSize);
1819
int access(const char *pathname, int mode);

shared/source/os_interface/linux/sys_calls_linux.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "shared/source/os_interface/linux/sys_calls.h"
99

10+
#include <dlfcn.h>
1011
#include <fcntl.h>
1112
#include <iostream>
1213
#include <stdio.h>
@@ -27,6 +28,10 @@ int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
2728
return ::ioctl(fileDescriptor, request, arg);
2829
}
2930

31+
void *dlopen(const char *filename, int flag) {
32+
return ::dlopen(filename, flag);
33+
}
34+
3035
int access(const char *pathName, int mode) {
3136
return ::access(pathName, mode);
3237
}

0 commit comments

Comments
 (0)