Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/vet: +build comment error is confusingly worded #31410
Please answer these questions before submitting your issue. Thanks!
What did you do?
Hello up there. I was updating my tracing/xruntime package for Go1.12 and hit test error:
The error here complains about
---- 8< ---- (
#include "textflag.h" // +build amd64 amd64p // func getg() *g TEXT ·getg(SB),NOSPLIT,$0-8 MOVQ (TLS), R14 MOVQ R14, ret+0(FP) RET
It was working with Go1.11 and previous releases.
What did you expect to see?
Build and test succeed; test pass, as with e.g. Go1.11:
What did you see instead?
Generate g for Go 1.12; no changes here compared to Go 1.11, however go1.12 build build fails because of +build in .s file: # lab.nexedi.com/kirr/go123/tracing/internal/xruntime ./runtime_g_amd64.s:3:1: +build comment must appear before package clause and be followed by a blank line Build problem reported upstream: golang/go#31410
The error could be improved (obviously there is no package clause), but it is correct to be complaining. The
A more appropriate error would be
./runtime_g_amd64.s:3:1: +build comment must appear before first non-comment source line
and the "blank line" should be dropped in this instance. When the blank line is relevant the message should be
./runtime_g_amd64.s:3:1: blank line must separate +build comment from first non-comment source line
This continues b46436b (tracing/runtime: Try to add support for Go1.12): Move `+build ...` constraint in assembly files to the top, as suggested by Russ Cox: golang/go#31410 (comment) Then go stops complaining about it. The build constraint had no effect previously, but it was not caught because getg is used only on race builds and I was testing on amd64 only, which is practically almost the only ISA supported by race detector as of Go1.11 .