HIP supports _Float16 by default in host programs, which
may cause calls of conversion functions for _Float16
emitted e.g. __truncdfhf2. These functions are not
available in libgcc but in libclang_rt.builtins. Therefore
--hip-link needs to link with libclang_rt.builtins by
default.
Details
Diff Detail
Unit Tests
Event Timeline
Looks OK syntax-wise. Library path should probably be fixed, though it appears to be a somewhat separate issue and could be done in its own patch, if the required change is not trivial.
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
684–690 | Nit: Collapse all of these into a single append() | |
clang/test/Driver/hip-runtime-libs-msvc.hip | ||
10 | What are we matching here? A more verbose pattern or some comments would be helpful. | |
12 | CHECK-SAME? |
clang/lib/Driver/ToolChains/MSVC.cpp | ||
---|---|---|
485 | will use getCompilerRT to get the compiler-rt builtin lib name so that it is always correct | |
clang/test/Driver/hip-runtime-libs-msvc.hip | ||
10 | this is for checking lib path for compiler lib. As we will use getCompilerRT to get the complete path of compiler-rt builtin lib, this part will be changed. We will use a clang option to print the compiler-rt lib path and use it as a reference to check compiler-rt lib used by HIP. | |
12 | will do |
These functions are not available in libgcc but in libclang_rt.builtins. Therefore --hip-link needs to link with libclang_rt.builtins by default.
I think this is problematic.
The current link sequence is ... "-lamdhip64" "/tmp/Debug/lib/clang/15.0.0/lib/linux/libclang_rt.builtins-x86_64.a" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o" "/lib/x86_64-linux-gnu/crtn.o"
Linking in libclang_rt.builtins is incompatible with libgcc. There may be subtle symbol resolving issues. I don't think silently changing the behavior is desired.
Perhaps --rocm-path should require --rtlib=compiler-rt. See the --rtlib=libgcc requires --unwindlib=libgcc diagnostic.
Your user will need to do a bit more work if CLANG_DEFAULT_RTLIB is not compiler-rt.
clang/test/Driver/hip-runtime-libs-linux.hip | ||
---|---|---|
6 | Note: -target is legacy spelling. --target= is the recommended name. |
No. --unwindlib=libunwind requires --rtlib=compiler-rt. --rtlib=compiler-rt is compatible with both --unwindlib=libgcc and --unwindlib=libunwind.
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
684–690 | Note: I think multiple push_back isn't that bad... |
clang/lib/Driver/ToolChains/Linux.cpp | ||
---|---|---|
684–690 | That's why I've marked it as a "nit". For arguments, push_back works best for single arguments. append(), when more than one is needed. CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath(); CmdArgs.append({"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())}); CmdArgs.push_back("-lamdhip64"); CmdArgs.push_back(Args.MakeArgString(getCompilerRT(Args, "builtins"))); Single .append({}) works OK for me, too. Passing a mix of single options and options with arguments via append() combined with passing multi-word arguments with push_back() looks rather odd in its inconsistency to me. It makes no practical difference either way, so it's merely a minor style/readability nit, as far as I'm concerned. I'm fine deferring to author's preferences. |
If only use -rtlib=compiler-rt without changing unwind lib, I will get missing symbol:
[2022-06-16T20:05:28.644Z] ld.lld: error: undefined symbol: _Unwind_Resume
[2022-06-16T20:05:28.644Z] >>> referenced by main.cpp
[2022-06-16T20:05:28.644Z] >>> CMakeFiles/MIOpenDriver.dir/main.cpp.o:(generate_skipahead_file())
[2022-06-16T20:05:28.644Z] >>> referenced by main.cpp
[2022-06-16T20:05:28.644Z] >>> CMakeFiles/MIOpenDriver.dir/main.cpp.o:(main)
[2022-06-16T20:05:28.644Z] >>> referenced by main.cpp
[2022-06-16T20:05:28.644Z] >>> CMakeFiles/MIOpenDriver.dir/main.cpp.o:(std::function<void (float&, float, bool&)> reduce::ReduceOpFn2<float>(miopenReduceTensorOp_t))
[2022-06-16T20:05:28.644Z] >>> referenced 1246 more times
[2022-06-16T20:05:28.644Z]
[2022-06-16T20:05:28.644Z] ld.lld: error: ../lib/libMIOpen.so.1.0.50300: undefined reference to _Unwind_Resume [--no-allow-shlib-undefined]
[2022-06-16T20:05:28.644Z] ld.lld: error: ../lib/libMIOpen.so.1.0.50300: undefined reference to _Unwind_Backtrace [--no-allow-shlib-undefined]
[2022-06-16T20:05:28.644Z] ld.lld: error: ../lib/libMIOpen.so.1.0.50300: undefined reference to _Unwind_GetIP [--no-allow-shlib-undefined]
[2022-06-16T20:05:28.644Z] clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
If I use --rtlib=compiler-rt, do I have to explicitly add --unwindlib=libgcc or --unwindlib=libunwind? I suspect the linker is not linking the unwind library when -rtlib=compiler-rt is specified.
Either is fine.
If --rtlib=libgcc, --unwindlib must be libgcc (platform defaults to libgcc on Linux).
--rtlib and --unwindlib are orthogonal. To use libunwind, specify --unwindlib.
Magically deciding a default value for --unwindlib or --rtlib is not nice. You may emit a warning if the selected default happens to be incompatible with HIP.
We build clang not just for compiling HIP programs. For C/C++ programs, we want to use the default runtime and unwind library.
We only want to change the default runtime and unwind library for HIP.
One choice is that ensure the user specify -DCMAKE_DEFAULT_RTLIB=compiler-rt.
(Since compiler-rt can be used with libgcc_s, -DCMAKE_DEFAULT_UNWINDLIB=libunwind is not strictly necessary.)
We only want to change the default runtime and unwind library for HIP.
The correct place is clang/lib/Driver/ToolChain.cpp ToolChain::GetUnwindLibType (see "platform").
HIP should have its derived ToolChain to override the member function.
Nit: Collapse all of these into a single append()