I was packaging this repo as dev-libs/rocm-comgr based on vanilla clang for Gentoo, and met a series of problem.
Since the clang include directory in Gentoo is located at /usr/lib/clang/CLANG_VERSION/include, while llvm install prefix is at /usr/lib/llvm/LLVM_VERSION, so assuming clang include directory is under "lib/clang" in llvm prefix does not work. Since llvm/clang may bump patch version (e.g. 14.0.5->14.0.6), this path may change, so hard coding is not a good idea, either.
Believing clang could handle its -internal-isystem well, I removed 4 lines of explicit -isystem. But compile_hip_test_in_process turns out to fail.
After comparison with hipcc, I found out the problem may originated from the incorrect -resource-dir and -internal-isystem from the clang driver.
Running AMD_COMGR_SAVE_TEMPS=1 AMD_COMGR_REDIRECT_LOGS=stdout AMD_COMGR_EMIT_VERBOSE_LOGS=1 ./compile_hip_test_in_process, it gave:
As you can see, clearly there is incorrect "-resource-dir" "../../../../lib/clang/14.0.5" "-internal-isystem" "../../../../lib/clang/14.0.5" in the compiler arguments. The paths is clearly a relative path to clang executable, located at /usr/lib/llvm/14/bin. If I append this prefix, this argument changes to "-resource-dir" "/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.5" "-internal-isystem" "/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.5", then everything works.
Calling hipcc (or clang directly) from command-line does not has such problem. For example with HIPCC_VERBOSE=1 hipcc --offload-arch=gfx1031 main.cpp, I got
which shows clang got the correct -resource-dir and -internal-isystem.
To find out the problem, I build clang and rocm-comgr with debug symbols and -O0. By gdb ./compile_hip_test_in_process, I found the incomplete -resource-dir is being read out at CmdArgs.push_back(D.ResourceDir.c_str());. I did the same with gdb --args /usr/lib/llvm/14/bin/clang++ ...... and the resource dir is correct.
So in conclusion, the clang driver called from ROCm-CompilerSupport seems to have incomplete -resource-dir and -internal-isystem, while clang itself does not have the issue. I would like to know why, and how to resolve this, which I think is the best approach for packaging.
The ROCm-CompilerSupport version I'm packaging is ROCm-5.1.3.
I was packaging this repo as
dev-libs/rocm-comgr
based on vanilla clang for Gentoo, and met a series of problem.Since the clang include directory in Gentoo is located at /usr/lib/clang/CLANG_VERSION/include, while llvm install prefix is at /usr/lib/llvm/LLVM_VERSION, so assuming clang include directory is under "lib/clang" in llvm prefix does not work. Since llvm/clang may bump patch version (e.g. 14.0.5->14.0.6), this path may change, so hard coding is not a good idea, either.
Believing clang could handle its
-internal-isystem
well, I removed 4 lines of explicit-isystem
. But compile_hip_test_in_process turns out to fail.After comparison with hipcc, I found out the problem may originated from the incorrect
-resource-dir
and-internal-isystem
from the clang driver.Running
AMD_COMGR_SAVE_TEMPS=1 AMD_COMGR_REDIRECT_LOGS=stdout AMD_COMGR_EMIT_VERBOSE_LOGS=1 ./compile_hip_test_in_process
, it gave:As you can see, clearly there is incorrect
"-resource-dir" "../../../../lib/clang/14.0.5" "-internal-isystem" "../../../../lib/clang/14.0.5"
in the compiler arguments. The paths is clearly a relative path to clang executable, located at/usr/lib/llvm/14/bin
. If I append this prefix, this argument changes to"-resource-dir" "/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.5" "-internal-isystem" "/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.5"
, then everything works.Calling hipcc (or clang directly) from command-line does not has such problem. For example with
HIPCC_VERBOSE=1 hipcc --offload-arch=gfx1031 main.cpp
, I gotYou can see there is no
-isystem "/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.5/include"
. By--verbose
, I gotwhich shows clang got the correct
-resource-dir
and-internal-isystem
.To find out the problem, I build clang and rocm-comgr with debug symbols and
-O0
. Bygdb ./compile_hip_test_in_process
, I found the incomplete-resource-dir
is being read out atCmdArgs.push_back(D.ResourceDir.c_str());
. I did the same withgdb --args /usr/lib/llvm/14/bin/clang++ ......
and the resource dir is correct.So in conclusion, the clang driver called from ROCm-CompilerSupport seems to have incomplete
-resource-dir
and-internal-isystem
, while clang itself does not have the issue. I would like to know why, and how to resolve this, which I think is the best approach for packaging.The ROCm-CompilerSupport version I'm packaging is ROCm-5.1.3.