question about runtime/debug.ReadBuildInfo

370 views
Skip to first unread message

Than McIntosh

unread,
Oct 27, 2021, 11:14:45 AM10/27/21
to golang-dev
Hi go module experts,

I have a question about the ReadBuildInfo function in runtime/debug package (e.g. https://pkg.go.dev/runtime/debug#ReadBuildInfo). Posting it here in case it might prove to be of general interest.

I wrote this toy program:


which has a go.mod that list a small collection of dependencies (9 to be exact). The program doesn't do anything interesting except invoke debug.ReadBuildInfo and dump the result. When I run it on the playground, it produces this output:

main package path blob
main mod: {Path:blob Version:(devel) Sum: Replace:<nil>}
  dep 0: &{Path:github.com/go-delve/delve Version:v1.7.2 Sum:h1:QTDJlgx9OwUVYVm7xthyf2XHKrZcTQu3wkRbovktidM= Replace:<nil>}
  dep 1: &{Path:github.com/hashicorp/golang-lru Version:v0.5.4 Sum:h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= Replace:<nil>}
  dep 2: &{Path:github.com/sirupsen/logrus Version:v1.6.0 Sum:h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= Replace:<nil>}
  dep 3: &{Path:github.com/thanm/dwarf-check Version:v1.2.1-0.20210506143206-793c7855fe71 Sum:h1:OLUESsgTzZ+1ulnuCwmlzuuT/rx/XzlJGPXMCCfhDQU= Replace:<nil>}
  dep 4: &{Path:github.com/thanm/dwdisplayfcn Version:v1.0.1 Sum:h1:HHLUsj8L3gqQedSNRiSLfHtXjZkuu3JgPU5bGL1EYmE= Replace:<nil>}
  dep 5: &{Path:golang.org/x/arch Version:v0.0.0-20190927153633-4e8777c89be4 Sum:h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI= Replace:<nil>}
  dep 6: &{Path:golang.org/x/sys Version:v0.0.0-20210514084401-e8d321eab015 Sum:h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E= Replace:<nil>}

Instead of seeing 9 deps, I only see 7. Here's the contents of the go.mod:

-- begin go.mod --
module blob

go 1.18

require github.com/thanm/dwdisplayfcn v1.0.1

require (
github.com/aquasecurity/libbpfgo v0.1.2-0.20210708203834-4928d36fafac // indirect
github.com/go-delve/delve v1.7.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/thanm/dwarf-check v1.2.1-0.20210506143206-793c7855fe71 // indirect
golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 // indirect
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
)

-- end go.mod --

I am puzzled as to why ReadBuildInfo doesn't seem to report a complete set of dependencies.

Is there something special about the missing deps that causes them to be skipped? Am I holding it wrong somehow, or is there a bug in my go.mod? 

Any insights/help would be appreciated.

Thanks, Than

Bryan C. Mills

unread,
Oct 27, 2021, 11:31:36 AM10/27/21
to Than McIntosh, golang-dev
Some of the dependencies are guarded by build tags:

'go mod tidy' includes those dependencies in the module graph so that your build remains reproducible if built with those tags set, but the particular configuration that you're running in the Playground does not set them, and so they are not needed in order to reproduce that particular build of the binary.

`go mod why' reports the paths to these dependencies, but unfortunately it does not annotate the edges with interesting build constraints:



--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/CA%2BUr55ETQMuacEDzLOQ5ta-fo8xoYPFODUpD46htK3dz-7JQZQ%40mail.gmail.com.

Than McIntosh

unread,
Oct 27, 2021, 11:37:21 AM10/27/21
to Bryan C. Mills, golang-dev
Thanks Bryan, that makes good sense. Appreciate the speedy answer--

Regards, Than

Reply all
Reply to author
Forward
0 new messages