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
runtime/cgo: build fails with GOARCH=arm GOARM=5 CC=clang #65290
Comments
This seems to have been introduced with CL505455 addition of This bit clang-14 --target=armv5-none-linux-gnu -mfloat-abi=hard --sysroot=/usr/arm-linux-gnueabihf test.c
test.c:8:15: warning: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Watomic-alignment]
int result = __atomic_load_n(&myVar, __ATOMIC_RELAXED);
^ You could try the compiler flag |
I think "max size 0" means that the platform does not natively support atomic operations and they have to be emulated. https://bugs.llvm.org/show_bug.cgi?id=38593 |
Interesting! That seems to be the real reason, the error message is just poorly worded. Mauri |
I wonder if we can just ignore the warning in runtime/cgo. Since we build with diff --git a/src/runtime/cgo/cgo.go b/src/runtime/cgo/cgo.go
index 1e3a502918..4bd8e6a53a 100644
--- a/src/runtime/cgo/cgo.go
+++ b/src/runtime/cgo/cgo.go
@@ -29,6 +29,8 @@ package cgo
#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS
+#cgo arm CFLAGS: -Wno-atomic-alignment
+
*/
import "C" cc @golang/runtime @golang/arm |
In triage, one thing we're wondering is if this error is actually benign and we're OK with unaligned atomics (which IIRC break some atomicity guarantees) or if we need to actually fix this in the code CL 505455 modified. |
I don't think the issue here is alignment. I think clang is just warning that ARMv5 doesn't really have atomics, as @corhere mentioned. In our own atomic code, we call into a kernel-provided stub to help with atomics on ARM <7: https://cs.opensource.google/go/go/+/master:src/runtime/internal/atomic/sys_linux_arm.s;l=79-83. In the kernel, that is https://elixir.bootlin.com/linux/latest/source/arch/arm/kernel/entry-armv.S#L749 -> https://elixir.bootlin.com/linux/latest/source/arch/arm/include/asm/assembler.h#L374. For ARMv5 that is ultimately a nop, because Linux simply doesn't support SMP for ARMv5 at all. I don't know what the clang-generated code looks like (if someone could provide the disassembly, that would be helpful), but I suspect it is just warning that it has to call into a helper. If this is accurate, I suspect ignoring the warning is fine. |
The |
If we only see the warnings for runtime/cgo/gcc_libinit.c, then we can add a
|
I just confirmed that this works. It is less intrusive than disabling the warning in a #cgo directive. Thanks, Ian. |
Change https://go.dev/cl/562348 mentions this issue: |
When cross-compiling a cgo program with CC=clang for Linux/ARMv5, atomic warnings cause build errors, as cgo uses -Werror. These warnings seem to be harmless and come from the usage of __atomic_load_n, which is emulated due to the lack of atomic instructions in armv5. Fixes golang#65290 Change-Id: Ie72efb77468f06888f81f15850401dc8ce2c78f9 GitHub-Last-Rev: fbad847 GitHub-Pull-Request: golang#65588 Reviewed-on: https://go-review.googlesource.com/c/go/+/562348 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Change https://go.dev/cl/567556 mentions this issue: |
For #65290 Fixes #65971 Change-Id: If15853f287e06b85bb1cb038b3785516d5812f84 Reviewed-on: https://go-review.googlesource.com/c/go/+/567556 Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Go version
go version go1.22rc2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Attempted to (cross-)compile a cgo program for Linux/ARMv5 using clang.
What did you see happen?
What did you expect to see?
The runtime/cgo package should build without error, like when using gcc.
The text was updated successfully, but these errors were encountered: