Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jayv opened this issue Apr 26, 2024 · 5 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: c++ C++ rules integration product: CLion CLion plugin

Comments

@jayv
Copy link

jayv commented Apr 26, 2024

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 #6410 (comment) 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. #6410 (comment) Or is there perhaps something wrong with my bazel project setup?

isClangBuild() && !Registry.is("bazel.trim.absolute.path.disabled")
? ImmutableList.of(
"--copt=-fdebug-compilation-dir=" + WorkspaceRoot.fromProject(env.getProject()),
"--linkopt=-Wl,-oso_prefix,.")
: ImmutableList.of();

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
Copy link
Author

jayv commented Apr 26, 2024

As I dig more into this, it seems like a non-standard Apple only linker flag?

image

I can't find any evidence of other linkers supporting this... impemented only for lld with mach-o target.

https://bugs.llvm.org/show_bug.cgi?id=50229

If that's the case the condition should not just check isClangBuild() but rather check if the Darwin ld64 linker is being invoked or lld with mach-o target.

@jayv jayv changed the title CLion C++ '-oso_prefix,.' "path trimming" flag injected by the debug launcher fails linking (clang-17/mold) CLion C++ '-oso_prefix,.' "path trimming" flag injected by the debug launcher fails linking (Linux/clang-17/mold) Apr 26, 2024
@jayv
Copy link
Author

jayv commented Apr 27, 2024

This is the relevant change "fix debugging on Mac OS" that introduced the new flag, and probably broke non-Apple users:

#4003

/cc @tpasternak

@tanishktyagii tanishktyagii added the lang: c++ C++ rules integration label Apr 29, 2024
@tanishktyagii tanishktyagii added awaiting-maintainer Awaiting review from Bazel team on issues product: CLion CLion plugin labels Apr 29, 2024
@tpasternak
Copy link
Collaborator

I think it's rather triggered by the fact you are using mold instead of lld. We are planning to reorganize some things in this area and we will take this issue into account.

@jayv
Copy link
Author

jayv commented Apr 30, 2024

Hmm, did you try? I tried mold, gold, and gnu ld, nothing worked, and then I found the PR/commit on llvm llvm/llvm-project@236197e
AFAICT this flag was only added for “mach-o” (mac) binaries, meaning lld for linux (elf) binaries does not support this flag.

@tpasternak
Copy link
Collaborator

Thanks for clarification then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: c++ C++ rules integration product: CLion CLion plugin
Projects
None yet
Development

No branches or pull requests

3 participants