Closed
Description
A segmentation fault occurs when calling olGetDeviceInfoSize
to retrieve the size of the device name for the host device.
The crash happens specifically when olGetDeviceInfoSize
is called with OL_DEVICE_INFO_NAME
for the host device handle.
Steps to Reproduce:
- Compile the C++ code snippet provided below using Clang and linking against the LLVMOffload library.
$ clang++ -std=c++17 host.cpp -I"$LLVM_HOME/include" -L"$LLVM_HOME/lib" -lLLVMOffload -ldl -lpthread -Wl,-rpath,"$LLVM_HOME/lib" -o host
- Execute the compiled program:
$ ./host
- Observe the output.
Program Output:
Getting the storage size of the device name...
Segmentation fault (core dumped)
Code Snippet:
#include <iostream>
#include <offload/OffloadAPI.h>
#include <string>
ol_device_handle_t getHostDevice() {
static ol_device_handle_t HostDevice = nullptr;
if (!HostDevice) {
olIterateDevices(
[](ol_device_handle_t D, void *Data) {
ol_platform_handle_t Platform;
olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform),
&Platform);
ol_platform_backend_t Backend;
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, sizeof(Backend),
&Backend);
if (Backend == OL_PLATFORM_BACKEND_HOST) {
*(static_cast<ol_device_handle_t *>(Data)) = D;
return false;
}
return true;
},
&HostDevice);
}
return HostDevice;
}
int main() {
olInit();
auto HostDevice = getHostDevice();
if (HostDevice == nullptr) {
std::cout << "Host device not found." << std::endl;
return 1;
}
std::cout << "Getting the storage size of the device name..." << std::endl;
size_t Size = 0;
olGetDeviceInfoSize(HostDevice, OL_DEVICE_INFO_NAME, &Size);
std::cout << "Getting the device name..." << std::endl;
std::string Name(Size, '\0');
olGetDeviceInfo(HostDevice, OL_DEVICE_INFO_NAME, Size, Name.data());
Name.pop_back();
std::cout << "Device name: " << Name << std::endl;
olShutDown();
return 0;
}
Environment:
- LLVM version: Custom build from git
- LLVM Project Commit Hash:
1e4841881ef89aeee77cbf081de42af376bfa3fb
- LLVM Project Commit Hash:
- Operating System: Ubuntu 24.04.2 LTS (WSL2)