This is an archive of the discontinued LLVM Phabricator instance.

[Support][CMake] Fix exposed absolute path dependency of terminfo library
AbandonedPublic

Authored by xndcn on Nov 23 2021, 6:30 AM.

Details

Summary

terminfo library dependency is exposed as absolute path in "LLVMExports.cmake".

clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz/lib/cmake/llvm/LLVMExports.cmake:

set_target_properties(LLVMSupport PROPERTIES
  INTERFACE_LINK_LIBRARIES "m;ZLIB::ZLIB;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libcurses.tbd;LLVMDemangle"
)

clang+llvm-13.0.0-aarch64-linux-gnu.tar.xz/lib/cmake/llvm/LLVMExports.cmake:

set_target_properties(LLVMSupport PROPERTIES
  INTERFACE_LINK_LIBRARIES "rt;dl;-lpthread;m;ZLIB::ZLIB;/usr/lib/aarch64-linux-gnu/libtinfo.so;LLVMDemangle"
)

Diff Detail

Event Timeline

xndcn created this revision.Nov 23 2021, 6:30 AM
xndcn requested review of this revision.Nov 23 2021, 6:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2021, 6:30 AM
compnerd requested changes to this revision.Nov 28 2021, 11:05 AM

I'm not sure that this is a good idea. This now means that you can link against two different versions of this library - one when building LLVMSupport and one that any user linking against LLVMSupport happens to find in the library search path. Consider someone explicitly providing a path to the terminfo library when configuring. At the very least, the library search path should be propagated to ensure that the right version is used.

This revision now requires changes to proceed.Nov 28 2021, 11:05 AM
xndcn updated this revision to Diff 390263.Nov 29 2021, 12:06 AM
xndcn updated this revision to Diff 390267.Nov 29 2021, 12:44 AM
xndcn added a comment.Nov 29 2021, 4:31 PM

I'm not sure that this is a good idea. This now means that you can link against two different versions of this library - one when building LLVMSupport and one that any user linking against LLVMSupport happens to find in the library search path. Consider someone explicitly providing a path to the terminfo library when configuring. At the very least, the library search path should be propagated to ensure that the right version is used.

Thanks! I have updated the patch. In fact the library like "ZLIB::ZLIB" or "LibXML2" also dose not use absolute path, so I think we can use the same idea to wrap the libtinfo into an IMPORTED library "LibTerminfo" in CMake. In LLVMConfig.cmake, we can try to find LibTerminfo from the specific path as a "HINTS".

compnerd added a comment.EditedDec 4 2021, 11:31 AM

I think that this is almost correct now. While this will generate the binaries correctly, this is still a problem for tests. Without the absolute path, we now run the risk of the DT_NEEDED being correct but without a DT_RPATH/DR_RUNPATH, this could pick up the wrong library still at runtime. While the link time issue is resolved, the runtime portion is still a problem.

xndcn added a comment.Dec 5 2021, 7:06 PM

I think that this is almost correct now. While this will generate the binaries correctly, this is still a problem for tests. Without the absolute path, we now run the risk of the DT_NEEDED being correct but without a DT_RPATH/DR_RUNPATH, this could pick up the wrong library still at runtime. While the link time issue is resolved, the runtime portion is still a problem.

Thanks! Just found a similar but more elegant commit has been merged yesterday: https://reviews.llvm.org/D114327
So I will close it now.

xndcn abandoned this revision.Dec 11 2021, 6:03 AM