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/internal/work/security.go: invalid flag in #cgo LDFLAGS: -Wl,-rpath,. #70924

Closed
t0rr3sp3dr0 opened this issue Dec 19, 2024 · 7 comments
Closed
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@t0rr3sp3dr0
Copy link
Contributor

t0rr3sp3dr0 commented Dec 19, 2024

Go version

go version go1.23.3 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/pedro/Library/Caches/go-build'
GOENV='/Users/pedro/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/pedro/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/pedro/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/pedro/sdk/go1.23.3'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/pedro/sdk/go1.23.3/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/pedro/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/pedro/Documents/git/sapsigner/impl/emu/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_3/sh8y1_5d07q_5xhk9k8mncs80000gn/T/go-build4238436678=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Run go build main.go in macOS with the following program.


  • main.go
package main

// #cgo LDFLAGS: -Wl,-rpath,.
import "C"

func main() {}

### What did you see happen?

```console
% go build -v main.go
command-line-arguments
command-line-arguments: invalid flag in #cgo LDFLAGS: -Wl,-rpath,.

What did you expect to see?

% go build -v main.go
command-line-arguments
@t0rr3sp3dr0
Copy link
Contributor Author

While looking for a workaround for #40559, I faced this problem. I don't see a reason why this shouldn't be allowed. This rpath instructs the loader for look for the libraries in the current working directory.

@t0rr3sp3dr0
Copy link
Contributor Author

t0rr3sp3dr0 commented Dec 19, 2024

Actually, any value for rpath that contains a single character will be denied. I'm not sure if this was intentional or not. This is the regex: -Wl,-rpath(-link)?[=,]([^,@\-][^,]+).

@ianlancetaylor
Copy link
Member

I don't see a problem with a path that is a single character. It would be fine to send a patch to change that. Thanks.

@t0rr3sp3dr0
Copy link
Contributor Author

@ianlancetaylor, should I extend the fix to other flags? -framework, -R, --just-symbols, -sectcreate, -syslibroot, and -undefined suffer from the same problem.

Proposed fixes:

- re(`-Wl,-framework,[^,@\-][^,]+`),
+ re(`-Wl,-framework,[^,@\-][^,]*`),
- re(`-Wl,-R,?([^@\-,][^,@]*$)`),
+ re(`-Wl,-R,?([^@\-,][^,@]*$)`),
- re(`-Wl,--just-symbols[=,]([^,@\-][^,@]+)`),
+ re(`-Wl,--just-symbols[=,]([^,@\-][^,@]*)`),
- re(`-Wl,-rpath(-link)?[=,]([^,@\-][^,]+)`),
+ re(`-Wl,-rpath(-link)?[=,]([^,@\-][^,]*)`),
- re(`-Wl,-sectcreate,([^,@\-][^,]+),([^,@\-][^,]+),([^,@\-][^,]+)`),
+ re(`-Wl,-sectcreate,([^,@\-][^,]*),([^,@\-][^,]*),([^,@\-][^,]*)`),
- re(`-Wl,-syslibroot[=,]([^,@\-][^,]+)`),
+ re(`-Wl,-syslibroot[=,]([^,@\-][^,]*)`),
- re(`-Wl,-undefined[=,]([^,@\-][^,]+)`),
+ re(`-Wl,-undefined[=,]([^,@\-][^,]*)`),

@ianlancetaylor
Copy link
Member

Sure, but don't mix that change with any other changes. Thanks.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/638035 mentions this issue: cmd/go/internal/work: allow single character values in -Wl, linker flags

@dr2chase dr2chase added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 21, 2024
@dmitshur dmitshur added this to the Go1.24 milestone Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants