]> Cypherpunks repositories - gostls13.git/commitdiff
debug/macho: filter non-external symbols when reading imported symbols without LC_DYS...
authorqmuntal <quimmuntal@gmail.com>
Wed, 10 Sep 2025 11:16:00 +0000 (13:16 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Thu, 11 Sep 2025 09:40:28 +0000 (02:40 -0700)
File.ImportedSymbols will return symbols with a type that has one of the
N_STAB (0xe0) bits set and no section. That's not the expected behavior,
as those symbols might not be external.

We should expand the type check to also account for the N_EXT bit.
The section check is not necessary, as N_EXT symbols never have it set.

I have found this issue in the wild by running "go tool cgo -dynimport",
but unfortuantely I couldn't get a minimal C code that generates
N_STAB symbols without section, so this CL doesn't add any new test.

Change-Id: Ib0093ff66b50c7cc2f39d83936314fc293236917
Reviewed-on: https://go-review.googlesource.com/c/go/+/702296
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/debug/macho/file.go

index 52ff81750cc4c1da1af12f380bbddbe0aa609301..8a4088828415b1b23176bc2ecc105364da517fce 100644 (file)
@@ -735,9 +735,10 @@ func (f *File) ImportedSymbols() ([]string, error) {
                const (
                        N_TYPE = 0x0e
                        N_UNDF = 0x0
+                       N_EXT  = 0x01
                )
                for _, s := range st.Syms {
-                       if s.Type&N_TYPE == N_UNDF && s.Sect == 0 {
+                       if s.Type&N_TYPE == N_UNDF && s.Type&N_EXT != 0 {
                                all = append(all, s.Name)
                        }
                }