Compile PyTorch with USE_CPP_CODE_COVERAGE=ON

I am very sorry for bothering u guys, but I have spent 1 week and asked chatgpt/discuss.pytorch.org and googled and rebuild llvm multiple times…I couldn’t build pytorch with “-fprofile-instr-generate -fcoverage-mapping”, clang 17.0.6, it always complains

/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_begin_data':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_begin_data+0x3): undefined reference to `__start___llvm_prf_data'
/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_end_data':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_end_data+0x3): undefined reference to `__stop___llvm_prf_data'
/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_begin_names':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_begin_names+0x3): undefined reference to `__start___llvm_prf_names'
/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_end_names':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_end_names+0x3): undefined reference to `__stop___llvm_prf_names'
/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_begin_counters':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_begin_counters+0x3): undefined reference to `__start___llvm_prf_cnts'
/usr/bin/ld: /home/iris/tool_bins/llvm_release_17/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a(InstrProfilingPlatformLinux.c.o): in function `__llvm_profile_end_counters':
InstrProfilingPlatformLinux.c:(.text.__llvm_profile_end_counters+0x3): undefined reference to `__stop___llvm_prf_cnts'

I tried to link with/without libclang_rt.profile.a, but it still remains. I tried " -rtlib=compiler-rt", but it said: " error adding symbols: DSO missing from command line"

single command

~/tool_bins/llvm_release_17/bin/clang++ -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wsuggest-override -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-pass-failed -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -fno-math-errno -fno-trapping-math -Werror=format -fprofile-instr-generate -fcoverage-mapping -g -fstandalone-debug -fno-omit-frame-pointer -O0 -rdynamic -Wl,-rpath-link,/home/iris/miniconda3/envs/pytorch_2_4_1/lib     -Xlinker --no-as-needed c10/cuda/test/CMakeFiles/c10_cuda_CUDAAssertionsTest_1_var_test.dir/impl/CUDAAssertionsTest_1_var_test.cu.o -o bin/c10_cuda_CUDAAssertionsTest_1_var_test -L/usr/local/cuda-12.4/targets/x86_64-linux/lib/stubs   -L/usr/local/cuda-12.4/targets/x86_64-linux/lib -Wl,-rpath,/home/iris/CDeepFuzz/pytorch/build/lib:/usr/local/cuda-12.4/lib64:  lib/libc10_cuda.so  lib/libc10.so  lib/libgtest_maind.a  /usr/local/cuda-12.4/lib64/libcudart.so  lib/libgtestd.a    -lcudadevrt  -lcudart_static  -lrt  -lpthread  -ldl && /home/iris/miniconda3/envs/pytorch_2_4_1/bin/cmake -E __run_co_compile --lwyu="ldd;-u;-r" --source=bin/c10_cuda_CUDAAssertionsTest_1_var_test 

Fix 136201-Compile with USE_CPP_CODE_COVERAGE=ON throw erros: use lld… by xuesu · Pull Request #136632 · pytorch/pytorch · GitHub just force lld