* Re: [Buildroot] [PATCH v1 1/1] package/pkg-golang: use external linking on ARM Thumb
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
1 sibling, 0 replies; 3+ messages in thread
From: yann.morin @ 2026-10-21 6:39 UTC (permalink / raw)
To: Christian Stewart
Cc: Julien Olivain, James Hilliard, Thomas Petazzoni, buildroot,
Thomas Perale
Christian, All,
On 2026-10-20 12:51 -0700, Christian Stewart spake thusly:
> 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>
Many thanks for looking into this! :-)
Reviewed-by: Yann E. MORIN <yann.morin@orange.com>
Tested-by: Yann E. MORIN <yann.morin@orange.com>
Regards,
Yann E. MORIN.
> ---
> 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
>
--
____________
.-----------------.--------------------: _ :------------------.
| Yann E. MORIN | Real-Time Embedded | __/ ) | /"\ ASCII RIBBON |
| | Software Designer | _/ - /' | \ / CAMPAIGN |
| +33 638.411.245 '--------------------: (_ `--, | X AGAINST |
| yann.morin (at) orange.com |_=" ,--' | / \ HTML MAIL |
'--------------------------------------:______/_____:------------------'
____________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.
This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Buildroot] [PATCH v1 1/1] package/pkg-golang: use external linking on ARM Thumb
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
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni via buildroot @ 2026-10-21 19:25 UTC (permalink / raw)
To: Christian Stewart
Cc: buildroot, Yann E . MORIN, Julien Olivain, James Hilliard,
Thomas Perale
On Tue, Oct 20, 2026 at 12:51:45PM -0700, Christian Stewart via buildroot wrote:
> 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>
>
Applied to master, thanks!
Best regards,
Thomas Petazzoni
--
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread