]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/nm: accept macho files which don't have symbol table in the archive
authorHiroshi Ioka <hirochachacha@gmail.com>
Thu, 21 Sep 2017 03:56:30 +0000 (12:56 +0900)
committerIan Lance Taylor <iant@golang.org>
Thu, 21 Sep 2017 19:17:33 +0000 (19:17 +0000)
After https://golang.org/cl/64793, we started to include Mach-O object
files which don't have symbol table into cgo archive.
However, toolchains didn't handle those files yet.

Fixes #21959

Change-Id: Ibb2f6492f1fa59368f2dfd4cff19783997539875
Reviewed-on: https://go-review.googlesource.com/65170
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/objfile/macho.go
src/cmd/nm/nm.go

index d6d545c23ecc6160219473e027383940d6e372b5..7a8999e5ba38a61c3bc7dabb173e0f965eb59087 100644 (file)
@@ -30,7 +30,7 @@ func openMacho(r io.ReaderAt) (rawFile, error) {
 
 func (f *machoFile) symbols() ([]Sym, error) {
        if f.macho.Symtab == nil {
-               return nil, fmt.Errorf("missing symbol table")
+               return nil, nil
        }
 
        // Build sorted list of addresses of all symbols.
index 65ef5b4295f9067140cc2b21d62df2b83c3d28c7..457239921bc34ff185f144467b7762bec1383f21 100644 (file)
@@ -110,15 +110,19 @@ func nm(file string) {
 
        entries := f.Entries()
 
+       var found bool
+
        for _, e := range entries {
                syms, err := e.Symbols()
                if err != nil {
                        errorf("reading %s: %v", file, err)
                }
                if len(syms) == 0 {
-                       errorf("reading %s: no symbols", file)
+                       continue
                }
 
+               found = true
+
                switch *sortOrder {
                case "address":
                        sort.Slice(syms, func(i, j int) bool { return syms[i].Addr < syms[j].Addr })
@@ -155,5 +159,9 @@ func nm(file string) {
                }
        }
 
+       if !found {
+               errorf("reading %s: no symbols", file)
+       }
+
        w.Flush()
 }