oneapi-src / oneapi-src/unified-runtime
"platform" CTS tests cause bizzare linker behaviour with `libze_loader.so` when linked with `-flto`
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_PATHis not set, then the program will search for alibze_loader.soin the system path, possibly ending up with/lib/x86_64-linux-gnu/libze_loader.so.1. Since this is different tobuild/lib/libze_loader.so, they don't have access to the same global state, and problems happen. - If
LD_LIBRARY_PATHis set tobuild/liband the printing code is present, it segfaults trying to write to stdout. - If
LD_LIBRARY_PATHis set tobuild/liband the printing code is removed, the test passes. GDB indicates thatprint_ctoredis still being called once per test, even if it doesn't print anything.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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