intellij icon indicating copy to clipboard operation
intellij copied to clipboard

CLion C++ '-oso_prefix,.' "path trimming" flag injected by the debug launcher fails linking (Linux/clang-17/mold)

Open jayv opened this issue 9 months ago • 5 comments

Whle trying to learn Bazel with a simple project setup with Bazel/Clion I ran into this issue.

update: oso_prefix seems a non-standard Apple/Darwin-only linker flag https://github.com/bazelbuild/intellij/issues/6410#issuecomment-2080239502 introduced to fix debugging on MacOS

A normal build/run of the main bazel target works fine, but the debug build fails to link because of the "path trimming" flags that get injected by default by the plugin. When I run the bazel command without the -oso_prefix,. part it links just fine, so when I enabled bazel.trim.absolute.path.disabled in the registry, my project builds/runs/hits breakpoints per usual 🤷🏻‍♂️, ~so I'm not sure why this is done by default.~

This is on Ubuntu Linux with clang-17 and mold (as linker) configured as a custom blaze toolchain to leverage C++23 and libc++. That said ld, and gold also struggle with this linker flag, suggesting -oso_prefix,. is not correct or universally supported. https://github.com/bazelbuild/intellij/issues/6410#issuecomment-2080239502 ~Or is there perhaps something wrong with my bazel project setup?~

https://github.com/bazelbuild/intellij/blob/86e31292434875ca1f86a02230cde5a3de5a70cf/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrRunConfigurationRunner.java#L120-L124

bazel command:

bazel build --tool_tag=ijwb:CLion --compilation_mode=dbg --copt=-O0 --copt=-g --strip=never --dynamic_mode=off --fission=yes --copt=-fdebug-compilation-dir=/home/jayv/devperso/serc --linkopt=-Wl,-oso_prefix,. --curses=no --color=yes --progress_in_terminal_title=no --build_event_binary_file=/tmp/intellij-bep-7aab6642-3b55-406f-bf24-7492807af451 --nobuild_event_binary_file_path_conversion -- //:serc

clang command:

ERROR: /home/jayv/devperso/serc/BUILD:28:10: Linking serc failed: (Exit 1): clang++-17 failed: error executing command (from target //:serc) /usr/bin/clang++-17 -o bazel-out/k8-dbg/bin/serc bazel-out/k8-dbg/bin/_objs/serc/main.o bazel-out/k8-dbg/bin/external/fmt/libfmt.a -Wl,-oso_prefix,. -lc++ -lm '-fuse-ld=ld'

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/usr/bin/ld: cannot find .: file format not recognized
clang++-17: error: linker command failed with exit code 1 (use -v to see invocation)
Target //:serc failed to build

jayv avatar Apr 26 '24 23:04 jayv