From b294e901e293e41b6374f056dcc8d4329780455c Mon Sep 17 00:00:00 2001 From: Joey Jiao Date: Thu, 23 May 2024 12:25:55 +0800 Subject: pkg/cover: remove symbols having the same Start Address For modules, init_module and cleanup_module might have the same sym.Start even these symbols are for different sections. Although we can keep symbols only in .text sections, there are still some symbols having the same Start. Looking forward a better way, but currently to get constant output in buildSymbols, keep only one symbol incase there are other symbols having the same Start. --- pkg/cover/backend/dwarf.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cover/backend/dwarf.go b/pkg/cover/backend/dwarf.go index 1eb6dd146..c3941a145 100644 --- a/pkg/cover/backend/dwarf.go +++ b/pkg/cover/backend/dwarf.go @@ -203,6 +203,17 @@ func makeDWARFUnsafe(params *dwarfParams) (*Impl, error) { allRanges = append(allRanges, result.ranges...) allUnits = append(allUnits, result.units...) } + // TODO: need better way to remove symbols having the same Start + uniqSymbs := make(map[uint64]*Symbol) + for _, sym := range allSymbols { + if _, ok := uniqSymbs[sym.Start]; !ok { + uniqSymbs[sym.Start] = sym + } + } + allSymbols = []*Symbol{} + for _, sym := range uniqSymbs { + allSymbols = append(allSymbols, sym) + } sort.Slice(allSymbols, func(i, j int) bool { return allSymbols[i].Start < allSymbols[j].Start }) -- cgit mrf-deployment