From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8865FC433E0 for ; Thu, 18 Jun 2020 20:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62FB820890 for ; Thu, 18 Jun 2020 20:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729178AbgFRUm5 (ORCPT ); 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