Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1646892ybt; Thu, 18 Jun 2020 13:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8+2EWU8GHq/zbijuMq2xkMG3dFSDzHzvp3z0HdeB9Gt8TEk63Wr9EbWoh1EZ0IgJ/oJDn X-Received: by 2002:aa7:db51:: with SMTP id n17mr44059edt.241.1592513247378; Thu, 18 Jun 2020 13:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513247; cv=none; d=google.com; s=arc-20160816; b=dTDCwxBk0W7W6YKHwHlHNzJbljeseFY5ub5OdNz74lvt2ALOWsBWSl0SumvSyXSLYZ EDte8/mC4lmK0K6O7j5LcsBOOAZ97kaMbzZt+tvI2GJTWGhiFRy7GtWZA9cdX7K9mQvH 8NmRDhTlb3KhOhnkvx3QK71Aa+Ew/mlte59ZM4Wfsoar3KJNxOMiwKlp6/xUZqn+hwsw lB6t+T+4Q5mUDsH84+9QWYTTeE1avjHV2ZQDKFJpFjDtVjLWcCFyUW7vkN5KhQiwfMMF PzSfK7t8bOGCGaQfcLE/w4ZQ5Dcfus2bXWzx75EbtAunCJUlthMf6BcBW2Zp5QlA/mu6 Ir4w== 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=G6lEGhoP/1FyDBtAN5/jhD45pasTuz/t+5ZRPwUBy0Q=; b=S7Uh8W836BKcCVF0/87kP/eZqHotQbVMB2s6dtVg5ipNjQIAUbXet3TyKQc+gb0B89 g0VIPFJOPCpZxGQ2R7Mu92WbB1tqQ/ex5NXgnI2FvxC2rZY6Ow6G9PP+VkUoMSBbNZsS QQR5l86j3LmAb39vvkOlXEIf6DMXLw6u8psUz+3r9pa72Y1cbra9EStz+bsiys5OCEMP z31Todr8mZnPlKkVFrmvuRO6W6QM6/+AX96/aLOciMnSh5cDHru9dS12u8bgAGeE/nUp e9zgW57ebw1jt5WUE2XH3fMLG0+Jb/E4IdhrXR/4CPiwi0t8GT61cWLsLd1KEWu3ZQ7A yJQg== 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 dr10si2726381ejc.204.2020.06.18.13.47.05; Thu, 18 Jun 2020 13:47:27 -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 S1731813AbgFRUkD (ORCPT + 99 others); Thu, 18 Jun 2020 16:40:03 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:4267 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731276AbgFRUjU (ORCPT ); Thu, 18 Jun 2020 16:39:20 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:15 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 7B390B2656; Thu, 18 Jun 2020 16:39:18 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 25/51] objtool: mcount: Use ELF header from objtool Date: Thu, 18 Jun 2020 13:38:11 -0700 Message-ID: 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-001.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 The ELF header is the very first structure in an ELF file. Rather than cast it from the file mapping we use the ELF header extracted via objtool's ELF code. This is the last usage of the open-coded mapping of the ELF file which we will remove in a later step. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.c | 37 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c index aa35173de3d9..f8699e52e7e5 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -525,21 +525,19 @@ static void MIPS64_r_info(Elf64_Rel *const rp, unsigned sym, unsigned type) static int do_file(char const *const fname) { unsigned int reltype = 0; - Elf32_Ehdr *ehdr; int rc = -1; - ehdr = mmap_file(fname); - if (!ehdr) + if (!mmap_file(fname)) goto out; w = w4nat; w2 = w2nat; w8 = w8nat; - switch (ehdr->e_ident[EI_DATA]) { + switch (lf->ehdr.e_ident[EI_DATA]) { static unsigned int const endian = 1; default: fprintf(stderr, "unrecognized ELF data encoding %d: %s\n", - ehdr->e_ident[EI_DATA], fname); + lf->ehdr.e_ident[EI_DATA], fname); goto out; case ELFDATA2LSB: if (*(unsigned char const *)&endian != 1) { @@ -568,18 +566,18 @@ static int do_file(char const *const fname) push_bl_mcount_thumb = push_bl_mcount_thumb_be; break; } /* end switch */ - if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 || - w2(ehdr->e_type) != ET_REL || - ehdr->e_ident[EI_VERSION] != EV_CURRENT) { + if (memcmp(ELFMAG, lf->ehdr.e_ident, SELFMAG) != 0 || + lf->ehdr.e_type != ET_REL || + lf->ehdr.e_ident[EI_VERSION] != EV_CURRENT) { fprintf(stderr, "unrecognized ET_REL file %s\n", fname); goto out; } gpfx = '_'; - switch (w2(ehdr->e_machine)) { + switch (lf->ehdr.e_machine) { default: fprintf(stderr, "unrecognized e_machine %u %s\n", - w2(ehdr->e_machine), fname); + lf->ehdr.e_machine, fname); goto out; case EM_386: reltype = R_386_32; @@ -620,37 +618,36 @@ static int do_file(char const *const fname) break; } /* end switch */ - switch (ehdr->e_ident[EI_CLASS]) { + switch (lf->ehdr.e_ident[EI_CLASS]) { default: fprintf(stderr, "unrecognized ELF class %d %s\n", - ehdr->e_ident[EI_CLASS], fname); + lf->ehdr.e_ident[EI_CLASS], fname); goto out; case ELFCLASS32: - if (w2(ehdr->e_ehsize) != sizeof(Elf32_Ehdr) - || w2(ehdr->e_shentsize) != sizeof(Elf32_Shdr)) { + if (lf->ehdr.e_ehsize != sizeof(Elf32_Ehdr) + || lf->ehdr.e_shentsize != sizeof(Elf32_Shdr)) { fprintf(stderr, "unrecognized ET_REL file: %s\n", fname); goto out; } - if (w2(ehdr->e_machine) == EM_MIPS) { + if (lf->ehdr.e_machine == EM_MIPS) { reltype = R_MIPS_32; is_fake_mcount = MIPS_is_fake_mcount; } rc = do32(reltype); break; case ELFCLASS64: { - Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr; - if (w2(ghdr->e_ehsize) != sizeof(Elf64_Ehdr) - || w2(ghdr->e_shentsize) != sizeof(Elf64_Shdr)) { + if (lf->ehdr.e_ehsize != sizeof(Elf64_Ehdr) + || lf->ehdr.e_shentsize != sizeof(Elf64_Shdr)) { fprintf(stderr, "unrecognized ET_REL file: %s\n", fname); goto out; } - if (w2(ghdr->e_machine) == EM_S390) { + if (lf->ehdr.e_machine == EM_S390) { reltype = R_390_64; mcount_adjust_64 = -14; } - if (w2(ghdr->e_machine) == EM_MIPS) { + if (lf->ehdr.e_machine == EM_MIPS) { reltype = R_MIPS_64; Elf64_r_info = MIPS64_r_info; is_fake_mcount = MIPS_is_fake_mcount; -- 2.20.1