This is an archive of the discontinued LLVM Phabricator instance.

[llvm] [lit] Fix use_lld() to respect llvm_shlib_dir
ClosedPublic

Authored by mgorny on Oct 6 2022, 8:05 AM.

Details

Summary

Fix the use_lld() to use llvm_shlib_dir similarly to how use_clang()
does it. This fixes use_lld() wrongly prepending llvm_libs_dir,
i.e. the directory with system-installed LLVM libraries before
the build directory of standalone build. As a result, the shared
libraries from an earlier version of clang end up being used instead of
the newly built version when running the test suite prior to installing.

To reproduce the problem, build and install LLVM with dylibs first,
e.g.:

cmake ../llvm -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel \
  -DCMAKE_INSTALL_PREFIX="${HOME}"/llvm-test \
  -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \
  -DLLVM_INSTALL_UTILS=ON
ninja install

Then build clang against that installation and run tests:

export LD_LIBRARY_PATH=~/llvm-test/lib
export PATh=~/llvm-test/bin:"${PATH}"
cmake ../clang -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel \
  -DCMAKE_INSTALL_PREFIX="${HOME}"/llvm-test \
  -DCLANG_LINK_CLANG_DYLIB=ON -DLLVM_BUILD_TESTS=ON \
  -DLLVM_EXTERNAL_LIT="${PWD}"/bin/llvm-lit
ninja check-clang

The tests will be run with LD_LIBRARY_PATH of:

/home/${USER}/llvm-test/lib:/home/${USER}/llvm-project/build-clang/lib

As a result, installed libclang-cpp will take precedence over the one
from build dir. With the patch, the correct path is used, i.e.:

/home/${USER}/llvm-project/build-clang/lib:/home/${USER}/llvm-test/lib

Diff Detail

Event Timeline

mgorny created this revision.Oct 6 2022, 8:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 8:05 AM
mgorny requested review of this revision.Oct 6 2022, 8:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 8:05 AM

Is there a CMake command to demonstrate the difference? Consider adding it to the description.

mgorny added a comment.Oct 6 2022, 9:55 AM

Is there a CMake command to demonstrate the difference? Consider adding it to the description.

Do you mean the standalone build method that could trigger this problem, or something that actually triggers a test failure?

Is there a CMake command to demonstrate the difference? Consider adding it to the description.

Do you mean the standalone build method that could trigger this problem, or something that actually triggers a test failure?

A small reproducible instruction, possibly two CMake commands, one with llvm/CMakeListss.txt and (for standalone build) the other with lld/CMakeLists.txt

mgorny edited the summary of this revision. (Show Details)Oct 6 2022, 12:45 PM

A small reproducible instruction, possibly two CMake commands, one with llvm/CMakeListss.txt and (for standalone build) the other with lld/CMakeLists.txt

Done. Although it's clang what's failing here.

MaskRay accepted this revision.Oct 6 2022, 1:21 PM
This revision is now accepted and ready to land.Oct 6 2022, 1:21 PM
This revision was landed with ongoing or failed builds.Oct 6 2022, 10:15 PM
This revision was automatically updated to reflect the committed changes.