From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id ACED93858C62 for ; Wed, 21 Sep 2022 06:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACED93858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102d.google.com with SMTP id s90-20020a17090a2f6300b00203a685a1aaso4812617pjd.1 for ; Tue, 20 Sep 2022 23:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date; bh=MpB/SzoWPDmFO0wpoI6KvQQNfUoARLPc2j/XdgZI7b8=; b=ZP0fi4a7wh68o4sDkVCUr7K3zrkIOxweR+9k9y/opEVG4fmqE5EEjwSI9WgqaHYl2t ikfuuwmYaAiKB/b+ZWrRDhmO/aXwuv4EJOsIVDUm/6QDB11QmVEdTt+RXzT+6cvngtRL fBkbdjF8UJ2gZ6phLZDEQIfdGpYFdsh2FRki12DNsEYPB+MF+hettD+EqF2X9BVH2q0q fFeMAZ5WZFQ9VBT8lVF8loS5jyV0mWddRSock1fPOCFWAySEuyknc68ujX+Sa53RsqYZ d3AMsvKzy2N4PXIosFR2YXtW6lgxyHtMT0CrRUn7bvYtjn3O+rTk4U/1lS/M7gnQEvjf 9cMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=MpB/SzoWPDmFO0wpoI6KvQQNfUoARLPc2j/XdgZI7b8=; b=F+N2vrM25et85b7q7N0b7xd/PzT5S6y1562MhsCL940W/7j0n7x2ThyY25vwVptC66 1zbsjiK/8kMXEK/86tZq3y71Od+5y9XSQlk+CPgp/oMW/52CCHeagkUXs4luj26fGOnc f3qffjlEXmHQJFAUx+nELkxHqWcy7W7UQTy5+TSIP0Z2tnFkgouDuB3dj6P1gLm/jbhH 6uBrPOv5tRp3MZLbujTGUp4kC5zJMHyQkjIlbM+S8DltbCmYKcS4IHvKhtss3P97+k50 yC6vF7All1YMnPjcYlMYx7tDKnudJtlcaEmF76mRkDJIa6UuZym58yX9weST+Rnw9J+7 9nuA== X-Gm-Message-State: ACrzQf2LJl+YiVvFJAokcPdLOXdicXgOfscK2qE2PdxDH1ftkG4WREWi 5Yx/AJTC+oSIfP7hk1NYHrhpI5gEWmo= X-Google-Smtp-Source: AMsMyM6TlkOmqIqkTyqhcDw9Rt9FaIbVOCT5BriaJsEciqtskFYaV7rsA1xMVEqlVJTjZiZeu4+AWA== X-Received: by 2002:a17:903:1110:b0:178:9f67:b543 with SMTP id n16-20020a170903111000b001789f67b543mr3232095plh.131.1663742467529; Tue, 20 Sep 2022 23:41:07 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id b3-20020a1709027e0300b0016be834d54asm1046506plm.306.2022.09.20.23.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 23:41:07 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C66871142E0E; Wed, 21 Sep 2022 16:11:04 +0930 (ACST) Date: Wed, 21 Sep 2022 16:11:04 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PR29573, addr2line doesn't display file/line for local symbols Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The DWARF standard is clear that DW_AT_linkage_name is optional. Compilers may not provide the attribute on functions and variables, even though the language mangles names. g++ does not for local variables and functions. Without DW_AT_linkage_name, mangled object file symbols can't be directly matched against the source-level DW_AT_name in DWARF info. One possibility is demangling the object file symbols, but that comes with its own set of problems: 1) A demangler might not be available for the compiler/language. 2) Demangling doesn't give the source function name as stored in DW_AT_name. Class and template parameters must be stripped at least. So this patch takes a simpler approach. A symbol matches DWARF info if the DWARF address matches the symbol address, and if the symbol name contains the DWARF name as a sub-string. Very likely the name matching is entirely superfluous. PR 29573 * dwarf.c (lookup_symbol_in_function_table): Match a symbol containing the DWARF source name as a substring. (lookup_symbol_in_variable_table): Likewise. (_bfd_dwarf2_find_nearest_line_with_alt): If stash_find_line_fast returns false, fall back to comp_unit_find_line. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index b8dad5cb3f4..4a6a1e40185 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -3379,7 +3379,7 @@ lookup_symbol_in_function_table (struct comp_unit *unit, && arange->high - arange->low < best_fit_len && each->file && each->name - && strcmp (name, each->name) == 0) + && strstr (name, each->name) != NULL) { best_fit = each; best_fit_len = arange->high - arange->low; @@ -3415,7 +3415,7 @@ lookup_symbol_in_variable_table (struct comp_unit *unit, && !each->stack && each->file != NULL && each->name != NULL - && strcmp (name, each->name) == 0) + && strstr (name, each->name) != NULL) break; if (each) @@ -5867,25 +5867,23 @@ _bfd_dwarf2_find_nearest_line_with_alt if (stash->info_hash_status == STASH_INFO_HASH_ON) { - found = stash_find_line_fast (stash, symbol, addr, filename_ptr, - linenumber_ptr); + found = stash_find_line_fast (stash, symbol, addr, + filename_ptr, linenumber_ptr); if (found) goto done; } - else - { - /* Check the previously read comp. units first. */ - for (each = stash->f.all_comp_units; each; each = each->next_unit) - if ((symbol->flags & BSF_FUNCTION) == 0 - || each->arange.high == 0 - || comp_unit_contains_address (each, addr)) - { - found = comp_unit_find_line (each, symbol, addr, filename_ptr, - linenumber_ptr); - if (found) - goto done; - } - } + + /* Check the previously read comp. units first. */ + for (each = stash->f.all_comp_units; each; each = each->next_unit) + if ((symbol->flags & BSF_FUNCTION) == 0 + || each->arange.high == 0 + || comp_unit_contains_address (each, addr)) + { + found = comp_unit_find_line (each, symbol, addr, filename_ptr, + linenumber_ptr); + if (found) + goto done; + } } else { -- Alan Modra Australia Development Lab, IBM