oneapi-src / oneapi-src/unified-runtime

"platform" CTS tests cause bizzare linker behaviour with `libze_loader.so` when linked with `-flto`

Open
#2,105 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
57
Forks
120
Avg merge
1d 14h
Merged PRs (30d)
1

Description

Reproduction:
Add the following to /build/_deps/level-zero-loader-src/source/lib/ze_lib.cpp:

__attribute__((destructor)) void print_dtored() {
    std::cout << "ze_lib has been dtored.\n";
};
__attribute__((constructor)) void print_ctored() {
    std::cout << "ze_lib has been ctored.\n";
};

This will print when libze_loader has been opened and closed.

Build, and run bin/test-platform. Note that print_ctored is printed once at the start of testing, and print_dtored is printed once at the end of testing.

If you set -flto on the ze_loader target (for example, via target_compile_options(ze_loader PRIVATE -flto) just after add_ur_adapter(ur_adapter_level_zero ...)), and rerun the tests, you will note that print_dtored at the end of the first test.

What happens next depends on a number of factors:

  • If LD_LIBRARY_PATH is not set, then the program will search for a libze_loader.so in the system path, possibly ending up with /lib/x86_64-linux-gnu/libze_loader.so.1. Since this is different to build/lib/libze_loader.so, they don't have access to the same global state, and problems happen.
  • If LD_LIBRARY_PATH is set to build/lib and the printing code is present, it segfaults trying to write to stdout.
  • If LD_LIBRARY_PATH is set to build/lib and the printing code is removed, the test passes. GDB indicates that print_ctored is still being called once per test, even if it doesn't print anything.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior by adding the constructor and destructor probes to /build/_deps/level-zero-loader-src/source/lib/ze_lib.cpp, enabling -flto on the ze_loader target, and running bin/test-platform. Compare runs with and without LD_LIBRARY_PATH=build/lib; done should avoid premature library destruction, repeated constructor behavior, and the reported stdout segfault.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.