Go: plugin: -buildmode=plugin not supported on linux/mips

Created on 30 Jul 2017  路  22Comments  路  Source: golang/go

According to https://golang.org/pkg/plugin/ plugins under Linux should be supported.

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64
go version devel +ac29f30dbb Fri Jul 28 00:29:08 2017 +0000 linux/amd64

What did you do?

GOOS=linux GOARCH=mips ./go build -a -buildmode=plugin main.go

What did you expect to see?

Successfully building mips(32) plugin

What did you see instead?

"-buildmode=plugin not supported on linux/mips"

Documentation NeedsFix

Most helpful comment

Seems it was not integrated in 1.12 (go1.12.5), is it still work in progress ?

All 22 comments

I suppose we could document this limitation in the meantime, if this is known. I believe it is.

/cc @MIPSbkirby @ianlancetaylor

Does the feature also ARCH dependent and not just OS dependent?

@juliandroid, it needs cgo. But that happened in https://go-review.googlesource.com/34318 already. Ah, I bet you're not getting cgo support (and thus no plugin support) because you're cross-compiling.

Is your host machine actually amd64?

My machine is amd64 while I want to build mips binaries with plugin support.

After git cloning golang, I've built it with:
GOROOT_BOOTSTRAP=$HOME/build/go1.8/ ./all.bash

I've noticed in the documentation that "C compiler such as gcc or clang must be installed first", but I guess that refers to cross-compiled GCC not about my "normal" gcc for amd64 (which I have installed in front).

Now I'm building openwrt 15.05 which should supply me with GCC 4.7.3 built to generate mips binaries, which I hope will be useful for the purpose of building go with CGO support. However I couldn't find any ENV variables and instructions how to pass that cross-compiler in order for the "all.bash" to use it.

Please let me know if I'm getting this right!?

Edit: Looking at the code, your point is that there is no internal linking for mips yet, so I need CGO with external linking to have support for plugins?

Edit 2: am I supposed to use CC when I run "go build" and not at the golang compiling phase, like this:

CC=mips-linux-musl-gcc GOOS=linux GOARCH=mips CGO_ENABLED=1 go build -a -o myprogram -ldflags="-extld=$CC"

@bradfitz I've spent some time testing and debugging:

Within Openwrt, I'm building Golang compiler with something like this (command line slightly redacted):

CC="gcc" GOOS=linux GOARCH=mips GOMIPS=r2softfloat CC_FOR_TARGET=mips-openwrt-linux-uclibc-gcc GOROOT_BOOTSTRAP=$HOME/bootstrap_golang/go/ ./make.bash

Building a simple program on my amd64 with embedded C builds and runs (later on mips device) fine:

CC_FOR_TARGET=mips-openwrt-linux-gcc GOPATH=/tmp/go STAGING_DIR=$HOME/openwrt/staging_dir PATH=$HOME/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin:$PATH CGO_ENABLED=1 GOOS=linux GOARCH=mips GOMIPS=r2softfloat ./go build -a -ldflags="-linkmode external -extld=mips-openwrt-linux-gcc" -o $HOME/main $HOME/main.go

main.go:

package main

import "fmt"

/*
#include <stdlib.h>
*/
import "C"

func Random() int {
    return int(C.random())
}

func Seed(i int) {
    C.srandom(C.uint(i))
}

func main() {
    Seed(10);
    fmt.Printf("Nice random number: %v...\n", Random());
}

However building a simple plugin (from https://golang.org/pkg/plugin/ does not):

CC_FOR_TARGET=mips-openwrt-linux-gcc GOPATH=/tmp/go STAGING_DIR=$HOME/openwrt/staging_dir PATH=$HOME/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin:$PATH CGO_ENABLED=1 GOOS=linux GOARCH=mips GOMIPS=r2softfloat ./go build -a -buildmode=plugin -ldflags="-linkmode external -extld=mips-openwrt-linux-gcc" -o $HOME/main $HOME/main.go

I've tried also with buildmode shared, c-shared, but I'm getting a similar error:

-buildmode=plugin not supported on linux/mips

I've tried to patch the source by removing the check for MIPS with the hope that this will work:

src/cmd/go/build.go

-       } else {
-           switch platform {
-           case "linux/amd64", "linux/arm", "linux/arm64", "linux/386",
--              "android/amd64", "android/arm", "android/arm64", "android/386":
-+              "android/amd64", "android/arm", "android/arm64", "android/386", "linux/mips", "linux/mipsel":
-           default:
-               fatalf("-buildmode=plugin not supported on %s\n", platform)
-           }

Trying to rebuild Golang compiler and my test app I ended up with another error:

# runtime/internal/sys
flag provided but not defined: -dynlink

Next, I've tried to patch src/cmd/compile/internal/gc/main.go like this:

- // supportsDynlink reports whether or not the code generator for the given
- // architecture supports the -shared and -dynlink flags.
- func supportsDynlink(arch *sys.Arch) bool {
--  return arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.PPC64, sys.S390X)
-+  return arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.PPC64, sys.S390X, sys.MIPS)
- }
- 

But then I get the next error:

# runtime/internal/sys
<unknown line number>: internal compiler error: arch mips not implemented

So, I gave up at this stage. I guess there is something more missing.

The worst thing here is that even -buildmode=shared doesn't work, so I cannot provide go libraries to C programs.

@vstefanovic are you aware of those limitations of the mips port?

Currently I can build golang app (with embedding C too) statically or dynamically, but no -buildmode like shared, c-shared or plugin works for GOOS=linux. Are there any known issues that prevent those on mips?

Thanks!

Hi @juliandroid, indeed, these three modes aren't supported for mips.
c-shared is mostly done, it will be submitted after soft-float gets merged;
shared and plugin mode are on the todo list.

Thanks Vladimir! Good to know those are on the todo list!

@vstefanovic I'm curious about plugin support and shared mode, are there any good news? :)

Hi Julian,
well, the news is that @milanknezevic is about to start working on the plugin mode.

@vstefanovic I'm also curious about plugin support for mips, are there any good news now? thanks a lot~

@vstefanovic is there a milestone for buildmode=c-shared support on linux/mips?

@WK-LLP @paride Both buildmode=c-shared and buildmode=plugin are currently work in progress. I hope they will be ready for 1.12 release.

Seems it was not integrated in 1.12 (go1.12.5), is it still work in progress ?

@bradfitz @MIPSbkirby @ianlancetaylor any update?

No updates I've seen. Plus they'd almost certainly be mentioned here if there were any.

@bradfitz BTW, buildmode=-pie support in linux/mips?

I'm not the domain expert here but I also don't see any update from the last time where it was declared that it didn't work. Try it and confirm, though.

@daixiang0 @bradfitz I've just rebased changes for buildmode=c-shared. You can find them here. Also, I have changes for buildmode=pie and buildmode=plugin but they are dependent on c-shared changes so I'm waiting for them to be accepted.

@milanknezevic happy to hear it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dominikh picture dominikh  路  3Comments

natefinch picture natefinch  路  3Comments

OneOfOne picture OneOfOne  路  3Comments

jayhuang75 picture jayhuang75  路  3Comments

Miserlou picture Miserlou  路  3Comments