From f3bbd5c389404eb4cc19d136886190d65fefde44 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 29 Mar 2022 08:18:49 +0200 Subject: [PATCH] bfd/Dwarf2: make find-nearest-line returned function name consistent Prior to entering the enclosing "else if()" the earlier associated if() checks function->is_linkage and, if set, uses function->name. The comment in patch context precedes (and explains) the setting function->is_linkage. Yet with the flag set, we should then also return the function name, just like said earlier if() would do when we came here a 2nd time for the same "addr". And indeed passing the same address twice on addr2line's command line would resolve the function for the 2nd instance, but not for the 1st (if this code path is taken). (This, obviously, is particularly relevant when there's no ELF symbol table in the first place, like would be the case - naturally - in PE/COFF binaries, for example.) --- bfd/dwarf2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 8b5ac6012e1..8cd0ce9d425 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -5295,8 +5295,9 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd, sec_vma = section->vma; if (section->output_section != NULL) sec_vma = section->output_section->vma + section->output_offset; - if (fun != NULL - && fun->value + sec_vma == function->arange.low) + if (fun == NULL) + *functionname_ptr = function->name; + else if (fun->value + sec_vma == function->arange.low) function->name = *functionname_ptr; /* Even if we didn't find a linkage name, say that we have to stop a repeated search of symbols. */ -- 2.30.2