From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 72BC13858284 for ; Wed, 21 Sep 2022 06:24:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72BC13858284 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-pl1-x62a.google.com with SMTP id d24so4669027pls.4 for ; Tue, 20 Sep 2022 23:24:35 -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=88POtJroiPwMGrNX+M8DseUSor4cgUQDxR04S/lUuxs=; b=MsjH5TkIAyK7weKIgu1haUgH2HRDNhXVlSmVGwZWO2vtUNMLi0gKmW4xM9t4lUOg5C CHisTBrFPW88o3Mo314C9RvzwB+6OP9INboLmBR7OZneP4yfJugtq0nZlUCklFFltmYQ 6bb0Yu+jdE54iKDZQdxtCtsLnMC2IaKtM8iARR5ZjZU+GgO3I+XpQd50QgNzrpfC6daR aDzotNorqfci4XEDA4lSKvmSCeJuHTKP1RrTebdjk0M7TApt3pxFkQ4mACFsSNtNhdHi PXWaLbUCfV08KSY43A4A7K+rA/CKxq612H80MwSOkRVCmT/oMaL4GFnA4rkW1pqb28/Z 8qpA== 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=88POtJroiPwMGrNX+M8DseUSor4cgUQDxR04S/lUuxs=; b=3ZlDvISJuT9dP/Ah432YcpocmauIp5JsWhEXxRwuAw0QBc2u0J7PAzTOLwvsw6TteN xclTAkzn+3vARgdudDrxnId7Up1yR5iqN6/qypLSn4JeAKjBdNf02wqfFCePgsEaU+m0 YA4v2eeg7VI+pV1nw7nhbArkMG1Jr3U3aPG785RlTWwidvgb0ikcHWm3ZvlRHJtsAb6T ImoTZZhoDKGwcgemeRN0QtBM9KSaekk3pQL3Gg5e3Dh/3KlWV7INh7bYGx5Wy062ILVr XCJ9JX990q19W3XQqafr+Y8EuTtM8zXrfDLgkBuuOUEV1Shxnw4R+GqRpIQLBZ0eSNZ+ 9lMQ== X-Gm-Message-State: ACrzQf2jNaBJa5ZMiabcaX/AZcuu3iL3l6v+ZcACw41HxA9s42lK1jzm MhPjctzd8VF60UNc/Wp61g4D3RxJ8yg= X-Google-Smtp-Source: AMsMyM5qCaL8f3Uy1v9Jg/JwJP7iMUELHh9zdNLU8mp2m41Obz/SPznotEpuvvzQUIU9aQr3en2q5A== X-Received: by 2002:a17:90a:fe90:b0:202:a345:b7a6 with SMTP id co16-20020a17090afe9000b00202a345b7a6mr7716246pjb.14.1663741474265; Tue, 20 Sep 2022 23:24:34 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:9a23:33bb:ab6a:2a17]) by smtp.gmail.com with ESMTPSA id y2-20020a623202000000b0052c849d0886sm1129975pfy.86.2022.09.20.23.24.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 23:24:33 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 389111142E0B; Wed, 21 Sep 2022 15:54:31 +0930 (ACST) Date: Wed, 21 Sep 2022 15:54:31 +0930 From: Alan Modra To: binutils@sourceware.org Subject: dwarf2.c: simplify best_fit_len tests Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.8 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: * dwarf2.c (lookup_address_in_function_table): Simplify best_fit_len test. (info_hash_lookup_funcinfo): Likewise. (lookup_symbol_in_function_table): Likewise, also reorder tests and check "file" is set. (lookup_symbol_in_variable_table): Reorder tests. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 138cdbb00bb..b8dad5cb3f4 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -3288,7 +3288,7 @@ lookup_address_in_function_table (struct comp_unit *unit, struct lookup_funcinfo* lookup_funcinfo = NULL; struct funcinfo* funcinfo = NULL; struct funcinfo* best_fit = NULL; - bfd_vma best_fit_len = 0; + bfd_vma best_fit_len = (bfd_vma) -1; bfd_size_type low, high, mid, first; struct arange *arange; @@ -3334,8 +3334,7 @@ lookup_address_in_function_table (struct comp_unit *unit, if (addr < arange->low || addr >= arange->high) continue; - if (!best_fit - || arange->high - arange->low < best_fit_len + if (arange->high - arange->low < best_fit_len /* The following comparison is designed to return the same match as the previous algorithm for routines which have the same best fit length. */ @@ -3367,32 +3366,24 @@ lookup_symbol_in_function_table (struct comp_unit *unit, const char **filename_ptr, unsigned int *linenumber_ptr) { - struct funcinfo* each_func; + struct funcinfo* each; struct funcinfo* best_fit = NULL; - bfd_vma best_fit_len = 0; + bfd_vma best_fit_len = (bfd_vma) -1; struct arange *arange; const char *name = bfd_asymbol_name (sym); - for (each_func = unit->function_table; - each_func; - each_func = each_func->prev_func) - { - for (arange = &each_func->arange; - arange; - arange = arange->next) + for (each = unit->function_table; each; each = each->prev_func) + for (arange = &each->arange; arange; arange = arange->next) + if (addr >= arange->low + && addr < arange->high + && arange->high - arange->low < best_fit_len + && each->file + && each->name + && strcmp (name, each->name) == 0) { - if (addr >= arange->low - && addr < arange->high - && each_func->name - && strcmp (name, each_func->name) == 0 - && (!best_fit - || arange->high - arange->low < best_fit_len)) - { - best_fit = each_func; - best_fit_len = arange->high - arange->low; - } + best_fit = each; + best_fit_len = arange->high - arange->low; } - } if (best_fit) { @@ -3400,8 +3391,8 @@ lookup_symbol_in_function_table (struct comp_unit *unit, *linenumber_ptr = best_fit->line; return true; } - else - return false; + + return false; } /* Variable table functions. */ @@ -3416,14 +3407,14 @@ lookup_symbol_in_variable_table (struct comp_unit *unit, const char **filename_ptr, unsigned int *linenumber_ptr) { - const char *name = bfd_asymbol_name (sym); struct varinfo* each; + const char *name = bfd_asymbol_name (sym); for (each = unit->variable_table; each; each = each->prev_var) - if (! each->stack + if (each->addr == addr + && !each->stack && each->file != NULL && each->name != NULL - && each->addr == addr && strcmp (name, each->name) == 0) break; @@ -5087,7 +5078,7 @@ info_hash_lookup_funcinfo (struct info_hash_table *hash_table, { struct funcinfo* each_func; struct funcinfo* best_fit = NULL; - bfd_vma best_fit_len = 0; + bfd_vma best_fit_len = (bfd_vma) -1; struct info_list_node *node; struct arange *arange; const char *name = bfd_asymbol_name (sym); @@ -5103,8 +5094,7 @@ info_hash_lookup_funcinfo (struct info_hash_table *hash_table, { if (addr >= arange->low && addr < arange->high - && (!best_fit - || arange->high - arange->low < best_fit_len)) + && arange->high - arange->low < best_fit_len) { best_fit = each_func; best_fit_len = arange->high - arange->low; @@ -5135,9 +5125,9 @@ info_hash_lookup_varinfo (struct info_hash_table *hash_table, const char **filename_ptr, unsigned int *linenumber_ptr) { - const char *name = bfd_asymbol_name (sym); struct varinfo* each; struct info_list_node *node; + const char *name = bfd_asymbol_name (sym); for (node = lookup_info_hash_table (hash_table, name); node; -- Alan Modra Australia Development Lab, IBM