Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v1 1/1] package/pkg-golang: use external linking on ARM Thumb
@ 2026-10-20 19:51 Christian Stewart via buildroot
  2026-10-21  6:39 ` yann.morin
  2026-10-21 19:25 ` Thomas Petazzoni via buildroot
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Stewart via buildroot @ 2026-10-20 19:51 UTC (permalink / raw)
  To: buildroot
  Cc: Christian Stewart, Yann E . MORIN, Julien Olivain, James Hilliard,
	Thomas Petazzoni, Thomas Perale

On ARMv5, runtime/cgo calls __sync_synchronize, which comes from
libgcc.a. When cgo objects have unresolved symbols, the Go internal
linker loads libgcc.a itself to resolve them. With
BR2_ARM_INSTRUCTIONS_THUMB=y, gcc is built with --with-mode=thumb, so
libgcc.a contains Thumb code, which the internal linker rejects:

  link: R_ARM_THM_CALL, are you using -marm?

Go already passes -marm when it compiles the cgo C sources, so adding
-marm to CGO_CFLAGS does not help. The call from ARM code into Thumb
code must switch the processor to the other instruction set, which the
internal linker cannot do. Force external linking instead: GNU ld can,
by rewriting the call to BLX or routing it through a small stub.

Fixes: https://autobuild.buildroot.org/results/7534211959577546c3777939d11e411d8a417baa

Signed-off-by: Christian Stewart <christian@aperture.us>

---
 package/pkg-golang.mk | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
index 3e388cb257..cf12dd56b0 100644
--- a/package/pkg-golang.mk
+++ b/package/pkg-golang.mk
@@ -146,6 +146,17 @@ ifeq ($(BR2_aarch64),y)
 $(2)_EXTLDFLAGS += -fuse-ld=bfd
 endif
 
+ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB)$(BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS),yy)
+# On ARMv5, runtime/cgo calls helpers such as __sync_synchronize that
+# come from libgcc.a. With BR2_ARM_INSTRUCTIONS_THUMB, libgcc.a is built
+# as Thumb code while Go emits ARM code. A call between the two must
+# switch the processor to the other instruction set, which Go's
+# internal linker cannot do: it aborts on the R_ARM_THM_CALL relocation.
+# The external linker (GNU ld) can, by rewriting the call to BLX or
+# routing it through a small stub, so use it.
+$(2)_LDFLAGS += -linkmode=external
+endif
+
 ifneq ($$($(2)_EXTLDFLAGS),)
 $(2)_LDFLAGS += -extldflags '$$($(2)_EXTLDFLAGS)'
 endif
-- 
2.55.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-21 19:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 19:51 [Buildroot] [PATCH v1 1/1] package/pkg-golang: use external linking on ARM Thumb Christian Stewart via buildroot
2026-10-21  6:39 ` yann.morin
2026-10-21 19:25 ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox