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: accept -Wl,-R,path #32167

Closed
ng-0 opened this issue May 21, 2019 · 9 comments
Closed

cmd/go: accept -Wl,-R,path #32167

ng-0 opened this issue May 21, 2019 · 9 comments
Assignees
Milestone

Comments

@ng-0
Copy link
Contributor

@ng-0 ng-0 commented May 21, 2019

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

$ go112 version
go version go1.12.4 netbsd/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go112 env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ng0/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="netbsd"
GOOS="netbsd"
GOPATH="/home/ng0/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/pkg/go112"
GOTMPDIR=""
GOTOOLDIR="/usr/pkg/go112/pkg/tool/netbsd_amd64"
GCCGO="gccgo"
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-build011870882=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given any code which involves:

#cgo LDFLAGS: -Wl,-R/usr/pkg/lib

or similar,

go build command-line-arguments: invalid flag in #cgo LDFLAGS: -Wl,-R/usr/pkg/lib

is returned.

What did you expect to see?

A successful treatment of the LDFLAGS.

I don't know if this is a feature limitation or a bug, but given that I need to invoke
LDFLAGS this way for out-of-pkgsrc builds usually, I consider this a bug.

What did you see instead?

See above.

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

@AlexRouSg AlexRouSg commented May 21, 2019

cgo flags are white listed, see https://golang.org/cmd/cgo/

For security reasons, only a limited set of flags are allowed, notably -D, -I, and -l. To allow additional flags, set CGO_CFLAGS_ALLOW to a regular expression matching the new flags. To disallow flags that would otherwise be allowed, set CGO_CFLAGS_DISALLOW to a regular expression matching arguments that must be disallowed. In both cases the regular expression must match a full argument: to allow -mfoo=bar, use CGO_CFLAGS_ALLOW='-mfoo.*', not just CGO_CFLAGS_ALLOW='-mfoo'. Similarly named variables control the allowed CPPFLAGS, CXXFLAGS, FFLAGS, and LDFLAGS.

cc @ianlancetaylor incase the flag could be added to the list

@ng-0

This comment has been minimized.

Copy link
Contributor Author

@ng-0 ng-0 commented May 21, 2019

I see. Okay, let me expand my argument for the specific LDFLAGS, this is I believe
the official statement/explanation for this in NetBSD: http://www.netbsd.org/docs/elf.html

Reference code, if relevant (debug quality, and I've just picked up go):
https://c.n0.is/go-hello-c/file/tip/v2/main.go

@ianlancetaylor ianlancetaylor changed the title LDFLAGS in cgo for go 1.12.4 issue cmd/go: accept -Wl,-R,path May 21, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone May 21, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 21, 2019

Yes, we should accept that. We currently accept -Wl,-rpath but not -Wl,-R.

If anybody wants to send a patch, the place is cmd/go/internal/work/security.go.

@gopherbot Please open backport to 1.12.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented May 21, 2019

Backport issue(s) opened: #32168 (for 1.12).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@ng-0

This comment has been minimized.

Copy link
Contributor Author

@ng-0 ng-0 commented May 21, 2019

Thanks for looking into this.

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

@AlexRouSg AlexRouSg commented May 21, 2019

@ng-0 you want to do the change?

https://golang.org/doc/contribute.html

@ng-0

This comment has been minimized.

Copy link
Contributor Author

@ng-0 ng-0 commented May 21, 2019

Yes (in fact I've looked into this already). There could be some delay for other tasks take priority.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented May 21, 2019

Change https://golang.org/cl/178397 mentions this issue: cmd/go: accept -Wl,-R/path/

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jun 9, 2019

Change https://golang.org/cl/181437 mentions this issue: [release-branch.go1.12] cmd/go: accept -Wl,-R/path/

gopherbot pushed a commit that referenced this issue Jun 10, 2019
This is a backport of CL 178397.

Updates #32167
Fixes #32168

Change-Id: Idb16a01d56814ea09ad277798787355dc6a3121f
Reviewed-on: https://go-review.googlesource.com/c/go/+/181437
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.