Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug/elf: ElfFile.SectionByType() should return a list of matched sections. #59287

Closed
BrytonLee opened this issue Mar 28, 2023 · 5 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge

Comments

@BrytonLee
Copy link

What version of Go are you using (go version)?

$ go version
1.19.5

Does this issue reproduce with the latest release?

Yes, there is no change between go 1.19.5 to the latest. The affected file and line number is here: https://github.com/golang/go/blob/master/src/debug/elf/file.go#L246

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/lichengdong/Library/Caches/go-build"
GOENV="/Users/lichengdong/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/lichengdong/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lichengdong/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g4/4_y2t8q179s1n1h40218_3rm0000gn/T/go-build2820814962=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Just send a ELF file for debug/elf to parse it. Then call SectionByType(elf.SHT_PROGBITS), it will return first section with type equals to elf.SHT_PROGBITS. But in a normal ELF file on Linux, there is more than on elf.SHT_PROGBITS section in fact.

What did you expect to see?

returns a list of matched sections.

What did you see instead?

None

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 28, 2023
@ianlancetaylor
Copy link
Contributor

Unfortunately we can't change the current method, as that would break existing programs. SectionByType is only useful for section types that normally only occur once, such as SHT_DYNAMIC.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2023
@BrytonLee
Copy link
Author

Thanks for your prompt reply.

What if we add a method such as SectionAllByType? Thus doesn't break existing programs.

@ianlancetaylor
Copy link
Contributor

That kind of new API should go through the proposal process: see https://go.dev/s/proposal. But I'm not sure it's really helpful; why not just loop through the sections yourself? Would anybody really call SectionAllByType?

@BrytonLee
Copy link
Author

Yeah, sure I can iterate all sections and find out what I need. But, I am a live sample that I was confused by SectionByType(), literally, it implies that user just need to specify section type and get what they need. I am not sure this will continue to confuse other developers as well. :-)

@ianlancetaylor
Copy link
Contributor

I agree that SectionByType is not all that useful, and it may have been a mistake to add it. But now that it exists we aren't going to change it.

@golang golang locked and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants