为什么带有 ldflag `-X` 的 `build` 仅在指定文件名时才起作用?

Mar*_*cus 5 linker build go ldflags

我有文件playground.go

package main

import (
  "fmt"
)

var GitCommit string

func main() {
  fmt.Printf("Hello world, version: %s\n", GitCommit)
}
Run Code Online (Sandbox Code Playgroud)

为什么构建 ldflag 的行为-X取决于指定源文件名?:

# CASE 1
$ go build -ldflags "-X main.GitCommit=abc" && ./go_playground
Hello world, version: 

$ go tool nm go_playground
52a900 D main.GitCommit

# CASE 2
$ go build -ldflags "-X main.GitCommit=abc" playground.go && ./playground
Hello world, version: abc

$ go tool nm playground
5242f0 D main.GitCommit
4c5678 R main.GitCommit.str
Run Code Online (Sandbox Code Playgroud)

编辑:当情况 1 从符号链接目录执行时,似乎会发生问题;当情况1从原始目录执行时,变量被传递。我不确定这是否是预期的,或者这是一个错误。