[OpenWrt-Devel] [PATCH] [toolchain]: Add experimental GCCGO support
Hauke Mehrtens
hauke at hauke-m.de
Sun Dec 13 15:11:17 EST 2015
On 12/09/2015 10:39 AM, openwrt at daniel.thecshore.com wrote:
> From: Daniel Dickinson <openwrt at daniel.thecshore.com>
>
> Packages can use TARGET_GOC for the gnugcc compiler.
>
> No generic packaging defaults have been added as I'm not sure what that should
> look like or if there are even sensible defaults for the Go projects out there.
>
> Currently only patches for GCC 5 - previous versions of GCC will need similar work.
> Also note that GCC 5 is required for Go 1.4; previous versions of GCC only support
> Go 1.1 therefore a dependency on GCC version will be required by many packages.
Supporting only gcc5 is no problem.
>
> Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
> ---
> rules.mk | 4 +
> toolchain/gcc/Config.in | 8 ++
> toolchain/gcc/common.mk | 10 +-
> toolchain/gcc/final/Makefile | 2 +-
> .../5.2.0/960-add-libm-for-extra-langs.patch | 39 +++++++
> .../5.2.0/970-fix-go-mprof-use-uninitialized.patch | 13 +++
> .../980-fix-missing-glibc-types-with-musl.patch | 119 +++++++++++++++++++++
> .../gcc/patches/5.2.0/990-fix-skip-gotools.patch | 26 +++++
> 8 files changed, 216 insertions(+), 5 deletions(-)
> create mode 100644 toolchain/gcc/patches/5.2.0/960-add-libm-for-extra-langs.patch
> create mode 100644 toolchain/gcc/patches/5.2.0/970-fix-go-mprof-use-uninitialized.patch
> create mode 100644 toolchain/gcc/patches/5.2.0/980-fix-missing-glibc-types-with-musl.patch
> create mode 100644 toolchain/gcc/patches/5.2.0/990-fix-skip-gotools.patch
>
> diff --git a/rules.mk b/rules.mk
> index 1e7549f..2bda73c 100644
> --- a/rules.mk
> +++ b/rules.mk
> @@ -187,6 +187,8 @@ else
> endif
> endif
>
> +TARGET_CFLAGS_GO=$(TARGET_CFLAGS) -g1
> +
> export PATH:=$(TARGET_PATH)
> export STAGING_DIR STAGING_DIR_HOST
> export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh;
> @@ -214,6 +216,7 @@ endif
> BUILD_KEY=$(TOPDIR)/key-build
>
> TARGET_CC:=$(TARGET_CROSS)gcc
> +TARGET_GOC:=$(TARGET_CROSS)gccgo
> TARGET_CXX:=$(TARGET_CROSS)g++
> KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
> SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
> @@ -253,6 +256,7 @@ TARGET_CONFIGURE_OPTS = \
> LD=$(TARGET_CROSS)ld \
> NM="$(TARGET_NM)" \
> CC="$(TARGET_CC)" \
> + GOC="$(TARGET_GOC)" \
> GCC="$(TARGET_CC)" \
> CXX="$(TARGET_CXX)" \
> RANLIB="$(TARGET_RANLIB)" \
> diff --git a/toolchain/gcc/Config.in b/toolchain/gcc/Config.in
> index a8c39d6..e89b81a 100644
> --- a/toolchain/gcc/Config.in
> +++ b/toolchain/gcc/Config.in
> @@ -72,3 +72,11 @@ config INSTALL_GFORTRAN
> default n
> help
> Build/install GNU fortran compiler ?
> +
> +config INSTALL_GOLANG
> + bool
> + prompt "Build/install golang compiler?" if TOOLCHAINOPTS
> + default n
> + help
> + Build/install GNU golang compiler ?
> +
You should add a dependency to gcc5
> diff --git a/toolchain/gcc/common.mk b/toolchain/gcc/common.mk
> index 3e4f3ee..54e8f2d 100644
> --- a/toolchain/gcc/common.mk
> +++ b/toolchain/gcc/common.mk
> @@ -101,7 +101,7 @@ HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
> HOST_STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.gcc_$(GCC_VARIANT)_installed
>
> SEP:=,
> -TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)"
> +TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GOLANG),$(SEP)go)"
>
> export libgcc_cv_fixed_point=no
> ifdef CONFIG_USE_UCLIBC
> @@ -122,8 +122,9 @@ GCC_CONFIGURE:= \
> SHELL="$(BASH)" \
> $(if $(shell gcc --version 2>&1 | grep LLVM), \
> CFLAGS="-O2 -fbracket-depth=512 -pipe" \
> - CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
> - ) \
> + CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
> + ) \
Why are you chaining the indenting here?
> + $(if $(CONFIG_USE_MUSL),CONFIG_USE_MUSL="-DCONFIG_USE_MUSL") \
Why is this needed?
> $(HOST_SOURCE_DIR)/configure \
> --with-bugurl=$(BUGURL) \
> --with-pkgversion="$(PKGVERSION)" \
> @@ -199,7 +200,8 @@ GCC_MAKE:= \
> $(MAKE) \
> CFLAGS="$(HOST_CFLAGS)" \
> CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
> - CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
> + CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
> + GOCFLAGS_FOR_TARGET="-O2 -g $(if $(CONFIG_USE_MUSL),-DCONFIG_USE_MUSL)"
Can't we take the $(TARGET_CFLAGS) for GOCFLAGS_FOR_TARGET here?
>
> define Host/Prepare
> mkdir -p $(GCC_BUILD_DIR)
> diff --git a/toolchain/gcc/final/Makefile b/toolchain/gcc/final/Makefile
> index 3434d89..224dbdb 100644
> --- a/toolchain/gcc/final/Makefile
> +++ b/toolchain/gcc/final/Makefile
> @@ -44,7 +44,7 @@ define Host/Compile
> endef
>
> define SetupExtraArch
> - for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
> + for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++,gccgo}; do \
> [ -e $$$$app ] || continue; \
> old_base=$$$$(basename $$$$app); \
> new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
> diff --git a/toolchain/gcc/patches/5.2.0/960-add-libm-for-extra-langs.patch b/toolchain/gcc/patches/5.2.0/960-add-libm-for-extra-langs.patch
> new file mode 100644
> index 0000000..a780ba6
> --- /dev/null
> +++ b/toolchain/gcc/patches/5.2.0/960-add-libm-for-extra-langs.patch
> @@ -0,0 +1,39 @@
> +Index: gcc-5.2.0/gcc/go/Make-lang.in
> +===================================================================
> +--- gcc-5.2.0.orig/gcc/go/Make-lang.in
> ++++ gcc-5.2.0/gcc/go/Make-lang.in
> +@@ -74,7 +74,7 @@ go_OBJS = $(GO_OBJS) go/gospec.o
> +
> + go1$(exeext): $(GO_OBJS) attribs.o $(BACKEND) $(LIBDEPS)
> + +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
> +- $(GO_OBJS) attribs.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
> ++ $(GO_OBJS) attribs.o $(BACKEND) $(LIBS) $(BACKENDLIBS) -lm
> +
> + # Documentation.
> +
> +Index: gcc-5.2.0/gcc/java/Make-lang.in
> +===================================================================
> +--- gcc-5.2.0.orig/gcc/java/Make-lang.in
> ++++ gcc-5.2.0/gcc/java/Make-lang.in
> +@@ -96,7 +96,7 @@ java/jvspec.o-warn = -Wno-error
> + jc1$(exeext): $(JAVA_OBJS) $(BACKEND) $(LIBDEPS) attribs.o
> + rm -f $@
> + +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
> +- $(JAVA_OBJS) $(BACKEND) $(ZLIB) $(LIBICONV) $(LIBS) attribs.o $(BACKENDLIBS)
> ++ $(JAVA_OBJS) $(BACKEND) $(ZLIB) $(LIBICONV) $(LIBS) attribs.o $(BACKENDLIBS) -lm
> +
> + jcf-dump$(exeext): $(JCFDUMP_OBJS) $(LIBDEPS)
> + rm -f $@
> +Index: gcc-5.2.0/gcc/fortran/Make-lang.in
> +===================================================================
> +--- gcc-5.2.0.orig/gcc/fortran/Make-lang.in
> ++++ gcc-5.2.0/gcc/fortran/Make-lang.in
> +@@ -96,7 +96,7 @@ f951$(exeext): $(F95_OBJS) \
> + $(BACKEND) $(LIBDEPS) attribs.o
> + +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
> + $(F95_OBJS) $(BACKEND) $(ZLIB) $(LIBS) attribs.o \
> +- $(BACKENDLIBS)
> ++ $(BACKENDLIBS) -lm
> +
> + gt-fortran-trans.h : s-gtype; @true
> + #
> diff --git a/toolchain/gcc/patches/5.2.0/970-fix-go-mprof-use-uninitialized.patch b/toolchain/gcc/patches/5.2.0/970-fix-go-mprof-use-uninitialized.patch
> new file mode 100644
> index 0000000..51300a0
> --- /dev/null
> +++ b/toolchain/gcc/patches/5.2.0/970-fix-go-mprof-use-uninitialized.patch
> @@ -0,0 +1,13 @@
> +Index: gcc-5.2.0/libgo/runtime/mprof.goc
> +===================================================================
> +--- gcc-5.2.0.orig/libgo/runtime/mprof.goc
> ++++ gcc-5.2.0/libgo/runtime/mprof.goc
> +@@ -403,7 +403,7 @@ func ThreadCreateProfile(p Slice) (n int
> +
> + func Stack(b Slice, all bool) (n int) {
> + byte *pc, *sp;
> +- bool enablegc;
> ++ bool enablegc = false;
> +
> + sp = runtime_getcallersp(&b);
> + pc = (byte*)(uintptr)runtime_getcallerpc(&b);
> diff --git a/toolchain/gcc/patches/5.2.0/980-fix-missing-glibc-types-with-musl.patch b/toolchain/gcc/patches/5.2.0/980-fix-missing-glibc-types-with-musl.patch
> new file mode 100644
> index 0000000..3a88be8
> --- /dev/null
> +++ b/toolchain/gcc/patches/5.2.0/980-fix-missing-glibc-types-with-musl.patch
> @@ -0,0 +1,119 @@
> +Index: gcc-5.2.0/libgo/mksysinfo.sh
> +===================================================================
> +--- gcc-5.2.0.orig/libgo/mksysinfo.sh
> ++++ gcc-5.2.0/libgo/mksysinfo.sh
> +@@ -166,6 +166,13 @@ cat > sysinfo.c <<EOF
> + #if defined(HAVE_SCHED_H)
> + #include <sched.h>
> + #endif
> ++#if defined(CONFIG_USE_MUSL)
> ++#include <sys/glibc-types.h>
> ++#undef off64_t
> ++#undef loff_t
> ++typedef off_t loff_t;
> ++typedef off_t off64_t;
> ++#endif
> +
> + /* Constants that may only be defined as expressions on some systems,
> + expressions too complex for -fdump-go-spec to handle. These are
> +Index: gcc-5.2.0/configure
> +===================================================================
> +--- gcc-5.2.0.orig/configure
> ++++ gcc-5.2.0/configure
> +@@ -641,6 +641,7 @@ BUILD_CONFIG
> + LDFLAGS_FOR_TARGET
> + CXXFLAGS_FOR_TARGET
> + CFLAGS_FOR_TARGET
> ++CONFIG_USE_MUSL
> + DEBUG_PREFIX_CFLAGS_FOR_TARGET
> + SYSROOT_CFLAGS_FOR_TARGET
> + extra_host_libiberty_configure_flags
> +Index: gcc-5.2.0/configure.ac
> +===================================================================
> +--- gcc-5.2.0.orig/configure.ac
> ++++ gcc-5.2.0/configure.ac
> +@@ -2359,6 +2359,7 @@ if test "x$CFLAGS_FOR_TARGET" = x; then
> + fi
> + fi
> + AC_SUBST(CFLAGS_FOR_TARGET)
> ++AC_SUBST(CONFIG_USE_MUSL)
> +
> + if test "x$CXXFLAGS_FOR_TARGET" = x; then
> + if test "x${is_cross_compiler}" = xyes; then
> +Index: gcc-5.2.0/libgo/Makefile.in
> +===================================================================
> +--- gcc-5.2.0.orig/libgo/Makefile.in
> ++++ gcc-5.2.0/libgo/Makefile.in
> +@@ -4510,7 +4510,7 @@ s-syscall_arch: Makefile
> +
> + sysinfo.go: s-sysinfo; @true
> + s-sysinfo: $(srcdir)/mksysinfo.sh config.h
> +- CC="$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(OSCFLAGS) -O" $(SHELL) $(srcdir)/mksysinfo.sh
> ++ CC="$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(OSCFLAGS) $(CONFIG_USE_MUSL) -O" $(SHELL) $(srcdir)/mksysinfo.sh
> + $(SHELL) $(srcdir)/mvifdiff.sh tmp-sysinfo.go sysinfo.go
> + $(STAMP) $@
> +
> +Index: gcc-5.2.0/Makefile.in
> +===================================================================
> +--- gcc-5.2.0.orig/Makefile.in
> ++++ gcc-5.2.0/Makefile.in
> +@@ -353,6 +353,7 @@ NM_FOR_BUILD = @NM_FOR_BUILD@
> + RANLIB_FOR_BUILD = @RANLIB_FOR_BUILD@
> + WINDMC_FOR_BUILD = @WINDMC_FOR_BUILD@
> + WINDRES_FOR_BUILD = @WINDRES_FOR_BUILD@
> ++CONFIG_USE_MUSL = @CONFIG_USE_MUSL@
> +
> + # Special variables passed down in EXTRA_GCC_FLAGS. They are defined
> + # here so that they can be overridden by Makefile fragments.
> +@@ -412,6 +413,9 @@ CXXFLAGS = @CXXFLAGS@
> + LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
> + GOCFLAGS = $(CFLAGS)
> +
> ++MODULE_FLAGS-target-libgo = \
> ++ CONFIG_USE_MUSL="$(CONFIG_USE_MUSL)"
> ++
> + TFLAGS =
> +
> + # Defaults for all stages; some are overridden below.
> +@@ -40930,8 +40934,8 @@ all-target-libgo: configure-target-libgo
> + s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
> + $(NORMAL_TARGET_EXPORTS) \
> + (cd $(TARGET_SUBDIR)/libgo && \
> +- $(MAKE) $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS) \
> +- $(TARGET-target-libgo))
> ++ $(MAKE) $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS) \
> ++ $(MODULE_FLAGS-target-libgo) $(TARGET-target-libgo))
> + @endif target-libgo
> +
> +
> +Index: gcc-5.2.0/Makefile.tpl
> +===================================================================
> +--- gcc-5.2.0.orig/Makefile.tpl
> ++++ gcc-5.2.0/Makefile.tpl
> +@@ -356,6 +356,7 @@ NM_FOR_BUILD = @NM_FOR_BUILD@
> + RANLIB_FOR_BUILD = @RANLIB_FOR_BUILD@
> + WINDMC_FOR_BUILD = @WINDMC_FOR_BUILD@
> + WINDRES_FOR_BUILD = @WINDRES_FOR_BUILD@
> ++CONFIG_USE_MUSL = @CONFIG_USE_MUSL@
> +
> + # Special variables passed down in EXTRA_GCC_FLAGS. They are defined
> + # here so that they can be overridden by Makefile fragments.
> +@@ -415,6 +416,9 @@ CXXFLAGS = @CXXFLAGS@
> + LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
> + GOCFLAGS = $(CFLAGS)
> +
> ++MODULE_FLAGS-target-libgo = \
> ++ CONFIG_USE_MUSL="$(CONFIG_USE_MUSL)"
> ++
> + TFLAGS =
> +
> + # Defaults for all stages; some are overridden below.
> +@@ -1104,7 +1108,7 @@ all-[+prefix+][+module+]: configure-[+pr
> + [+exports+] [+extra_exports+] \
> + (cd [+subdir+]/[+module+] && \
> + $(MAKE) $(BASE_FLAGS_TO_PASS) [+args+] [+stage1_args+] [+extra_make_flags+] \
> +- $(TARGET-[+prefix+][+module+]))
> ++ $(MODULE_FLAGS-[+prefix+][+module+]) $(TARGET-[+prefix+][+module+]))
> + @endif [+prefix+][+module+]
> +
> + [+ IF bootstrap +]
> diff --git a/toolchain/gcc/patches/5.2.0/990-fix-skip-gotools.patch b/toolchain/gcc/patches/5.2.0/990-fix-skip-gotools.patch
> new file mode 100644
> index 0000000..151a5b4
> --- /dev/null
> +++ b/toolchain/gcc/patches/5.2.0/990-fix-skip-gotools.patch
> @@ -0,0 +1,26 @@
> +Index: gcc-5.2.0/configure
> +===================================================================
> +--- gcc-5.2.0.orig/configure
> ++++ gcc-5.2.0/configure
> +@@ -2836,7 +2836,7 @@ Use a pristine source tree when building
> + fi
> +
> + # Skipdirs are removed silently.
> +-skipdirs=
> ++skipdirs=gotools
> + # Noconfigdirs are removed loudly.
> + noconfigdirs=""
> +
> +Index: gcc-5.2.0/configure.ac
> +===================================================================
> +--- gcc-5.2.0.orig/configure.ac
> ++++ gcc-5.2.0/configure.ac
> +@@ -226,7 +226,7 @@ Use a pristine source tree when building
> + fi
> +
> + # Skipdirs are removed silently.
> +-skipdirs=
> ++skipdirs=gotools
> + # Noconfigdirs are removed loudly.
> + noconfigdirs=""
> +
>
Are any of these patches in upstream gcc?
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list