golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.76k stars 17.64k forks source link

cmd/cgo: unable to pass "--static" to pkgconfig #23875

Closed AlexRouSg closed 6 years ago

AlexRouSg commented 6 years ago

Please answer these questions before submitting your issue. Thanks!

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

1.10

Does this issue reproduce with the latest release?

Yes

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

Irrevelent

What did you do?

If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on play.golang.org is best.

I'm trying to build a package that static links C dependencies using pkg-config to set the flags. Before the cgo security update for go get (1.9.3), doing #cgo pkg-config: --static SDL2 would tell pkg-config to use the flags for static linking. As --static is a arg passed to pkg-config not the C compiler or linker, there is now no easy way to pass --static to pkg-config.

What did you expect to see?

Build succeed

What did you see instead?

Invalid pkg-config package name: --static

ianlancetaylor commented 6 years ago

This is with the final released version of 1.10? A fix for that went in quite late in the process.

AlexRouSg commented 6 years ago

Yup I just downloaded it from golang.org a few minutes before the report

ianlancetaylor commented 6 years ago

I can't recreate the problem. Can you show a complete test case? Thanks.

AlexRouSg commented 6 years ago

After some checking I found out what's wrong. I'm setting --static in multiple files. While exec is only allowing the first arg in the list to contain -- https://github.com/golang/go/blob/f7c2a71632854050d9fe6de115c6c346fcd9774c/src/cmd/go/internal/work/exec.go#L939

ianlancetaylor commented 6 years ago

That's a loop, though.

Assuming this is still a problem for you, I'd still like to see a test case. Thanks.

AlexRouSg commented 6 years ago

Test case is just any 2+ files with --static in the pkgconfig args.

main.go

package main

/*
    #cgo pkg-config: --static SDL2
*/
import "C"

func main() {

}

foo.go

package main

/*
    #cgo pkg-config: --static SDL2
*/
import "C"

func foo() {

}
gopherbot commented 6 years ago

Change https://golang.org/cl/94896 mentions this issue: cmd/go: permit pkg-config flags in any argument position

ptoomey3 commented 6 years ago

Hmm...I'm having a similar problem (same error), but maybe it is different enough to be worth describing. I have a project that relies on https://github.com/flier/gohs (golang wrapper around an Intel developed C library called hyperscan). My usage requires that I build the tool that relies on gohs inside of a local directory not related to my GOPATH. So, to make that work I have a script that does something like:

gopath=$(cd "$installdir" && pwd)
cd "$builddir"
GOPATH=$gopath go build

This worked fine in the past, but now I'm getting:

go build github.com/github/myproject/vendor/github.com/flier/gohs/hyperscan: invalid pkg-config package name: --static

If I do a go get github.com/flier/gohs and then do a go build github.com/flier/gohs/hyperscan it builds fine. But, if I try to do the build in a "non-standard" directory I get the whitelist error. Would you imagine the fix in https://go-review.googlesource.com/#/c/94896/ would fix what I'm seeing? Let me know if I can provide any extra information to help produce a test case.

bradfitz commented 6 years ago

Hmm...I'm having a similar problem (same error), but maybe it is different enough to be worth describing.

If it's different enough to be worth describing, it's worth being in its open bug (or at least on a bug that's not closed and thus not tracked).

ptoomey3 commented 6 years ago

@bradfitz - Will do. I only added it hear since it wasn't clear to me if my issue was obviously addressed by the patch that closed this issue already.

ianlancetaylor commented 6 years ago

Reopening for 1.10.1.

andybons commented 6 years ago

CL 94896 OK for Go 1.10.1

gopherbot commented 6 years ago

Change https://golang.org/cl/102779 mentions this issue: [release-branch.go1.10] cmd/go: permit pkg-config flags in any argument position

gopherbot commented 6 years ago

Change https://golang.org/cl/103155 mentions this issue: [release-branch.go1.9] cmd/go: permit pkg-config flags in any argument position