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
cmd/cgo/internal/testsanitizers: TestMSAN/msan8 fails with clang16.0.6 #64616
Comments
This appears to be a general clang 16 issue, not only to wsl2. It is complaining about the use of Shorter repro: package main
/*
#include <stdint.h>
#include <sanitizer/msan_interface.h>
__attribute__((noinline))
void funinit(unsigned long a1) {}
static unsigned long uninit;
void f() {
__msan_poison(&uninit, sizeof uninit);
funinit(uninit);
}
*/
import "C"
func main() {
C.f()
} Strangely enough I can't seem to replicate it with a C version and clang-16. |
Huh, something appear to have changed in clang-16 that makes it report memory as uninitialized in this case. From the test msan8 it reads: // msanGoLoop loops calling msanGoWait, with the arguments passed
// such that msan thinks that they are undefined. msan permits
// undefined values to be used as long as they are not used to
// for conditionals or for memory access. I tried clang 14, 15, 16, 17 and this only happens with clang >= 16. Looking at the release notes I can't spot anything that might've caused this change in msan behavior https://releases.llvm.org/16.0.0/docs/ReleaseNotes.html I'm not sure if this comment above is actually a guarantee from the memory sanitizer, they might have changed it silently in clang-16 without mentioning it. Here is a short C repro I put together that runs in clang 15 but not on clang 16: // clang-16 -fsanitize=memory test.c && ./a.out
#include <stdint.h>
#include <sanitizer/msan_interface.h>
__attribute__((noinline))
void funinit(unsigned long a1) {}
static unsigned long uninit ;
void f() {
__msan_poison(&uninit, sizeof uninit);
funinit(uninit);
}
int main() {
f();
return 0;
} |
Adjusting the labels as this appears to be a clang issue |
cc @dvyukov |
This looks like -fsanitize-address-param-retval (detects passing uninits as arguments), but it should be disabled by default. Maybe it was accidentally enabled in clang 16 and then disabled. |
It's enabled by default https://reviews.llvm.org/D134669 |
Looks like that is the culprint, I was looking at the llvm release notes and not the tools, that is why I did not spot this change. Thanks for the valuable insight @vitalybuka @dvyukov. |
@bcmills Do you consider this as a breaking change? This new behavior seems to be beneficial for programs:
Should we retain the old behavior? |
I think end users can control this using CGO_CFLAGS. So the breakage is not that bad. |
The state of that flag for linked C/C++ code needs to be consistent with GO code. Mismatch either way will cause false positives. |
Change https://go.dev/cl/549297 mentions this issue: |
So it appears that we cannot use |
@mauri870, perhaps the test driver itself could first try building with |
Clang 16 introduced a more aggressive behavior regarding uninitialized memory in the memory sanitizer. The new option -fsanitize-memory-param-retval is enabled by default and makes the test msan8 fail, since it uses an uninitialized variable on purpose. Disable this behavior if we are running with clang 16+. Fixes golang#64616 Change-Id: If366f978bef984ea73f6ae958f24c8fce99b59fe GitHub-Last-Rev: 60bd64a GitHub-Pull-Request: golang#64691 Reviewed-on: https://go-review.googlesource.com/c/go/+/549297 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
Go version
go version devel go1.22-78b42a5338a Fri Dec 8 03:28:17 2023 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
In wsl2
export CC=clang
clang --version
Debian clang version 16.0.6 (16)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
go test cmd/cgo/internal/testsanitizers
What did you expect to see?
test pass.
What did you see instead?
The text was updated successfully, but these errors were encountered: