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/go: error when enable cgo and static link with build flag '-mod=vendor' #27667

Closed
sanguohot opened this issue Sep 14, 2018 · 7 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@sanguohot
Copy link

sanguohot commented Sep 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 linux/amd64.

Does this issue reproduce with the latest release?

of course it is.

What operating system and processor architecture are you using (go env)?

NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

What did you do?

this is my simple test code

package main

import (
	"fmt"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/crypto/secp256k1"
	"log"
)

func main()  {
	bytes, err := hexutil.Decode("0x71b9732fa43b52d8c9085c053064b55dccc8785da7f12b3812787ee3def367ba0a8796dafb76fd5a146c226036092b7f5dd59feecb92776f7bb2cf2a48594ae201")
	if err != nil {
		log.Fatal(err)
	}
	pub, err := secp256k1.RecoverPubkey(crypto.Keccak256Hash([]byte("hello")).Bytes(), bytes)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(hexutil.Encode(pub))
}

then I ran the command go build --ldflags "-linkmode external -extldflags -static" -a -o main -v -mod=vendor secp256k1.test.go

What did you expect to see?

well, not error and output with the executable file main

What did you see instead?

error and it still go on but with no main file output at the end.

> runtime/debug
> github.com/ethereum/go-ethereum/common
> github.com/ethereum/go-ethereum/common/math
> runtime/cgo
> github.com/ethereum/go-ethereum/crypto/secp256k1
> # github.com/ethereum/go-ethereum/crypto/secp256k1
> ../vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/curve.go:42:44: fatal error: libsecp256k1/include/secp256k1.h: No such file or directory
> compilation terminated.
> github.com/ethereum/go-ethereum/rlp
> log

by the way, if I do not add the flag -mod=vendor , it seems ok.

@sanguohot
Copy link
Author

no body take a look at this issue?

@dmitshur dmitshur changed the title error when enable cgo and static link with build flag '-mod=vendor' cmd/go: error when enable cgo and static link with build flag '-mod=vendor' Sep 17, 2018
@dmitshur dmitshur added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 17, 2018
@dmitshur dmitshur added this to the Go1.12 milestone Sep 17, 2018
@dmitshur
Copy link
Contributor

dmitshur commented Sep 17, 2018

You're saying that go build --ldflags "-linkmode external -extldflags -static" -a -o main -v -mod=vendor secp256k1.test.go produces an error above, but there's no error if you take out -mod=vendor.

What happens if you take out all the other flags, and run go build -mod=vendor secp256k1.test.go?

As is, it's hard to tell if the issue is within Go, or if there's a problem with the go-ethereum source code (it's also not clear which commit was being used). To make progress, we'll need to narrow it down into a smaller, reproducible test case (ideally, one that doesn't depend on an external project).

If you're unsure how to do that, I'd suggest first reporting this issue in the go-ethereum project's issue tracker. If they can confirm it's not an issue in that codebase, we can investigate further.

/cc @bcmills

@dmitshur dmitshur added the GoCommand cmd/go label Sep 17, 2018
@sanguohot
Copy link
Author

sanguohot commented Sep 18, 2018

@dmitshur
My test result is the same with the latest go-ethereum commit.
It is very easy to replay with the following commands:

> root@sanguohot:/opt# rm -rf test
> root@sanguohot:/opt# mkdir test
> root@sanguohot:/opt# cp ./medichain/test/secp256k1.test.go test/
> root@sanguohot:/opt# cd test/
> root@sanguohot:/opt/test# go mod init github.com/sanguohot/test
> go: creating new go.mod: module github.com/sanguohot/test
> root@sanguohot:/opt/test# go mod tidy && go mod vendor
> go: finding github.com/ethereum/go-ethereum/common/hexutil latest
> go: finding github.com/ethereum/go-ethereum/crypto latest
> go: finding github.com/ethereum/go-ethereum/crypto/secp256k1 latest
> go: finding github.com/ethereum/go-ethereum/common latest
> go: finding github.com/btcsuite/btcd/btcec latest
> go: finding github.com/btcsuite/btcd latest
> go: finding gopkg.in/check.v1 latest
> go: finding github.com/davecgh/go-spew/spew latest
> go: finding github.com/kr/text v0.1.0
> go: finding github.com/kr/pty v1.1.1
> go: downloading github.com/kr/text v0.1.0
> root@sanguohot:/opt/test# go build --ldflags "-linkmode external -extldflags -static" -a -o main -mod=vendor
> # github.com/ethereum/go-ethereum/crypto/secp256k1
> vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/curve.go:42:44: fatal error: libsecp256k1/include/secp256k1.h: No such file or directory
> compilation terminated.
> root@sanguohot:/opt/test# ll
> total 24
> drwxr-xr-x  3 root root 4096 Sep 18 09:45 ./
> drwxr-xr-x 11 root root 4096 Sep 18 09:44 ../
> -rw-r--r--  1 root root  314 Sep 18 09:45 go.mod
> -rw-r--r--  1 root root 1180 Sep 18 09:45 go.sum
> -rw-r--r--  1 root root  567 Sep 18 09:44 secp256k1.test.go
> drwxr-xr-x  3 root root 4096 Sep 18 09:45 vendor/
> root@sanguohot:/opt/test# go build --ldflags "-linkmode external -extldflags -static" -a -o main
> root@sanguohot:/opt/test# ls
> go.mod  go.sum  main  secp256k1.test.go  vendor

But your suggestion is good, it may be the go-ethereum's problem.
I will report an issue to their project.

@dmitshur
Copy link
Contributor

But your suggestion is good, it may be the go-ethereum's problem.
I will report an issue to their project.

Sounds good. Feel free to link it to this issue so we can keep track of progress.

Also, did you see this question:

What happens if you take out all the other flags, and run go build -mod=vendor secp256k1.test.go?

@sanguohot
Copy link
Author

sanguohot commented Sep 19, 2018

@dmitshur There is no difference with go build -mod=vendor secp256k1.test.go.
I test it in the issue ethereum/go-ethereum:17700

@myitcv
Copy link
Member

myitcv commented Sep 26, 2018

This is almost certainly a dup of #26366. The thread gives some good background on what's happening here, especially #26366 (comment).

If you want to "vendor" the entire module then #26366 (comment) gives links to how to do that.

@myitcv myitcv closed this as completed Sep 26, 2018
@sanguohot
Copy link
Author

This is almost certainly a dup of #26366. The thread gives some good background on what's happening here, especially #26366 (comment).

If you want to "vendor" the entire module then #26366 (comment) gives links to how to do that.

@myitcv Thank you very much, it works to me.
I hope there will be go mod modvendor as you say.

@golang golang locked and limited conversation to collaborators Sep 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants