Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1366736imi; Sat, 23 Jul 2022 03:49:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u+zQrm45Sd8aghQt9rwjOsUE2USeYtBhQgXNL3IwHzqvxptFnbNi0HpybPL+KENroMkER6 X-Received: by 2002:a17:902:d4c2:b0:16b:ffc5:9705 with SMTP id o2-20020a170902d4c200b0016bffc59705mr3676628plg.142.1658573390343; Sat, 23 Jul 2022 03:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573390; cv=none; d=google.com; s=arc-20160816; b=nT2pwMjHPH0fdnxXnjg+4ibvLeiAcGmpZT+wpFae/HJI5lq/A1Epk6C8Wa7DBRacNt WrA2wwQU7m4VRvZs0Rn80TxHRx8VHRsOR4/FUY1gCDRP92OiTv8IYP9rhtX/eRaVyold Rhx3V30sw86+73XpTyPGdFV4088IfmQ47NojmEw2dfNJK+Io/x4xMFIcoxaPVJscY9Cg NHDJR+AeR7bYUAXGDr5iLWxqFYgg4+qymDGPr32xG0NeMUL7mMlutdjEUo6fz52tdzjR LD/ZDE8C53ZPjFhNEz/9LCrofX3kG/SFZEIY612bCE23LnSQRU4ko9YSChW+fvi5B9XZ aYUg== 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=oyYUuZuVIPLIEzGkRb0gKmhJ3Xt9XWfpgJwKUfegaLM=; b=EiqqisJvXWQ8QWciJO9vsEpW0FFEGPf8pue5U2AbZ2OM48bPRDzgOPjIuMIXwqyYRw egcADovcHD9mNA91kkg1m6ybF3BMRnACmAthVQA1U1b0xwLn0Pd7d/sahHYFtZ3kfGyy b56DjNkbV2D5/z3zCbEAAOkGMphGns62Og6x+OnTCaA5YjKOHJ+rj/WUtHFnsCy1ZZgU 4FAk1qM5IFwIqCLmV4DjUo0f0REYLCQ1q2Q9OIXE3J8levFZjL0vcrAg5BarhSy8bkmg l6DI798hD2cQXvrLp3mLkCcAGqRCUBzk9CHYytyqOWhgYLC25D9cgyxitJS9C3/MHbPK RG1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rNd2ovEj; 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 d3-20020a631d03000000b003fae0c67055si8332465pgd.777.2022.07.23.03.49.35; Sat, 23 Jul 2022 03:49:50 -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=rNd2ovEj; 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 S237734AbiGWJ7x (ORCPT + 99 others); Sat, 23 Jul 2022 05:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237711AbiGWJ7K (ORCPT ); Sat, 23 Jul 2022 05:59:10 -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 55460474D8; Sat, 23 Jul 2022 02:57:52 -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 E3FC4B82C1B; Sat, 23 Jul 2022 09:57:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44E7BC341C0; Sat, 23 Jul 2022 09:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570269; bh=LpGgRFhrdCtmBrJ1+C5WSb3c5uJQUargm8UG6qofKak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNd2ovEjuqFfKSei/9WpL/YprXfvZx+61oWyq5dzeNKpPKTQYBFuSEnLJM8+jMtp7 761uvtKN5itxTvol2BkAj4D5FMSCOPcSCpwiJ0lj028Jf2Ok88EmVC4KpytOrZtvQX aiC77QpD9KkfJpavH+MdJBS7iL/cwEb8oFy13p1E= 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 028/148] objtool: Extract elf_strtab_concat() Date: Sat, 23 Jul 2022 11:54:00 +0200 Message-Id: <20220723095232.278686983@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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 417a4dc91e559f92404c2544f785b02ce75784c3 upstream. Create a common helper to append strings to a strtab. 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/20210326151259.941474004@infradead.org Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/elf.c | 60 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -724,13 +724,48 @@ err: return NULL; } +static int elf_add_string(struct elf *elf, struct section *strtab, char *str) +{ + Elf_Data *data; + Elf_Scn *s; + int len; + + if (!strtab) + strtab = find_section_by_name(elf, ".strtab"); + if (!strtab) { + WARN("can't find .strtab section"); + return -1; + } + + s = elf_getscn(elf->elf, strtab->idx); + if (!s) { + WARN_ELF("elf_getscn"); + return -1; + } + + data = elf_newdata(s); + if (!data) { + WARN_ELF("elf_newdata"); + return -1; + } + + data->d_buf = str; + data->d_size = strlen(str) + 1; + data->d_align = 1; + + len = strtab->len; + strtab->len += data->d_size; + strtab->changed = true; + + return len; +} + struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr) { struct section *sec, *shstrtab; size_t size = entsize * nr; Elf_Scn *s; - Elf_Data *data; sec = malloc(sizeof(*sec)); if (!sec) { @@ -787,7 +822,6 @@ struct section *elf_create_section(struc sec->sh.sh_addralign = 1; sec->sh.sh_flags = SHF_ALLOC | sh_flags; - /* Add section name to .shstrtab (or .strtab for Clang) */ shstrtab = find_section_by_name(elf, ".shstrtab"); if (!shstrtab) @@ -796,27 +830,9 @@ struct section *elf_create_section(struc WARN("can't find .shstrtab or .strtab section"); return NULL; } - - s = elf_getscn(elf->elf, shstrtab->idx); - if (!s) { - WARN_ELF("elf_getscn"); - return NULL; - } - - data = elf_newdata(s); - if (!data) { - WARN_ELF("elf_newdata"); + sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); + if (sec->sh.sh_name == -1) return NULL; - } - - data->d_buf = sec->name; - data->d_size = strlen(name) + 1; - data->d_align = 1; - - sec->sh.sh_name = shstrtab->len; - - shstrtab->len += strlen(name) + 1; - shstrtab->changed = true; list_add_tail(&sec->list, &elf->sections); elf_hash_add(elf->section_hash, &sec->hash, sec->idx);