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/ld: -X flag broken #8806

Closed
josharian opened this issue Sep 25, 2014 · 11 comments
Closed

cmd/ld: -X flag broken #8806

josharian opened this issue Sep 25, 2014 · 11 comments
Milestone

Comments

@josharian
Copy link
Contributor

$ cd test
$ ./run
fail: ./linkx.go


Or more directly:

$ cat x.go
package main

var s string

func main() {
    println(s)
}
$ go build -ldflags="-X main.s hi" x.go
 command-line-arguments
missing Go type information for global symbol: main.s size 16


See also issue #4139.
@josharian
Copy link
Contributor Author

Comment 1:

Labels changed: added release-go1.4, repo-main.

@gopherbot
Copy link
Contributor

Comment 2:

CL https://golang.org/cl/142680043 mentions this issue.

@gopherbot
Copy link
Contributor

Comment 3:

CL https://golang.org/cl/144630044 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Sep 26, 2014

Comment 4:

Owner changed to @rsc.

Status changed to Started.

@gopherbot
Copy link
Contributor

Comment 5:

CL https://golang.org/cl/145420043 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Sep 26, 2014

Comment 6:

This issue was closed by revision df781cc.

Status changed to Fixed.

@bgentry
Copy link
Contributor

bgentry commented Sep 26, 2014

Comment 7:

I'm actually still seeing an issue here. Am I doing something wrong, or is this not
actually fixed?
➜  go build -ldflags="-X BuildTag TEST" x.go   
# command-line-arguments
missing Go type information for global symbol: BuildTag size 16
➜  go version
go version devel +5450f6b00f00 Fri Sep 26 13:50:53 2014 -0400 darwin/amd64
➜  cat x.go
package main
import "fmt"
var (
    BuildTag = "dev"
)
func main() {
    fmt.Println(BuildTag)
}

@bgentry
Copy link
Contributor

bgentry commented Sep 26, 2014

Comment 8:

Ugh, spoke too soon. My flag should have been `-X main.BuildTag TEST`. Sorry about the
noise.

@josharian
Copy link
Contributor Author

Comment 9:

Perhaps the linker should warn when the -X key doesn't match anything. Feel free to file
an issue for that if you'd like.

@bgentry
Copy link
Contributor

bgentry commented Sep 26, 2014

Comment 10:

Ok, there is in fact still a bug here (or at least a change in behavior since 1.3). When
you specify an overwrite for a package your build doesn't actually use, there is a type
error. The same set of commands and files builds fine under 1.3, and also worked on tip
until earlier this week when the changes that broke the -X flag were committed.
➜  cat ~/go/src/github.com/bgentry/gotag/gotag.go 
package gotag
var (
    BuildTag = "dev"
)
➜  cat ~/go/src/github.com/bgentry/gotag/sub/sub.go
package main
import "fmt"
func main() {
    fmt.Println("hello")
}
==============
The behavior on 1.3.2:
➜  go version                                                   
go version go1.3.2 darwin/amd64
➜  go build -ldflags="-X github.com/bgentry/gotag.BuildTag TEST"
github.com/bgentry/gotag/sub
(no error)
==============
Now, on tip:
➜  go version
go version devel +5450f6b00f00 Fri Sep 26 13:50:53 2014 -0400 darwin/amd64
➜  go build -ldflags="-X github.com/bgentry/gotag.BuildTag TEST"
github.com/bgentry/gotag/sub
# github.com/bgentry/gotag/sub
missing Go type information for global symbol: github.com/bgentry/gotag.BuildTag size 16

@josharian
Copy link
Contributor Author

Comment 11:

Thanks, Blake. I filed issue #8820 and issue #8821 for these. (The tests around linking
are in flux right now, so it'll may be easier to let that stabilize before fixing.)

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
This fixes the test/linkx.go test, which does not run by default.
(Issue 4139 is about fixing that.)

Fixes golang#8806.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/145420043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
This fixes the test/linkx.go test, which does not run by default.
(Issue 4139 is about fixing that.)

Fixes golang#8806.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/145420043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
This fixes the test/linkx.go test, which does not run by default.
(Issue 4139 is about fixing that.)

Fixes golang#8806.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/145420043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
This fixes the test/linkx.go test, which does not run by default.
(Issue 4139 is about fixing that.)

Fixes golang#8806.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/145420043
@rsc rsc removed their assignment Jun 23, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants