From patchwork Sat Nov 23 13:27:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 180090 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp735987ilf; Sat, 23 Nov 2019 05:28:22 -0800 (PST) X-Google-Smtp-Source: APXvYqy+fn+p2hkMWJ5N33WrTdHDpGwwRMGpxFAA4BDDP+Q2krmBldyEPwN/iQreJ3ueALcwDK3T X-Received: by 2002:a50:ec83:: with SMTP id e3mr7180140edr.292.1574515702624; Sat, 23 Nov 2019 05:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574515702; cv=none; d=google.com; s=arc-20160816; b=LaCDgFAg/e1iyBT/iLWLxUwiMQwVup7ac2kKm6VoOn/ywUSBE6Lx0Gxk3RwFXTgyaD 6bEw/NsBwedokvd1TrCa0qUNubv2MJMg5zJMRdDvlsEtglciVflQGIJmGGwdqap6ZJB9 jg+3Ir28siIorEWFE1acP/PEUuKfmbkjxynhNomw/QrSd8ShC1IXwknBEuuYGY9/JzqH 8VPiMexhRcnwF4R1r7wsytqx0Nnk86C5sAPjnvXjPBeKbQrvBLozSiT/lVRskHXVygXm CwN2jkHnycNbV8rzA/iTo7AHFL/j+4le2LjUcV7xbKARMTCpEKLnr/xihkV2Xm/B3lbk gBOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=VDV0cx69m4DwPpF44Vbld+kv89R0ZXuzwtz3kyXW5XA=; b=SalyUKzvZhivCnj2uP++HwD1FHRvBROS0pGy9UPgWpxeUwD3KqQmdlQNqnU5/JKgNz HCiJS4OrATf0+QJ69B5hTdz+k8Rdj+G1+0j9Or1AEd6XI1RIezq7MQyS0xNLbuvIJSxM m77mveMPlxJa1n81sm3BOv4aFSWT9+oDiH/DxTXlkS7n6KiOpWfwOaGP2YAIEJssLFik pyVeeoCCQmWqmECPJho6QxdpiHauL8Hie58gfgSInh0ARcUHuDIsUrD2T00hZvxGRje5 lJiaKvYZI8JuQBHbPf6IS9YxELdgD/kzSNvKmUpwMSLdtT8MJYDezmrub8aBzQJhikut ixlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=WrTp4OB9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si764070edy.41.2019.11.23.05.28.22; Sat, 23 Nov 2019 05:28:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=WrTp4OB9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727107AbfKWN2V (ORCPT + 26 others); Sat, 23 Nov 2019 08:28:21 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:39546 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbfKWN2B (ORCPT ); Sat, 23 Nov 2019 08:28:01 -0500 Received: from grover.flets-west.jp (softbank126093102113.bbtec.net [126.93.102.113]) (authenticated) by conuserg-10.nifty.com with ESMTP id xANDRbkj000733; Sat, 23 Nov 2019 22:27:43 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com xANDRbkj000733 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1574515663; bh=VDV0cx69m4DwPpF44Vbld+kv89R0ZXuzwtz3kyXW5XA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrTp4OB9QdcpBPwRnc6TWEX/KLLonFnhg5UPkZIF/U07HSoqNXFDVcSxoO5y43Pu3 REpPTpNte4SLML/2yuvP5ejvBQtJ6egLpH2yaDQIvyz0jh03ynLLz2d+OERncU0WBk Kw9YOqoGDuIUToGL/RvROyWLhD/qOW42WFi0pdmfdAlbvoYbjgOdM2zbD6Ll4E30Wj /51581QiI3oUYSxQYuyZiNPJhMkJP9QHo5OQeF9Yfz6uWH/uFrLSq+QM+jm815Gvu5 jzre8IUYDtskPMQB+SYhC9o0XAcAeOH95e6JBG1lhmTeXIUSnqwT7QsCPonr+hxE0N bbyp3ekj/CyAw== X-Nifty-SrcIP: [126.93.102.113] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 10/16] scripts/kallsyms: skip ignored symbols very early Date: Sat, 23 Nov 2019 22:27:21 +0900 Message-Id: <20191123132727.30151-11-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191123132727.30151-1-yamada.masahiro@socionext.com> References: <20191123132727.30151-1-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unless the address range matters, symbols can be ignored earlier, which avoids unneeded memory allocation. Signed-off-by: Masahiro Yamada --- scripts/kallsyms.c | 113 +++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 51 deletions(-) -- 2.17.1 diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index d745fd2c7247..5553843631d4 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -18,6 +18,7 @@ * */ +#include #include #include #include @@ -79,6 +80,64 @@ static char *sym_name(const struct sym_entry *s) return (char *)s->sym + 1; } +static bool is_ignored_symbol(const char *name, char type) +{ + static const char * const ignored_symbols[] = { + /* + * Symbols which vary between passes. Passes 1 and 2 must have + * identical symbol lists. The kallsyms_* symbols below are + * only added after pass 1, they would be included in pass 2 + * when --all-symbols is specified so exclude them to get a + * stable symbol list. + */ + "kallsyms_addresses", + "kallsyms_offsets", + "kallsyms_relative_base", + "kallsyms_num_syms", + "kallsyms_names", + "kallsyms_markers", + "kallsyms_token_table", + "kallsyms_token_index", + /* Exclude linker generated symbols which vary between passes */ + "_SDA_BASE_", /* ppc */ + "_SDA2_BASE_", /* ppc */ + NULL + }; + + static const char * const ignored_prefixes[] = { + "__crc_", /* modversions */ + "__efistub_", /* arm64 EFI stub namespace */ + NULL + }; + + static const char * const ignored_suffixes[] = { + "_from_arm", /* arm */ + "_from_thumb", /* arm */ + "_veneer", /* arm */ + NULL + }; + + const char * const *p; + + /* Exclude symbols which vary between passes. */ + for (p = ignored_symbols; *p; p++) + if (!strcmp(name, *p)) + return true; + + for (p = ignored_prefixes; *p; p++) + if (!strncmp(name, *p, strlen(*p))) + return true; + + for (p = ignored_suffixes; *p; p++) { + int l = strlen(name) - strlen(*p); + + if (l >= 0 && !strcmp(name + l, *p)) + return true; + } + + return false; +} + static int check_symbol_range(const char *sym, unsigned long long addr, struct addr_range *ranges, int entries) { @@ -118,6 +177,9 @@ static int read_symbol(FILE *in, struct sym_entry *s) return -1; } + if (is_ignored_symbol(sym, stype)) + return -1; + /* Ignore most absolute/undefined (?) symbols. */ if (strcmp(sym, "_text") == 0) _text = s->addr; @@ -188,38 +250,6 @@ static int symbol_in_range(const struct sym_entry *s, static int symbol_valid(const struct sym_entry *s) { - /* Symbols which vary between passes. Passes 1 and 2 must have - * identical symbol lists. The kallsyms_* symbols below are only added - * after pass 1, they would be included in pass 2 when --all-symbols is - * specified so exclude them to get a stable symbol list. - */ - static const char * const special_symbols[] = { - "kallsyms_addresses", - "kallsyms_offsets", - "kallsyms_relative_base", - "kallsyms_num_syms", - "kallsyms_names", - "kallsyms_markers", - "kallsyms_token_table", - "kallsyms_token_index", - - /* Exclude linker generated symbols which vary between passes */ - "_SDA_BASE_", /* ppc */ - "_SDA2_BASE_", /* ppc */ - NULL }; - - static const char * const special_prefixes[] = { - "__crc_", /* modversions */ - "__efistub_", /* arm64 EFI stub namespace */ - NULL }; - - static const char * const special_suffixes[] = { - "_veneer", /* arm */ - "_from_arm", /* arm */ - "_from_thumb", /* arm */ - NULL }; - - int i; const char *name = sym_name(s); /* if --all-symbols is not specified, then symbols outside the text @@ -241,25 +271,6 @@ static int symbol_valid(const struct sym_entry *s) return 0; } - /* Exclude symbols which vary between passes. */ - for (i = 0; special_symbols[i]; i++) - if (strcmp(name, special_symbols[i]) == 0) - return 0; - - for (i = 0; special_prefixes[i]; i++) { - int l = strlen(special_prefixes[i]); - - if (strncmp(name, special_prefixes[i], l) == 0) - return 0; - } - - for (i = 0; special_suffixes[i]; i++) { - int l = strlen(name) - strlen(special_suffixes[i]); - - if (l >= 0 && strcmp(name + l, special_suffixes[i]) == 0) - return 0; - } - return 1; }