From patchwork Fri Oct 28 19:40:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1014382wru; Fri, 28 Oct 2022 12:55:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qI0RAWVT+Ra1D2ktfTgudaDQDLxU4pexuRd7w+7CHrG1jICZttuJo/PdRC9GKmW5DLxXK X-Received: by 2002:a17:906:7313:b0:78e:c2a:a3fa with SMTP id di19-20020a170906731300b0078e0c2aa3famr836267ejc.581.1666986956686; Fri, 28 Oct 2022 12:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666986956; cv=none; d=google.com; s=arc-20160816; b=tWBO1p6aKhhUH2rIpwMQMkDMREMP+bF1Kfj4VajM2hEK8wcG6izY1V6956sar1jdqb Q+JAnM6vBBfvZqo6Ud2WfPw0LrHClpoNsjbgIui58n7jfF9nQnIyJAfI+w1WIvD3Yqy+ XqyCOt71BeftCti03TmqScn8dUR2quOilKLdZikfKwc6hlvPeX1KSlQYil5F2Wwr8bxg XhikJyDGKkDkyQKUofg77jM7V+UiMpVyXEI+jl9hib5k4u8rkSPEQ0ylX6z8IaEQhlzz 2OrVDjiwMdasar9Ss1AEewtc8zLsQOAkmg+HDKIDNnE+P6csltxT2wDYoVKwqYEf4OLH ikdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=IORdw0i358+WCHTJMo8FHxkOZ204c2jlWb6nUgvX6XI=; b=SDQM3f04gGEG+InP+3rGFOCShKV28AZmqMqsvN/YXl8ZYOYyl7qT3l74M30Ml16Bf0 tzyOCEDo/fogJCReSWT5xjECvLAEzK+UU/Ooa+8WBPE+e2ksJGZj5PzZxEImPg4JJXkB Gmmxr/2zhU6P4fwMOTjYH4vFe5gVrgVI2uS4cPYM5nvQ8W5WPYKZUvU1/GdpI+K/JDKo TfSB9tIT88fNQOTn1SCe1tPB3ATE/WU1wvKkP7Du82GkfvElUWGpccpg5jeb06A7m736 pKy2EHna7votuUSN2z26Ms+CoylKBIdgUsqPuHnLIatrge3sa79dMyH9BGin5MQlKPvE SQJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mHVGpEbm; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a1709063b4f00b007826cb6f57csi566847ejf.407.2022.10.28.12.55.33; Fri, 28 Oct 2022 12:55:56 -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=@infradead.org header.s=casper.20170209 header.b=mHVGpEbm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbiJ1TsG (ORCPT + 99 others); Fri, 28 Oct 2022 15:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbiJ1Trz (ORCPT ); Fri, 28 Oct 2022 15:47:55 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED6A241B07 for ; Fri, 28 Oct 2022 12:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=IORdw0i358+WCHTJMo8FHxkOZ204c2jlWb6nUgvX6XI=; b=mHVGpEbm8sOcQ7hwd9786o/oxg p0whUxIGOUwNbBtGadYe5jv9R6b0FVQTQZ31Y0chVZi2yOPZeuFHU2k6PMkVd2WCCfp/DpXjArrDN n21ePo41DzyAu18b+ipSYfhhDicimP6xlfVzqsGDBmAdy6N9YcDq1c3svOG8zNwOWqyvVEe/RI6FZ 2UHw4VGe31/g6jdAx3jSJY6jEPN5pCwU+6suxlXpuykF1znt84zgQGaiXOQcLbAmOm989AO4Mdy7k d61HL9Y6l9tFWVqkCMmyPW4BeqtYIWIhru1d9GO6siabvRPt4lTHoPIHBIkGy1DKbEg/cZrskSKUG XNuSXtdQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooVKV-001V5n-VM; Fri, 28 Oct 2022 19:47:48 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B74FF30035C; Fri, 28 Oct 2022 21:47:41 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 99F592C6DAB20; Fri, 28 Oct 2022 21:47:41 +0200 (CEST) Message-ID: <20221028194453.396634875@infradead.org> User-Agent: quilt/0.66 Date: Fri, 28 Oct 2022 21:40:24 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, djwong@kernel.org, yujie.liu@intel.com, tglx@linutronix.de, jpoimboe@kernel.org, joao.moreira@intel.com, samitolvanen@google.com Subject: [PATCH 2/5] objtool: Slice up elf_create_section_symbol() References: <20221028194022.388521751@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747962514868072734?= X-GMAIL-MSGID: =?utf-8?q?1747962514868072734?= In order to facilitate creation of more symbol types, slice up elf_create_section_symbol() to extract a generic helper that deals with adding ELF symbols. Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/elf.c | 56 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -717,11 +717,11 @@ static int elf_update_symbol(struct elf } static struct symbol * -elf_create_section_symbol(struct elf *elf, struct section *sec) +__elf_create_symbol(struct elf *elf, struct symbol *sym) { struct section *symtab, *symtab_shndx; Elf32_Word first_non_local, new_idx; - struct symbol *sym, *old; + struct symbol *old; symtab = find_section_by_name(elf, ".symtab"); if (symtab) { @@ -731,27 +731,16 @@ elf_create_section_symbol(struct elf *el return NULL; } - sym = calloc(1, sizeof(*sym)); - if (!sym) { - perror("malloc"); - return NULL; - } + new_idx = symtab->sh.sh_size / symtab->sh.sh_entsize; - sym->name = sec->name; - sym->sec = sec; - - // st_name 0 - sym->sym.st_info = GELF_ST_INFO(STB_LOCAL, STT_SECTION); - // st_other 0 - // st_value 0 - // st_size 0 + if (GELF_ST_BIND(sym->sym.st_info) != STB_LOCAL) + goto non_local; /* * Move the first global symbol, as per sh_info, into a new, higher * symbol index. This fees up a spot for a new local symbol. */ first_non_local = symtab->sh.sh_info; - new_idx = symtab->sh.sh_size / symtab->sh.sh_entsize; old = find_symbol_by_index(elf, first_non_local); if (old) { old->idx = new_idx; @@ -769,18 +758,43 @@ elf_create_section_symbol(struct elf *el new_idx = first_non_local; } + /* + * Either way, we will add a LOCAL symbol. + */ + symtab->sh.sh_info += 1; + +non_local: sym->idx = new_idx; if (elf_update_symbol(elf, symtab, symtab_shndx, sym)) { WARN("elf_update_symbol"); return NULL; } - /* - * Either way, we added a LOCAL symbol. - */ - symtab->sh.sh_info += 1; + return sym; +} + +static struct symbol * +elf_create_section_symbol(struct elf *elf, struct section *sec) +{ + struct symbol *sym = calloc(1, sizeof(*sym)); + + if (!sym) { + perror("malloc"); + return NULL; + } + + sym->name = sec->name; + sym->sec = sec; + + // st_name 0 + sym->sym.st_info = GELF_ST_INFO(STB_LOCAL, STT_SECTION); + // st_other 0 + // st_value 0 + // st_size 0 - elf_add_symbol(elf, sym); + sym = __elf_create_symbol(elf, sym); + if (sym) + elf_add_symbol(elf, sym); return sym; }