Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp459398imi; Fri, 22 Jul 2022 02:51:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ufS4qeG/PYM6voTXCh7n18ihy9AIt9sGkWlc20qZybuyES5j5C1Q5DbgtUmX4WCa9/mYlX X-Received: by 2002:a17:903:2346:b0:16d:4084:51d1 with SMTP id c6-20020a170903234600b0016d408451d1mr1982121plh.10.1658483504092; Fri, 22 Jul 2022 02:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483504; cv=none; d=google.com; s=arc-20160816; b=IhcYwVorLSV7tT64icqxUkdsEC92nP98DIq2GpiJAUfZ35k0u1vhOb11ndm9wvPDbs 7+TrtqpIX0oeJgS4rdhfUTQyXqeNhZXiMofFRyqHW/+qnR3+ZpFPiX/vvtCask1iTxYW +rdwfVfFAywxUnh7b0HSJ9IeOumrpZxQYXNUn5ABqmQiIgAxM1luoqaNCIWKJAgZlUnr qeaUTknVGyKUfPdd/jQ22Z4i4miDV6hShc/dvliwvvJxFFLWFjyoLKeU4z3GHwEuvH6E RXfN2KCPfzYhgbKs1A2pJJmDhS/D3nReg/aKHA1QaavCB6wI7V6iW3Z6Ypku4ayBrUYL ccmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5LbVq+qMB/fQZNuNs2zq7jzk3fndSPOediSh0hCjOUk=; b=GNVzMlcEY46793Cy6pJ5d3cinPrwKH8BCpbgW9IWfGvEetbGFSJvZ5lLTxFZ+N48hJ 28LBcc9oPCm22cfKmF9ezMZVY491NMh8q2gYPuPwNP3ydAnmDm7P9sLsIZGO/SSM6aNR VU+WRW5JXipZqaqID2UKzjinY7qpGf7nGbFXAh3oRDeNSGLsLVmygC1PnWpqvmv/aNwg 9FJVOMmZFwjNfK130Kw6E+aMPux+ZLQX9+9A7vyD13OpTilewmOHdNosZS8uUwDMyx4v VzZy25Zg3vMZWKANoN6OZXJlc6CpuYYbxTqpjj/XLUqCB8zio9lZ+kqAeKrFGMB97A8x xFkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uuAqIoJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj9-20020a17090b4f4900b001f24b418354si1539255pjb.117.2022.07.22.02.51.30; Fri, 22 Jul 2022 02:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uuAqIoJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235720AbiGVJS3 (ORCPT + 99 others); Fri, 22 Jul 2022 05:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235813AbiGVJSE (ORCPT ); Fri, 22 Jul 2022 05:18:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05661B8784; Fri, 22 Jul 2022 02:12:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6923CB827C7; Fri, 22 Jul 2022 09:12:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B39C5C341C6; Fri, 22 Jul 2022 09:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481166; bh=hff1j457xnb18OdE/bo9iM0uQJtV9b7GJETPm1tbrBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uuAqIoJgHMzkgh6KAbX0f6DwRFrMbXvURWgt63tDpZ7VBrJIX+yWkgA+fJRdm++YN VuyO+ITt2F3MfnDbskMcnHk4tbVlOiRePugEELTmt7zymSVyIt1kFlVZRI87fL9otJ Z2LpdgG89GIIVh0ZwO0F71bymksIikxzqfOxS6pU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Alexei Starovoitov , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.15 05/89] objtool: Classify symbols Date: Fri, 22 Jul 2022 11:10:39 +0200 Message-Id: <20220722091133.674439447@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722091133.320803732@linuxfoundation.org> References: <20220722091133.320803732@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit 1739c66eb7bd5f27f1b69a5a26e10e8327d1e136 upstream. In order to avoid calling str*cmp() on symbol names, over and over, do them all once upfront and store the result. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Borislav Petkov Acked-by: Josh Poimboeuf Tested-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20211026120309.658539311@infradead.org [cascardo: no pv_target on struct symbol, because of missing db2b0c5d7b6f19b3c2cab08c531b65342eb5252b] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- tools/objtool/check.c | 34 ++++++++++++++++++++++------------ tools/objtool/include/objtool/elf.h | 7 +++++-- 2 files changed, 27 insertions(+), 14 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -859,8 +859,7 @@ static void add_call_dest(struct objtool * so they need a little help, NOP out any KCOV calls from noinstr * text. */ - if (insn->sec->noinstr && - !strncmp(insn->call_dest->name, "__sanitizer_cov_", 16)) { + if (insn->sec->noinstr && insn->call_dest->kcov) { if (reloc) { reloc->type = R_NONE; elf_write_reloc(file->elf, reloc); @@ -884,7 +883,7 @@ static void add_call_dest(struct objtool } } - if (mcount && !strcmp(insn->call_dest->name, "__fentry__")) { + if (mcount && insn->call_dest->fentry) { if (sibling) WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); @@ -934,7 +933,7 @@ static int add_jump_destinations(struct } else if (reloc->sym->type == STT_SECTION) { dest_sec = reloc->sym->sec; dest_off = arch_dest_reloc_offset(reloc->addend); - } else if (arch_is_retpoline(reloc->sym)) { + } else if (reloc->sym->retpoline_thunk) { /* * Retpoline jumps are really dynamic jumps in * disguise, so convert them accordingly. @@ -1075,7 +1074,7 @@ static int add_call_destinations(struct add_call_dest(file, insn, dest, false); - } else if (arch_is_retpoline(reloc->sym)) { + } else if (reloc->sym->retpoline_thunk) { /* * Retpoline calls are really dynamic calls in * disguise, so convert them accordingly. @@ -1759,17 +1758,28 @@ static int read_intra_function_calls(str return 0; } -static int read_static_call_tramps(struct objtool_file *file) +static int classify_symbols(struct objtool_file *file) { struct section *sec; struct symbol *func; for_each_sec(file, sec) { list_for_each_entry(func, &sec->symbol_list, list) { - if (func->bind == STB_GLOBAL && - !strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, + if (func->bind != STB_GLOBAL) + continue; + + if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR, strlen(STATIC_CALL_TRAMP_PREFIX_STR))) func->static_call_tramp = true; + + if (arch_is_retpoline(func)) + func->retpoline_thunk = true; + + if (!strcmp(func->name, "__fentry__")) + func->fentry = true; + + if (!strncmp(func->name, "__sanitizer_cov_", 16)) + func->kcov = true; } } @@ -1831,7 +1841,7 @@ static int decode_sections(struct objtoo /* * Must be before add_{jump_call}_destination. */ - ret = read_static_call_tramps(file); + ret = classify_symbols(file); if (ret) return ret; @@ -1889,9 +1899,9 @@ static int decode_sections(struct objtoo static bool is_fentry_call(struct instruction *insn) { - if (insn->type == INSN_CALL && insn->call_dest && - insn->call_dest->type == STT_NOTYPE && - !strcmp(insn->call_dest->name, "__fentry__")) + if (insn->type == INSN_CALL && + insn->call_dest && + insn->call_dest->fentry) return true; return false; --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -54,8 +54,11 @@ struct symbol { unsigned long offset; unsigned int len; struct symbol *pfunc, *cfunc, *alias; - bool uaccess_safe; - bool static_call_tramp; + u8 uaccess_safe : 1; + u8 static_call_tramp : 1; + u8 retpoline_thunk : 1; + u8 fentry : 1; + u8 kcov : 1; }; struct reloc {