Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: -buildmode=plugin not supported on linux/mips #21222

Open
juliandroid opened this issue Jul 30, 2017 · 26 comments
Open

plugin: -buildmode=plugin not supported on linux/mips #21222

juliandroid opened this issue Jul 30, 2017 · 26 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@juliandroid
Copy link

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"

@bradfitz bradfitz added this to the Go1.10 milestone Jul 30, 2017
@bradfitz
Copy link
Contributor

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

/cc @MIPSbkirby @ianlancetaylor

@bradfitz bradfitz added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Jul 30, 2017
@juliandroid
Copy link
Author

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

@bradfitz
Copy link
Contributor

@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?

@juliandroid
Copy link
Author

juliandroid commented Jul 30, 2017

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
Copy link
Contributor

I'm pretty sure you need CC_FOR_TARGET. Three examples are in the Dockerfiles under:
https://github.com/golang/build/blob/master/env/crosscompile/
like:
https://github.com/golang/build/blob/master/env/crosscompile/linux-s390x-stretch/Dockerfile

@juliandroid
Copy link
Author

@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.

@juliandroid
Copy link
Author

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

@juliandroid
Copy link
Author

@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!

@vstefanovic
Copy link
Member

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.

@juliandroid
Copy link
Author

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

@cherrymui cherrymui modified the milestones: Go1.10, Unplanned Dec 7, 2017
@juliandroid
Copy link
Author

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

@vstefanovic
Copy link
Member

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

@WK-LLP
Copy link

WK-LLP commented May 2, 2018

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

@paride
Copy link

paride commented May 2, 2018

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

@milanknezevic
Copy link
Contributor

@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.

@TMesot
Copy link

TMesot commented Jun 5, 2019

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

@daixiang0
Copy link

@bradfitz @MIPSbkirby @ianlancetaylor any update?

@bradfitz
Copy link
Contributor

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

@daixiang0
Copy link

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

@bradfitz
Copy link
Contributor

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.

@milanknezevic
Copy link
Contributor

@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.

@daixiang0
Copy link

@milanknezevic happy to hear it!

jefferyto added a commit to jefferyto/openwrt-packages that referenced this issue Jan 8, 2020
This adds support to compile host and target Go as position-independent
executables.

Host Go will have PIE enabled if Go supports PIE on the host platform.

Target Go will have PIE enabled if Go supports PIE on the target
platform and CONFIG_PKG_ASLR_PIE is selected.

Go 1.13 supports PIE for x86 and arm targets; mips support is in
progress[1].

[1]: golang/go#21222 (comment)

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
jefferyto added a commit to jefferyto/openwrt-packages that referenced this issue Jan 14, 2020
This adds support to compile position-independent executables for
packages that use golang-package.mk.

Go packages will have PIE enabled if:
* Go supports PIE on the target platform;
* CONFIG_PKG_ASLR_PIE is selected; and
* PKG_ASLR_PIE (for the package) is not set to 0

Go 1.13 supports PIE for x86 and arm targets; mips support is in
progress[1].

[1]: golang/go#21222 (comment)

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
@alexsanderp

This comment was marked as spam.

@alexsanderp

This comment was marked as duplicate.

@hyperiris

This comment was marked as duplicate.

@adonespitogo
Copy link

Are there technical challenges that is preventing this feature to be implemented in mips?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests