Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1650959ybt; Thu, 18 Jun 2020 13:54:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJdc11hCunBKykrmLi70sEr7+bR82RFtvFta1DGPFb6cd+Dv9d24dEWPa94St3Zk7b4BYd X-Received: by 2002:a50:f60a:: with SMTP id c10mr63146edn.295.1592513663402; Thu, 18 Jun 2020 13:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513663; cv=none; d=google.com; s=arc-20160816; b=Jyaf+9MX72ciYQj8Si6hnqaqw6qaq8AMcJilzTCTrPRS/kaYW8rgTirTEc5ZDi/ts8 99wc7t57CQwh+wFIVcBqiKazubGu8SJjfMtr4PkR/N7nsDPekEtDrAbYrhjzmo9xRTHJ /F6P2EYWcP1pe8vt7Wk6q7AnQJR3TvRr509/YjuXrOMhlwFAO7Fltoef9p+o+qCp47eS /JWsREMUaUEeDGVt/ad0b8eTtV0my0dphBmp6lJ+scEJAFpN+Sk6TfWLCZd7+SGGl5or xSzKI9b89wr7ToHkS1wae4ousGvQ/slq7SU2/CEyjseCDhqu130zMMyJ8ATKvN/a46oO zyIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jq9NiAaCOcNEqV09OckbDa6B1r6m/nQVdBk0lQvRSh8=; b=RFZjNxYqSKwGlDo51aJ4g9gwWrDZpH37eYBETteN+oAqcU2Hx/RC7b5RmxcfbZ+Flm p6EmlboeHmVcfZDL8+F/0ASiVcR7d3TUFG+cBeT5uypZjcarg5AYEM9qjiiAqgebnaeF V/Syiwt17ofqnPpuXmQ+qduNBLnO/9j95vXKZyQMCGXqBZTcvan0K9sULtHSocW+Gg+a pUtI3z5a7s5uPFHBDgjH7Fc3q4sCLEOTrkleDpcmnU4tnudBETWH3Flyw8pAzHbFbRKo vJWABZpN3el2TQvqIyATqh4OEZ/cVaWL9dssJd/o+5WD2qSl70+5U+cvh4Xt4K7ImkRh dANQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si2524185ejk.282.2020.06.18.13.54.01; Thu, 18 Jun 2020 13:54:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbgFRUm5 (ORCPT + 99 others); Thu, 18 Jun 2020 16:42:57 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:48844 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731260AbgFRUjS (ORCPT ); Thu, 18 Jun 2020 16:39:18 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:10 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id BB732B265A; Thu, 18 Jun 2020 16:39:13 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 19/51] objtool: mcount: Restrict using ehdr in append_func() Date: Thu, 18 Jun 2020 13:38:05 -0700 Message-ID: <1d87f1541128bec33f23ce8570cc4fbcc34789f3.1592510545.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the ehdr parameter to append_func() to write the ELF file's header but use the objtool ELF header data as the basis for making changes. The makes it clearer when we can switch from using the old recordmcount wrapper to write the ELF file because ehdr will only be passed on to uwrite() calls and those will get replaced later. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h index eed592954f37..19bff5a7c8ce 100644 --- a/tools/objtool/recordmcount.h +++ b/tools/objtool/recordmcount.h @@ -93,7 +93,7 @@ static void (*Elf_r_info)(Elf_Rel *const rp, unsigned sym, unsigned type) = fn_E static int mcount_adjust = 0; -static unsigned int get_shnum(Elf_Ehdr const *ehdr, Elf_Shdr const *shdr0) +static unsigned int get_shnum(GElf_Ehdr const *ehdr, Elf_Shdr const *shdr0) { if (shdr0 && !ehdr->e_shnum) return w(shdr0->sh_size); @@ -133,11 +133,11 @@ static int append_func(Elf_Ehdr *const ehdr, char const *mc_name = (sizeof(Elf_Rela) == rel_entsize) ? ".rela__mcount_loc" : ".rel__mcount_loc"; - uint_t const old_shoff = _w(ehdr->e_shoff); + uint_t const old_shoff = lf->ehdr.e_shoff; uint_t const old_shstr_sh_size = _w(shstr->sh_size); uint_t const old_shstr_sh_offset = _w(shstr->sh_offset); Elf_Shdr *const shdr0 = (Elf_Shdr *)(old_shoff + (void *)ehdr); - unsigned int const old_shnum = get_shnum(ehdr, shdr0); + unsigned int const old_shnum = get_shnum(&lf->ehdr, shdr0); unsigned int const new_shnum = 2 + old_shnum; /* {.rel,}__mcount_loc */ uint_t t = 1 + strlen(mc_name) + _w(shstr->sh_size); uint_t new_e_shoff; @@ -149,8 +149,6 @@ static int append_func(Elf_Ehdr *const ehdr, t += (_align & -t); /* word-byte align */ new_e_shoff = t; - set_shnum(ehdr, shdr0, new_shnum); - /* body for new shstrtab */ if (ulseek(sb.st_size, SEEK_SET) < 0) return -1; @@ -205,6 +203,7 @@ static int append_func(Elf_Ehdr *const ehdr, return -1; ehdr->e_shoff = _w(new_e_shoff); + set_shnum(ehdr, shdr0, new_shnum); if (ulseek(0, SEEK_SET) < 0) return -1; if (uwrite(ehdr, sizeof(*ehdr)) < 0) -- 2.20.1