The normal process should no longer involve any ldflags, starting with Go 1.18 (Q4 2021/Q1 2022).
See issue 37475 and CL 356013
The go command now embeds version control information in binaries including the currently checked-out revision and a flag indicating  whether edited or untracked files are present.
Version control information is embedded if the go command is invoked in a directory within a Git or Mercurial repository, and the main package and its containing main module are in the same repository.
This information may be omitted using the flag -buildvcs=false.
Additionally, the go command embeds information about:
- the build including build and tool tags (set with -tags),
- compiler,
- assembler, and
- linker flags (like -gcflags),
- whether cgowas enabled, and if it was, the values of thecgoenvironment variables (likeCGO_CFLAGS).
This information may be omitted using the flag -buildinfo=false.
Both VCS and build information may be  read together with module information using:
- go version -m fileor
- runtime/debug.ReadBuildInfo(for the currently running binary) or
- the new debug/buildinfopackage.
CL 373875 adds
- The BuildInfostruct has new fields with additional information about how the binary was built.
- The new GoVersionfield holds the version of Go used to build the binary.
- The new Settingsfield is a slice ofBuildSettingsstructs holding key/value pairs describing the build.