From 99bf48e5f8d0ba791706c168c81adb7484fffef2 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Thu, 27 Feb 2025 19:27:16 +0100 Subject: [PATCH] Makefile: set CGO_LDFLAGS=-latomic on arm/v6 Compiling with Go >= 1.22 on arm/v6 is failing with the following error message: 27.84 gcc_libinit.c:44:8: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] For these Go versions, we need to manually link to libatomic as arm/v6 does not support atomic intrinsics and neither the CGo, nor the C toolchain automatically link to that library. Signed-off-by: Albin Kerouanton --- Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile b/Makefile index 9868445..036a8f0 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,17 @@ ifeq "$(shell go env GOOS)" "darwin" export CGO_CFLAGS = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) endif +ifeq "$(shell go env GOOS)/$(shell go env GOARCH)/$(shell go env GOARM)" "linux/arm/6" + # Neither the CGo compiler, nor the C toolchain automatically link to + # libatomic when the architecture doesn't support atomic intrinsics, as is + # the case for arm/v6. + # + # Here's the error we get when this is not done (see https://github.com/docker/docker-credential-helpers/pull/340#issuecomment-2437593837): + # + # gcc_libinit.c:44:8: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] + export CGO_LDFLAGS=-latomic +endif + .PHONY: all all: cross