Skip to content

cmd/go: go1.15.5 breaks LDFLAGS=-std=c++14 #42606

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

Closed
aykevl opened this issue Nov 14, 2020 · 4 comments
Closed

cmd/go: go1.15.5 breaks LDFLAGS=-std=c++14 #42606

aykevl opened this issue Nov 14, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@aykevl
Copy link

aykevl commented Nov 14, 2020

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

$ go version
go version go1.15.5 linux/amd64

Does this issue reproduce with the latest release?

Yes, with Go 1.15.5 released a few days ago.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ayke/.cache/go-build"
GOENV="/home/ayke/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ayke/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ayke:/home/ayke"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build201769525=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I put two files in a new directory.
main.go:

package main

// void hello(void);
import "C"

func main() {
	C.hello()
}

main.cpp:

#include <cstdio>

extern "C"
void hello(void) {
	printf("hello!\n");
}

And then I ran this code using

CGO_LDFLAGS=-std=c++14 go run .

What did you expect to see?

The following message should be printed:

hello!

This works in Go 1.15.4 at least. I've also tested some version of Go 1.14 in which it works.

What did you see instead?

go build runtime/cgo: invalid flag in go:cgo_ldflag: -std=c++14

It seems to me that -std=c++14 is a perfectly safe flag, I've been using it for quite some time.

I suspect #42562 is the cause.

@ALTree ALTree changed the title Go 1.15.5 breaks LDFLAGS=-std=c++14 cmd/go: go1.15.5 breaks LDFLAGS=-std=c++14 Nov 14, 2020
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 14, 2020
@ALTree
Copy link
Member

ALTree commented Nov 14, 2020

cc @ianlancetaylor

aykevl added a commit to tinygo-org/tinygo that referenced this issue Nov 14, 2020
@aykevl
Copy link
Author

aykevl commented Nov 14, 2020

It looks like I have a workaround.

deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Nov 14, 2020
@ianlancetaylor
Copy link
Contributor

Yes, my apologies. Because it was a security patch that was kept quiet until the release, it was hard to do proper widescale testing. The workaround is to copy CGO_LDFLAGS into CGO_LDFLAGS_ALLOW. This will be fixed in the next release.

Closing as a dup of #42567.

@aykevl
Copy link
Author

aykevl commented Nov 14, 2020

Oops, looks like I didn't properly search for duplicates first.
Thank you for the quick response!

@golang golang locked and limited conversation to collaborators Nov 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants