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

cmd/cgo: cgo breaks multiple cgo packages linked with libgcc #7604

Open
gopherbot opened this issue Mar 21, 2014 · 5 comments
Open

cmd/cgo: cgo breaks multiple cgo packages linked with libgcc #7604

gopherbot opened this issue Mar 21, 2014 · 5 comments
Labels
Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@gopherbot
Copy link

by jim.deng:

What does 'go version' print?
go version devel +358e2b416518 Wed Mar 19 09:00:58 2014 -0700 darwin/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Create a source tree that can be downloaded below:

  src/main/main.go   http://play.golang.org/p/3y44TXNfEf
  src/hello/hello.go   http://play.golang.org/p/iJZL_tuvDm
  src/world/world.go http://play.golang.org/p/V7m4penOiv

2. Install android standalone ndk 49d following 4/ Invoking the compiler (the easy way):

  http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html
  https://developer.android.com/tools/sdk/ndk/index.html

3.  Run  the following command to build
export PATH=/path/to/android/toolchain-r9d/bin:$PATH

CGO_CFLAGS='-I /Users/jim_deng/workspace/android/toolchain-r9d/include -march=armv7-a
-mfloat-abi=softfp' \ 
CGO_LDFLAGS='-Wl,--fix-cortex-a8' \ 
CC=arm-linux-androideabi-gcc \ 
CXX=arm-linux-androideabi-g++ \ 
GOOS=linux \ 
GOARCH=arm \ 
CGO_ENABLED=1 \ 
go build -tags android -x

What happened?

Got multiple definition of '__aeabi_dcmpge' errors ...
http://hastebin.com/sodekeqibi.mel

What should have happened instead?

go build should succeed

Please provide any additional information below.

* Background discussion: https://groups.google.com/forum/#!topic/golang-nuts/73NvFzLZpSY
* android tool chain cannot be linked with -lpthread.  I have to patch cgo not to add
-lpthread in the linker.
--- a/src/pkg/runtime/cgo/cgo.go        Wed Mar 19 09:00:58 2014 -0700
+++ b/src/pkg/runtime/cgo/cgo.go        Thu Mar 20 17:31:16 2014 -0700
@@ -14,7 +14,7 @@
-#cgo linux LDFLAGS: -lpthread
+#cgo linux,!android LDFLAGS: -lpthread
@minux
Copy link
Member

minux commented Mar 25, 2014

Comment 1:

I will take a look.

Labels changed: added release-go1.3, repo-main.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Apr 3, 2014

Comment 2:

Labels changed: added release-go1.3maybe, removed release-go1.3.

@rsc
Copy link
Contributor

rsc commented May 9, 2014

Comment 3:

I don't know what's wrong here. Either gcc is generating objects with duplicate symbols
or the Go linker is misinterpreting the symbols as global when they are really static
(more likely). External linking might help but I thought that was already in place.
If you write your own wrapper for __aeabi_dcmpge and make both places refer to that
wrapper I think everything will be fine. For example:
/*
#include <stdio.h>
void mydcmp(void) {
    __aeabi_dcmpge(0, 0);
}
static void Print() {
        mydcmp();
        printf("hello\n");
}
*/
import "C"
and
/*
#include <stdio.h>
void mydcmp(void);
static void Print() {
        mydcmp();
        printf("world\n");
}
*/
import "C"

Labels changed: added release-none, suggested, removed release-go1.3maybe.

@gopherbot gopherbot added accepted Suggested Issues that may be good for new contributors looking for work to do. labels May 9, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@lcmmhcc

This comment was marked as off-topic.

@ianlancetaylor

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

5 participants