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/link: -X on a constant, type, or func doesn't report an error #47072
Comments
I don't think it's possible to override a constant at link time ( Variables on the other hand, do have a specific location that the linker can populate, hence how |
Oh, and I should also mention that types are also only compile-time, hence that restriction. And finally, top-level functions are immutable. |
Unless I'm mistaken, the original issue was saying that these cases silently failed, not that they should work, hence the expected behavior being error messages, but the actual behavior being a runnable binary. |
And indeed:
To show that the
|
@zikaeroh Got it. Thanks. I'm not sure it's actually possible for the linker to know what CC @cherrymui @thanm |
This would be a relatively straightforward change to make, but I would be a little concerned that there is a lot of code that already relies on the current behavior (which is to say, if the "-X" symbol is not present or not a variable, the option is silently ignored). In the current implementation, -X is silently ignored if:
It would seem weird to add a new error for "symbol not a variable" and not have errors for the other cases. |
if we are concerned with compatibility, just pix the fix to a version in I support returning errors for "not found" and "not var", not sure what "dead" means in this context? |
By "dead" I mean unreachable/unreferenced (transitively) from main.main. The linker's "dead code" pass will remove such variables. |
ok, so "dead" and "not found" are indistinguishable to this component of the linker? if so, I am comfortable erroring on both, since saying I want to set the value of an unused thing feels orthogonal to the compiler erroring on if not, I think there is still an argument to error on "dead" symbols, but if we can type check and it is a |
I can respect that decision[0], but there is a little uncertainty I want to clear up; you mention the following across the two issues:
and based on @rsc's comment, it seems like you would be happy to error on type conflicts, but it was impossible/infeasible? it seems like the issue was closed because there was no migration path. however, now that a path exists with the go version directive in modules, could we reopen #20649 to track "the symbol is not a variable" case? that being said, I may be reading too much into #20649, since your comments seem to suggest that
0] I would also be remiss if I did not call out that while some people may find the feature helpful, this is a footgun. it does not appear to be well documented, and I had to go out of your way to notice that |
I think it would be good if I do not think that |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: