Skip to content

[Offload] Segmentation fault when calling olGetDeviceInfoSize for host device name #141434

Closed
@leandrolcampos

Description

@leandrolcampos

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:

  1. 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
  2. Execute the compiled program:
    $ ./host
  3. 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
  • Operating System: Ubuntu 24.04.2 LTS (WSL2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions