-
Notifications
You must be signed in to change notification settings - Fork 18k
Cross-compiling with cgo for ARMv7 fails #13377
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
Comments
You should be able to address this without modifying Go by setting the CC environment variable when running the go tool. I don't know of any simple way that the Go distribution can get this right for all the possible ARM cases. |
We are setting the CC environment variable. Go strips off all of the arm-phytec-linux-gnueabi-gcc -march=armv7-a -marm -mthumb-interwork Here is the output when Go compiles What we get when Go compiles cgo (go WORK=/tmp/go-build861803713 runtime/cgoIn file included from include <gnu/stubs-soft.h>
compilation terminated. Go used the compiler we specified, but replaced all of the command line Greg Strange mail 1511 6th Ave Suite 400, Seattle, WA 98101 This email and any files transmitted with it are confidential. Unauthorized On Tue, Nov 24, 2015 at 10:31 AM, Ian Lance Taylor <[email protected]
|
You may also need to set CGO_CFLAGS for the compiler flags. Actually, though, the behaviour you are describing sounds like a bug. Or else a misunderstanding on my part. |
Thanks. You are right. Setting CGO_CFLAGS corrects the compiler flag The resulting code does not run because it is trying to use the wrong Greg Strange mail 1511 6th Ave Suite 400, Seattle, WA 98101 This email and any files transmitted with it are confidential. Unauthorized On Tue, Nov 24, 2015 at 11:26 AM, Ian Lance Taylor <[email protected]
|
I'd recommend using external linking, if you are not using that already
(add -ldflags="-linkmode=external -v" to your go build invocation).
|
When you run your compiler directly, does it use the correct dynamic linker? Go is not going to override that. As Michael says, make sure you are using external linking, although that should be the default since you are using cgo. |
Yes, when I compile directly (C code only), the resulting program uses Setting linkmode=external seems to make no difference. Greg Strange mail 1511 6th Ave Suite 400, Seattle, WA 98101 This email and any files transmitted with it are confidential. Unauthorized On Tue, Nov 24, 2015 at 1:40 PM, Ian Lance Taylor [email protected]
|
That's pretty strange. Can you add -x to the build command and stick the On 25 November 2015 at 11:01, gjstrange [email protected] wrote:
|
The problem is probably that when invoking the external linker, cmd/link
failed to to specify its float abi is hard, so gcc uses the normal dynamic
interpreter.
|
Yea sure. Here it is https://gist.github.com/gjstrange/5243afe5b16dc8836db8 Greg Strange mail 1511 6th Ave Suite 400, Seattle, WA 98101 This email and any files transmitted with it are confidential. Unauthorized On Tue, Nov 24, 2015 at 2:12 PM, Michael Hudson-Doyle <
|
Shouldn't gcc, if compiled against hard float use this as a default? Maybe Did someone ask for the output of gcc -v to see what it's default are ? On Wed, 25 Nov 2015, 09:41 Minux Ma [email protected] wrote:
|
On 25 November 2015 at 11:45, gjstrange [email protected] wrote:
I think I've seen this behaviour too, but it wasn't important to me at the |
Actually I put the linker flags into CGO_LDFLAGS environment variable and Greg Strange mail 1511 6th Ave Suite 400, Seattle, WA 98101 This email and any files transmitted with it are confidential. Unauthorized On Tue, Nov 24, 2015 at 2:58 PM, Michael Hudson-Doyle <
|
Another workaround is to create a gcc wrapper that
contains the necessary fp abi flags, and set that
to $CC.
|
Do you happen to have a small example that shows how to do the workaround you mention? |
See $GOROOT/misc/ios/clangwrap.sh for an example script
that is used as $CC during iOS go build.
It's for iOS, but it should give you the idea.
|
This problem was also seen when build BusyBox from a Yocto toolchain using the SDK installed externally. The problem stemmed from the fact that the BusyBox build used the $CROSS_COMPILE and the $CFLAGS environment variables and di not access the $CC variable which had the switches: -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT With busybox we could add the additional CFLAGS switches via the menuconfig or we could modify the Environment.sh script and added the flags to the $CFLAGS variable. Hope this helps someone as we could not find an answer! Nev |
We are using Go on a ARM335x/Linux board very similar to the BeagleBone black, but the cross compile fails if it involves mixed C and Go code and cgo.
Background: Using go version 1.5.1. Host is Ubunutu 15.04 running in a VM on a Mac. Target settings:
GOOS= linux
GOARCH=arm
GOARM=7
CC, CXX, etc. are also set to the cross compiler gcc tools.
The error reported is:
`# runtime/cgo
In file included from /opt/yogurt/AM335x-PD15.1.1/sysroots/cortexa8t2hf-vfp-neon-phytec-linux-gnueabi/usr/include/features.h:389:0,
from /opt/yogurt/AM335x-PD15.1.1/sysroots/cortexa8t2hf-vfp-neon-phytec-linux-gnueabi/usr/include/errno.h:28,
from /usr/local/go/src/runtime/cgo/cgo.go:50:
/opt/yogurt/AM335x-PD15.1.1/sysroots/cortexa8t2hf-vfp-neon-phytec-linux-gnueabi/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory
include <gnu/stubs-soft.h>
compilation terminated.`
Some research showed that the problem stemmed from incorrect compiler flags. The ARMv7 processor (TI AM3359 Cortex A8 in this case), uses hardware hardware floating point, so the following flags need to be set:
"-mthumb-interwork", "-mfloat-abi=hard", "-mfpu=neon"
It also should link against /lib/ld-linux-armhf.so.3, but links against /lib/ld-linux.so.3 instead.
We have a personal branch of Go now that fixes the problem, though we are new to Go, so the change may not be well done.
The text was updated successfully, but these errors were encountered: