audit_symbols.go: show the origin (library filename) of offending symbols. This is nice when having checked multiple libraries. Bug: 544576498 Change-Id: I7e363e5d8132f316e358b89232cddd1c6a6a6964 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/100667 Reviewed-by: Xiangfei Ding <xfding@google.com> Commit-Queue: Xiangfei Ding <xfding@google.com> Auto-Submit: Rudolf Polzer <rpolzer@google.com>
diff --git a/util/audit_symbols.go b/util/audit_symbols.go index 3383fea..ead6709 100644 --- a/util/audit_symbols.go +++ b/util/audit_symbols.go
@@ -190,16 +190,22 @@ } // Only add first instance of any symbol; keep track of them in this map. - symbols := make(map[string]strength) + symbols := make(map[string]symbolInfo) collectSymbols := func(name, archive string, contents []byte) { syms, err := listSymbols(contents) if err != nil { printAndExit("Error listing symbols from %q in %q: %s", name, archive, err) } for s, strength := range syms { - if _, ok := symbols[s]; !ok { - symbols[s] = strength + info, found := symbols[s] + if !found || strength > info.strength { + info.strength = strength } + if info.origins == nil { + info.origins = map[string]struct{}{} + } + info.origins[archive] = struct{}{} + symbols[s] = info } } @@ -238,7 +244,7 @@ if *ignoreSymbolsWith != "" && strings.Contains(s, *ignoreSymbolsWith) { continue } - if symbols[s] == weakSymbol { + if symbols[s].strength == weakSymbol { for _, symRE := range skipWeakSymbols { if symRE.MatchString(s) { continue SYMBOLS @@ -252,7 +258,7 @@ } msg := s if *ignoreSymbolsWith != "" { - msg = fmt.Sprintf("Found %s symbol without %q: %s", symbols[s], *ignoreSymbolsWith, s) + msg = fmt.Sprintf("Found %s symbol without %q in %v: %s", symbols[s].strength, *ignoreSymbolsWith, slices.Sorted(maps.Keys(symbols[s].origins)), s) } if _, err := fmt.Fprintln(out, msg); err != nil { printAndExit("Error writing to %s: %s", *outFlag, err) @@ -290,6 +296,11 @@ return strongSymbol } +type symbolInfo struct { + strength strength + origins map[string]struct{} +} + // listSymbols lists the exported symbols from an object file. func listSymbols(contents []byte) (map[string]strength, error) { switch *objFileFormat {