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: unable to pass "--static" to pkgconfig #23875

Closed
AlexRouSg opened this issue Feb 16, 2018 · 14 comments

Comments

@AlexRouSg
Copy link
Contributor

commented Feb 16, 2018

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

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2018

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

@AlexRouSg

This comment has been minimized.

Copy link
Contributor Author

commented Feb 16, 2018

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

@ianlancetaylor ianlancetaylor added this to the Go1.10.1 milestone Feb 16, 2018

@ianlancetaylor ianlancetaylor changed the title cmd/cgo: Unable to pass "--static" to pkgconfig cmd/cgo: unable to pass "--static" to pkgconfig Feb 16, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2018

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

@AlexRouSg

This comment has been minimized.

Copy link
Contributor Author

commented Feb 16, 2018

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

for len(pkgs) > 0 && strings.HasPrefix(pkgs[0], "--") {

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2018

That's a loop, though.

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

@AlexRouSg

This comment has been minimized.

Copy link
Contributor Author

commented Feb 16, 2018

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

This comment has been minimized.

Copy link

commented Feb 17, 2018

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

@ptoomey3

This comment has been minimized.

Copy link

commented Feb 20, 2018

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

This comment has been minimized.

Copy link
Member

commented Feb 20, 2018

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

This comment has been minimized.

Copy link

commented Feb 20, 2018

@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

This comment has been minimized.

Copy link
Contributor

commented Feb 20, 2018

Reopening for 1.10.1.

@andybons

This comment has been minimized.

Copy link
Member

commented Mar 27, 2018

CL 94896 OK for Go 1.10.1

@gopherbot

This comment has been minimized.

Copy link

commented Mar 27, 2018

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

@gopherbot

This comment has been minimized.

Copy link

commented Mar 28, 2018

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

gopherbot pushed a commit that referenced this issue Mar 29, 2018
[release-branch.go1.9] cmd/go: permit pkg-config flags in any argumen…
…t position

Fixes #23875

Change-Id: I503af71f44d11cd6b787fef100246b55735614a0
Reviewed-on: https://go-review.googlesource.com/94896
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-on: https://go-review.googlesource.com/103155
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
gopherbot pushed a commit that referenced this issue Mar 29, 2018
[release-branch.go1.10] cmd/go: permit pkg-config flags in any argume…
…nt position

Fixes #23875

Change-Id: I503af71f44d11cd6b787fef100246b55735614a0
Reviewed-on: https://go-review.googlesource.com/94896
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-on: https://go-review.googlesource.com/102779
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

@andybons andybons closed this Mar 29, 2018

@golang golang locked and limited conversation to collaborators Mar 29, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants
You can’t perform that action at this time.