microsoft / microsoft/DirectXShaderCompiler

libdxil.so has incorrect soname and requires use of --as-needed when linking

Open
#7,568 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description

Linking a binary against DirectXShaderCompiler using the Clang compiler on Ubuntu will by default result in a binary that will not run, complaining about a missing library with an incorrect name libdxildll.so. When using GCC, building and linking the exact same program against the exact some precompiled dxcompiler library will not exhibit this problem.

sean@desktop:~/projects/dxc-bug$ ./build/repro
./build/repro: error while loading shared libraries: libdxildll.so: cannot open shared object file: No such file or directory

The correct library name is libdxil.so. I'm unsure what the root fix should be, but the workaround for using is to add -Wl,--as-needed to the linker invocation when using Clang.

The specific test circumstances are using Ubuntu 24.04 system (via WSL or GitHub Actions) with the distro's Clang 19 packages, building via CMake, and consuming DirectXShaderCompiler via vcpkg. A small repro is attached.

It appears that -- at least on some distros -- GCC uses --as-needed by default when invoking the linker, but Clang does not.

If this flag is intended to be required, then an issue against vcpkg to add the flag to their CMake import script would be the correct source of action. I would also then ask that the flag be documented as required for DirectXShaderCompiler, which does not seem to be the case currently.

The linker flag would perhaps not be needed if the soname of libdxil.so were correct, but I have not tried fixing the soname.

sean@desktop:~/projects/dxc-bug$ readelf --all vcpkg/packages/directx-dxc_x64-linux/lib/libdxil.so | grep -i libdxildll
 0x000000000000000e (SONAME)             Library soname: [libdxildll.so]

The CMakeShaderCompiler build scripts set the OUTPUT_NAME property of the dxildll target to "dxil" but the soname is not affected. CMake's default behavior uses the library target name plus lib prefix for the soname.

Steps to Reproduce

repro.zip

Attached repro has detailed steps in the README.md file. The short version:

  • Install clang-19 on Ubuntu 24.04.
  • Make a simple main.cpp that uses symbols like IDxcCompiler3 from dxcapi.h.
  • Setup build via CMake and consuming the library via vcpkg's directx-dxc package (which "just" uses the official binary releases from the dxc repo)
  • Configure the CMake project with -DCMAKE_CXX_COMPILER=clang++.
  • Build the project
  • Execute the binary, observe error.

If built with GCC, the error will not occur.

The workaround for users is to add -Wl,--as-needed to the clang command line when linking the binary, e.g. via CMAKE_EXE_LINKER_FLAGS.

Actual Behavior

The Clang-built binary will fail to run, with the error:

./build/repro: error while loading shared libraries: libdxildll.so: cannot open shared object file: No such file or directory

Environment

Contributor guide

Open the contributing guide

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 failure using the attached repro.zip and its README.md with Ubuntu 24.04, Clang 19, CMake, and vcpkg. Inspect tools/clang/tools/dxildll/CMakeLists.txt, the linked libdxil.so with readelf, and vcpkg's directx-dxc-config.cmake.in. Done means the Clang-linked binary no longer requests libdxildll.so, with the chosen fix documented or reflected in the relevant build configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.