Skip to content

Commit 4cd5c2b

Browse files
corherethaJeztah
andcommitted
hack/make/.binary: set CGO_LDFLAGS=-latomic for arm/v5
cross-compiling for arm/v5 was failing; moby#56 84.12 /usr/bin/arm-linux-gnueabi-clang -marm -o $WORK/b001/exe/a.out -Wl,--export-dynamic-symbol=_cgo_panic -Wl,--export-dynamic-symbol=_cgo_topofstack -Wl,--export-dynamic-symbol=crosscall2 -Qunused-arguments -Wl,--compress-debug-sections=zlib /tmp/go-link-759578347/go.o /tmp/go-link-759578347/000000.o /tmp/go-link-759578347/000001.o /tmp/go-link-759578347/000002.o /tmp/go-link-759578347/000003.o /tmp/go-link-759578347/000004.o /tmp/go-link-759578347/000005.o /tmp/go-link-759578347/000006.o /tmp/go-link-759578347/000007.o /tmp/go-link-759578347/000008.o /tmp/go-link-759578347/000009.o /tmp/go-link-759578347/000010.o /tmp/go-link-759578347/000011.o /tmp/go-link-759578347/000012.o /tmp/go-link-759578347/000013.o /tmp/go-link-759578347/000014.o /tmp/go-link-759578347/000015.o /tmp/go-link-759578347/000016.o /tmp/go-link-759578347/000017.o /tmp/go-link-759578347/000018.o -O2 -g -O2 -g -O2 -g -lpthread -O2 -g -no-pie -static moby#56 84.12 ld.lld: error: undefined symbol: __atomic_load_4 moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(_cgo_wait_runtime_init_done) moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(_cgo_wait_runtime_init_done) moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(_cgo_wait_runtime_init_done) moby#56 84.12 >>> referenced 2 more times moby#56 84.12 moby#56 84.12 ld.lld: error: undefined symbol: __atomic_store_4 moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(_cgo_wait_runtime_init_done) moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(x_cgo_notify_runtime_init_done) moby#56 84.12 >>> referenced by gcc_libinit.c moby#56 84.12 >>> /tmp/go-link-759578347/000009.o:(x_cgo_set_context_function) moby#56 84.12 clang: error: linker command failed with exit code 1 (use -v to see invocation) From discussion on GitHub; moby#46982 (comment) The arm/v5 build failure looks to be due to libatomic not being included in the link. For reasons probably buried in mailing list archives, [gcc](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358) and clang don't bother to implicitly auto-link libatomic. This is not a big deal on many modern platforms with atomic intrinsics as the compiler generates inline instruction sequences, avoiding any libcalls into libatomic. ARMv5 is not one of those platforms: all atomic operations require a libcall. In theory, adding `CGO_LDFLAGS=-latomic` should fix arm/v5 builds. While it could be argued that cgo should automatically link against libatomic in the same way that it automatically links against libpthread, the Go maintainers would have a valid counter-argument that it should be the C toolchain's responsibility to link against libatomic automatically, just like it does with libgcc or compiler-rt. Co-authored-by: Sebastiaan van Stijn <[email protected]> Signed-off-by: Cory Snider <[email protected]>
1 parent e853c09 commit 4cd5c2b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

hack/make/.binary

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ source "${MAKEDIR}/.go-autogen"
8484
# we can set the correct option manually.
8585
CGO_CFLAGS+=" -Wno-atomic-alignment"
8686
export CGO_CFLAGS
87+
88+
# Make sure libatomic is included on arm/v5, because clang does not auto-link it.
89+
# see https://github.com/moby/moby/pull/46982#issuecomment-2206992611
90+
export CGO_LDFLAGS="-latomic"
8791
fi
8892

8993
echo "Building $([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "dynamic") $DEST/$BINARY_FULLNAME ($PLATFORM_NAME)..."

0 commit comments

Comments
 (0)