blob: b1d7576328f51a39188e6b4eb75bd4f46cec3028 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From dda6b050cd74a352670787a294596a9c56c21327 Mon Sep 17 00:00:00 2001
2From: Yousong Zhou <yszhou4tech@gmail.com>
3Date: Fri, 4 May 2018 18:20:53 +0800
4Subject: [PATCH] gotools: fix compilation when making cross compiler
5
6libgo is "the runtime support library for the Go programming language.
7This library is intended for use with the Go frontend."
8
9gccgo will link target files with libgo.so which depends on libgcc_s.so.1, but
10the linker will complain that it cannot find it. That's because shared libgcc
11is not present in the install directory yet. libgo.so was made without problem
12because gcc will emit -lgcc_s when compiled with -shared option. When gotools
13were being made, it was supplied with -static-libgcc thus no link option was
14provided. Check LIBGO in gcc/go/gcc-spec.c for how gccgo make a builtin spec
15for linking with libgo.so
16
17- GccgoCrossCompilation, https://github.com/golang/go/wiki/GccgoCrossCompilation
18- Cross-building instructions, http://www.eglibc.org/archives/patches/msg00078.html
19
20When 3-pass GCC compilation is used, shared libgcc runtime libraries will be
21available after gcc pass2 completed and will meet the gotools link requirement
22at gcc pass3
23---
24 gotools/Makefile.am | 4 +++-
25 gotools/Makefile.in | 4 +++-
26 2 files changed, 6 insertions(+), 2 deletions(-)
27
28--- a/gotools/Makefile.am
29+++ b/gotools/Makefile.am
30@@ -26,6 +26,7 @@ PWD_COMMAND = $${PWDCMD-pwd}
31 STAMP = echo timestamp >
32
33 libgodir = ../$(target_noncanonical)/libgo
34+libgccdir = ../$(target_noncanonical)/libgcc
35 LIBGODEP = $(libgodir)/libgo.la
36
37 LIBGOTOOL = $(libgodir)/libgotool.a
38@@ -41,7 +42,8 @@ GOCFLAGS = $(CFLAGS_FOR_TARGET)
39 GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
40
41 AM_GOCFLAGS = -I $(libgodir)
42-AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
43+AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs \
44+ -L $(libgccdir) -L $(libgccdir)/.libs -lgcc_s
45 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
46
47 libgosrcdir = $(srcdir)/../libgo/go
48--- a/gotools/Makefile.in
49+++ b/gotools/Makefile.in
50@@ -337,6 +337,7 @@ mkinstalldirs = $(SHELL) $(toplevel_srcd
51 PWD_COMMAND = $${PWDCMD-pwd}
52 STAMP = echo timestamp >
53 libgodir = ../$(target_noncanonical)/libgo
54+libgccdir = ../$(target_noncanonical)/libgcc
55 LIBGODEP = $(libgodir)/libgo.la
56 LIBGOTOOL = $(libgodir)/libgotool.a
57 @NATIVE_FALSE@GOCOMPILER = $(GOC)
58@@ -346,7 +347,8 @@ LIBGOTOOL = $(libgodir)/libgotool.a
59 GOCFLAGS = $(CFLAGS_FOR_TARGET)
60 GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
61 AM_GOCFLAGS = -I $(libgodir)
62-AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
63+AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs \
64+ -L $(libgccdir) -L $(libgccdir)/.libs -lgcc_s
65 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
66 libgosrcdir = $(srcdir)/../libgo/go
67 cmdsrcdir = $(libgosrcdir)/cmd