Skip to content

cmd/nm: bss symbols not correctly reported on linux/amd64 #77301

Closed

Description

@egonelbre

Go version

go1.26rc2

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/egon/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/egon/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/1w/2x_sgq2j111d19xj1kpxkgp40000gn/T/go-build3668712380=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/egon/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/egon/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/egon/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26rc2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

var globalUninitialized int64     // should be in BSS
var globalInitialized int64 = 42  // should be in DATA

func main() {
    println(globalUninitialized)
    println(globalInitialized)
}

What did you see happen?

∫ GOOS=linux GOARCH=amd64 go build -o example example.go && go tool nm example | grep main.global
  534490 D main.globalInitialized
  55d510 D main.globalUninitialized

What did you expect to see?

∫ nm --version
llvm-nm, compatible with GNU nm
Apple LLVM version 17.0.0
  Optimized build.

∫ nm example | grep main.global
0000000000534490 D main.globalInitialized
000000000055d510 B main.globalUninitialized

Activity

  1. egonelbre commented on Jan 24, 2026

    @egonelbre
    ContributorAuthor

    Debugging with AI pointed me to

    sect := f.elf.Sections[i]
    switch sect.Flags & (elf.SHF_WRITE | elf.SHF_ALLOC | elf.SHF_EXECINSTR) {
    case elf.SHF_ALLOC | elf.SHF_EXECINSTR:
    sym.Code = 'T'
    case elf.SHF_ALLOC:
    sym.Code = 'R'
    case elf.SHF_ALLOC | elf.SHF_WRITE:
    sym.Code = 'D'

    And suggested that it should check for:

    case elf.SHF_ALLOC | elf.SHF_WRITE:
    	if sect.Type == elf.SHT_NOBITS {
    		sym.Code = 'B'
    	} else {
    		sym.Code = 'D'
    	}
    

    However, I do not have intimate knowledge with elf to know whether that is always correct.

  2. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Jan 24, 2026
  3. ianlancetaylor commented on Jan 24, 2026

    @ianlancetaylor
    Contributor

    That is the correct fix. Sent CL 739080. Thanks.

  4. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Jan 24, 2026
  5. gopherbot commented on Jan 24, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/739080 mentions this issue: cmd/internal/objfile: use 'B' code for symbols in ELF NOBITS sections

  6. added this to the Go1.27 milestone on Feb 4, 2026
  7. odeke-em commented on Jun 24, 2026

    @odeke-em
    Member

    Thanks for the report @egonelbre! To investigate this further, I sent out a test in CL https://go-review.googlesource.com/c/go/+/794080 that I'll kindly nudge @ianlancetaylor to add to the fix CL and it turns out that it fails too on windows per windows-386-result and windows-amd64-result

  8. added a commit that references this issue on Jun 25, 2026
    5703e10
  9. added a commit that references this issue on Jul 21, 2026
    6295f44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址