-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
bazel links program using clang rather than clang++, incompatible with -fsanitize=undefined (UBSan) #12797
Comments
Maybe I am just mistaken, and bazel does not actually look at the It seems to be compiling the So am I simply using it wrong? |
Assuming bazel does indeed not look at |
bazel currently compiles through the base clang/gcc driver and doesn't support the c++ drivers of these commands, bazel c++ toolchains generally have to be explicit about any implicit c++ stuff that would otherwise happen when you use the c++ drivers for clang/gcc. if you run -v on your invocation with clang++ you'll probably see something like you effectively need to do this manually in your toolchain (or via --linkopts, or via the linkopts rule attributes), afaik this is a known limitation of the toolchain design, the link invocation is also always assumed to be c++ which isn't great but is typically benign because c code won't emit any references to c++ symbols. |
See #11122 (comment) for two easy ways to fix this problem. There is no need to hardcode library paths. Appending either
or
to the commandline above makes clang link the UBSan C++ runtime libraries without the need to use clang++. In fact, the latter flag makes clang behave as if it were clang++. |
This workaround solves the problem of compiling C++ code with a C compiler by trying to act like a C++ compiler. I was successfully able to compile C++ code with this workaround, but doing so broke the compilation of some of our dependencies that use C (see below). IMO, the fact that we need workarounds for this is evidence that we should allow specifying both the C and C++ compiler. We get errors like:
And hundreds of warnings like the following:
|
Both `-fsanitize-link-c++-runtime` and `--driver-mode=g++` can be used to work around bazelbuild/bazel#12797 but intent is clearer with `-fsanitize-link-c++-runtime`. Change-Id: I8bbf9518b7587f67c274ed389e5153d66166b2f7
Both `-fsanitize-link-c++-runtime` and `--driver-mode=g++` can be used to work around bazelbuild/bazel#12797 but intent is clearer with `-fsanitize-link-c++-runtime`. resolves #57 Change-Id: I8bbf9518b7587f67c274ed389e5153d66166b2f7
Both `-fsanitize-link-c++-runtime` and `--driver-mode=g++` can be used to work around bazelbuild/bazel#12797 but intent is clearer with `-fsanitize-link-c++-runtime`. resolves #57 Change-Id: I8bbf9518b7587f67c274ed389e5153d66166b2f7
Both `-fsanitize-link-c++-runtime` and `--driver-mode=g++` can be used to work around bazelbuild/bazel#12797 but intent is clearer with `-fsanitize-link-c++-runtime`. resolves #57 Change-Id: I8bbf9518b7587f67c274ed389e5153d66166b2f7
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale. |
@comius @pzembrod I am thinking of extending the auto-configured toolchain in a way that ends up using |
Description of the problem / feature request:
Linking a C++ program with
clang -fsanitize=undefined
results in undefined symbols.It is necessary to use
clang++ -fsanitize=undefined
instead.And bazel as of 3.7.2 tries to link C++ object files using
clang
rather thanclang++
.What operating system are you running Bazel on?
Ubuntu Focal 20.04.1 LTS.
The test case was done using clang 10.0.0-4ubuntu1, that's simply from the clang-10 Ubuntu package.
What's the output of
bazel info release
?release 3.7.2
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Here's a test case:
And we now try to build, link and run
:ubsan_test
as follows:Now I am going to manually repeat the link step (the
/usr/bin/clang @bazel-out/k8-dbg/bin/ubsan_test-2.params
) but replaceclang
withclang++
:And that succeeded just fine. And when I manually run the produced binary, it works just fine:
The text was updated successfully, but these errors were encountered: