]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objfile: Skip mach-o debug symbols.
authorRyan Brown <ribrdb@google.com>
Wed, 8 Apr 2015 19:55:34 +0000 (12:55 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 26 May 2015 23:00:00 +0000 (23:00 +0000)
This allows objdump to disassemble gcc generated binaries on OS X 10.6.

Change-Id: I1a5bfbf7c252e78215ef1f122520689d5ce6ddca
Reviewed-on: https://go-review.googlesource.com/10383
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/objfile/macho.go

index a6cd02b930d76a2ca9524ac36b47c41b38d0fa05..7371c0d9d1cb80da06f8a56cc6b5f3b895db4715 100644 (file)
@@ -13,6 +13,8 @@ import (
        "sort"
 )
 
+const stabTypeMask = 0xe0
+
 type machoFile struct {
        macho *macho.File
 }
@@ -34,12 +36,19 @@ func (f *machoFile) symbols() ([]Sym, error) {
        // We infer the size of a symbol by looking at where the next symbol begins.
        var addrs []uint64
        for _, s := range f.macho.Symtab.Syms {
-               addrs = append(addrs, s.Value)
+               // Skip stab debug info.
+               if s.Type&stabTypeMask == 0 {
+                       addrs = append(addrs, s.Value)
+               }
        }
        sort.Sort(uint64s(addrs))
 
        var syms []Sym
        for _, s := range f.macho.Symtab.Syms {
+               if s.Type&stabTypeMask != 0 {
+                       // Skip stab debug info.
+                       continue
+               }
                sym := Sym{Name: s.Name, Addr: s.Value, Code: '?'}
                i := sort.Search(len(addrs), func(x int) bool { return addrs[x] > s.Value })
                if i < len(addrs) {