Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5235imw; Tue, 12 Jul 2022 13:24:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s9fADLkR7dhFHriA1x3BBVS2J1ISX48gt29HU8xSVznSjDx5TNzsQEd+P+FqtOasYaL+5f X-Received: by 2002:a63:5c58:0:b0:411:8062:5308 with SMTP id n24-20020a635c58000000b0041180625308mr22083795pgm.553.1657656837901; Tue, 12 Jul 2022 13:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657656837; cv=none; d=google.com; s=arc-20160816; b=KpyvOZZjuE0OYUAqAwHoMv4Gbq0+3elbN3kh6fz6+K2lVA3DVpfNwBl9h9ltKKx9o8 w1a7UJVUHlN64XehHhDLm/R2DVDoSM626p9wuKESXLjV2P8jBP/2pD/DSGcCHghww+i7 dtXxp+A6CR5NWr/GPAbRJdfIlizfXzIU11PtjIJ5ZTmTQR8ebg0WyDghWd+xMgUDTPjr 5W+YUuihflNSaKCxQ7JquyINTaV3QZ1MHhHgZCi4GNtW68L/A/FOSAf5pSuxVhdSoHhS I7Yo6A8SusliG6G6AueSm8JaaEswStbX0rHaD3hDHYqSLZ3X4xwljtSOfB8C374Mj7cB XE9w== 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=Z9/fzZHI9BRmmY4xIh+IbJ+kRm+7Kv/yD9Fn23lwrHA=; b=zoKvpxywkEVgqjcnRNy/V1PYvkmLQYhA6ZPmxmF48yWT46kLLIAF/ql27daA3j3ZeX lq8mBY8PJbTGbMXK9r432nbkE33uVlwRB4nSff4q8FRCBarg/mLqv67ygu+ecMu9hgYn Y74Z1sW9coJxMiOJcdUEKHITMYmK+cSl/Y4MqDmDZMOy6F9gC7XItJFoySskkzdSmzY+ 5KpE0esWHqvbsZTYqpqls3xVDPnAAGp0AnnyUJdtF8i3bD7sOVmuCb1dArJ5lhD7PyTC 53a5N8k02nF4NgduBz5qqCd/1gEUj4V7tsvGsKtP+ahK+IKXMVFBCFeE7SejbtqQ8K6c OKfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pJVdeAK7; 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 q10-20020a056a00088a00b005184ae7a3c4si16798103pfj.140.2022.07.12.13.13.26; Tue, 12 Jul 2022 13:13:57 -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=pJVdeAK7; 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 S233813AbiGLSmb (ORCPT + 99 others); Tue, 12 Jul 2022 14:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234039AbiGLSl6 (ORCPT ); Tue, 12 Jul 2022 14:41:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AECD514E; Tue, 12 Jul 2022 11:41:25 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2C7A261ACE; Tue, 12 Jul 2022 18:41:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38154C3411C; Tue, 12 Jul 2022 18:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651284; bh=6MHWoP7j5DCxR+KQoeA5JjHbHKkbd3JWJTvdKzygbME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pJVdeAK7Q6A0QZzat85XbvdB0v51TuQIuhUBm42L0pTMelHdSWoxiuoqxngbLAgst clZ5yqAew5NuuMSKWHDSOXLdFENTrvo3Zo4+vujiS9TgEGimhF4ePzDrNS1eZl15UR LDr5LMcBbgJvaMt4KuWfz/CPByBTI1bD7cb/YKwI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Ingo Molnar , Miroslav Benes , Ben Hutchings Subject: [PATCH 5.10 029/130] objtool: Extract elf_symbol_add() Date: Tue, 12 Jul 2022 20:37:55 +0200 Message-Id: <20220712183247.735138934@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@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.7 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,T_SCC_BODY_TEXT_LINE 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 9a7827b7789c630c1efdb121daa42c6e77dce97f upstream. Create a common helper to add symbols. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Signed-off-by: Ingo Molnar Reviewed-by: Miroslav Benes Link: https://lkml.kernel.org/r/20210326151300.003468981@infradead.org [bwh: Backported to 5.10: rb_add() parameter order is different] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/elf.c | 56 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 25 deletions(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -341,12 +341,39 @@ static int read_sections(struct elf *elf return 0; } +static void elf_add_symbol(struct elf *elf, struct symbol *sym) +{ + struct list_head *entry; + struct rb_node *pnode; + + sym->type = GELF_ST_TYPE(sym->sym.st_info); + sym->bind = GELF_ST_BIND(sym->sym.st_info); + + sym->offset = sym->sym.st_value; + sym->len = sym->sym.st_size; + + rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset); + pnode = rb_prev(&sym->node); + if (pnode) + entry = &rb_entry(pnode, struct symbol, node)->list; + else + entry = &sym->sec->symbol_list; + list_add(&sym->list, entry); + elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx); + elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name)); + + /* + * Don't store empty STT_NOTYPE symbols in the rbtree. They + * can exist within a function, confusing the sorting. + */ + if (!sym->len) + rb_erase(&sym->node, &sym->sec->symbol_tree); +} + static int read_symbols(struct elf *elf) { struct section *symtab, *symtab_shndx, *sec; struct symbol *sym, *pfunc; - struct list_head *entry; - struct rb_node *pnode; int symbols_nr, i; char *coldstr; Elf_Data *shndx_data = NULL; @@ -391,9 +418,6 @@ static int read_symbols(struct elf *elf) goto err; } - sym->type = GELF_ST_TYPE(sym->sym.st_info); - sym->bind = GELF_ST_BIND(sym->sym.st_info); - if ((sym->sym.st_shndx > SHN_UNDEF && sym->sym.st_shndx < SHN_LORESERVE) || (shndx_data && sym->sym.st_shndx == SHN_XINDEX)) { @@ -406,32 +430,14 @@ static int read_symbols(struct elf *elf) sym->name); goto err; } - if (sym->type == STT_SECTION) { + if (GELF_ST_TYPE(sym->sym.st_info) == STT_SECTION) { sym->name = sym->sec->name; sym->sec->sym = sym; } } else sym->sec = find_section_by_index(elf, 0); - sym->offset = sym->sym.st_value; - sym->len = sym->sym.st_size; - - rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset); - pnode = rb_prev(&sym->node); - if (pnode) - entry = &rb_entry(pnode, struct symbol, node)->list; - else - entry = &sym->sec->symbol_list; - list_add(&sym->list, entry); - elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx); - elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name)); - - /* - * Don't store empty STT_NOTYPE symbols in the rbtree. They - * can exist within a function, confusing the sorting. - */ - if (!sym->len) - rb_erase(&sym->node, &sym->sec->symbol_tree); + elf_add_symbol(elf, sym); } if (stats)