This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Fix rpath for compiler-rt
ClosedPublic

Authored by yaxunl on Mar 22 2023, 9:03 PM.

Details

Summary

The compiler-rt library path can be either {resource_dir}/lib/{triple}
or {resource_dir}/lib/{OS}/{arch} depending on whether
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default is ON or OFF.
Currently, the rpath added by -rtlib-add-rpath only adds
the latter. This patch checks both and adds the one that exists.

Diff Detail

Event Timeline

yaxunl created this revision.Mar 22 2023, 9:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 9:03 PM
Herald added a subscriber: dberris. · View Herald Transcript
yaxunl requested review of this revision.Mar 22 2023, 9:03 PM

This change is correct for Linux. llvm/CMakeLists.txt says:

if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux|OS390")
  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)

Some rpath using OSes (notably macOS) use LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default=OFF. Is the rpath setting ever usable on macOS?
If not, the change is correct.

This change is correct for Linux. llvm/CMakeLists.txt says:

if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux|OS390")
  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)

Some rpath using OSes (notably macOS) use LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default=OFF. Is the rpath setting ever usable on macOS?
If not, the change is correct.

How about I try to add both? there is check whether the dir exist then adding it, so only the existing one will be added. then it should work in either case.

This change is correct for Linux. llvm/CMakeLists.txt says:

if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux|OS390")
  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)

Some rpath using OSes (notably macOS) use LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default=OFF. Is the rpath setting ever usable on macOS?
If not, the change is correct.

How about I try to add both? there is check whether the dir exist then adding it, so only the existing one will be added. then it should work in either case.

Yes. Detecting both locations will be nice.

yaxunl updated this revision to Diff 508312.Mar 25 2023, 8:44 AM
yaxunl edited the summary of this revision. (Show Details)

adds check for both {resource_dir}/lib/{triple} and {resource_dir}/lib/{OS}/{arch}

The new test can be placed in arch-specific-libdir-rpath.c. One or two additional RUN lines seem sufficient, no need to duplicate too many.

Also, use --target= for new tests and avoid ^//$.

clang/lib/Driver/ToolChains/OHOS.cpp
142–144

delete braces

yaxunl updated this revision to Diff 508823.Mar 27 2023, 3:52 PM

revised by Fangrui's comments

MaskRay accepted this revision.Mar 30 2023, 8:43 PM
MaskRay added inline comments.
clang/lib/Driver/ToolChain.cpp
638

unneeded blank line

This revision is now accepted and ready to land.Mar 30 2023, 8:43 PM
yaxunl marked 2 inline comments as done.Apr 1 2023, 8:46 PM
yaxunl added inline comments.
clang/lib/Driver/ToolChain.cpp
638

will remove when committing

This revision was landed with ongoing or failed builds.Apr 5 2023, 5:15 PM
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 5:15 PM