Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1543392ybg; Tue, 2 Jun 2020 12:54:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWbMtVSVIskEgaAh3Z+IuiQCTY1EKGVq3icO+6E1BCiwInzySpPWfsxl3Qa0qKT4x8hDDU X-Received: by 2002:a17:907:1118:: with SMTP id qu24mr17605042ejb.287.1591127670841; Tue, 02 Jun 2020 12:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591127670; cv=none; d=google.com; s=arc-20160816; b=l0KdgoD4IUYaj8wvWxpreUoOHyrmqNjeIkrkSMoxHjPhg5I47MjRm8EIpyBz2wXB3i jgLQSTdottcgYArah1XL+ujEGNuC4qecvRQLF6hKGqy8PkE9AoP1dhnq4ftqDye8vACi ciK7oLxTTiv9nCdeyXpF7nQFBxoCMuixKviQdvaqkcsQOfOmzeAWA2fC+zGzxjBvuZ1M ENuYDJFp21gyoLM7t/Be9TUslsTDU/HO8ET9XpfdpiuwPjZUyAfZfOtuBHUN7Gfgi/9O CZ0pDiFO3XKUWfDxdwuzeAKUfHeVMBW0q0eWo1c2IPf7aHYGk6qz6WoafEkeD94z8WLb MUJA== 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=TICD+HHHHvenuy/ptzTXKD9YhTwkenGF1fM7nn2fCR0=; b=osmSr5Krhc23PJVVQB49lrd9QnYmHtUhBFMB2GihCEDHj0kcUO44g9W+1emsCI4RcF ecNFJm6gZoMbei2GXvRhQn5qrOAWg99mbLiQa7fVPmRVpGAF8+SljXcmWh37LboKjHGR zjPYLztdrc+9dToGmkUEmBuvkOt6HRps1tLpzTDu7w8XbP+CwtAFa4H/b50AntVt+pS/ ZnECiTKkP+Nqo72oafq3enpO85UqVvhUuGlPBvAio+OggKwW6qA/b+cLThNURNZtKWXR 36ry3zf1Qb3uzjGb1h+RUHoXyhmeUlrRw5cA9/qnUbaAtuCs4dZtv3wZneLFaGp/jPvC FWEg== 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 u7si1985942edx.125.2020.06.02.12.54.07; Tue, 02 Jun 2020 12:54:30 -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 S1728550AbgFBTvX (ORCPT + 99 others); Tue, 2 Jun 2020 15:51:23 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36862 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728395AbgFBTvH (ORCPT ); Tue, 2 Jun 2020 15:51:07 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 2 Jun 2020 12:51:03 -0700 Received: from sc9-mailhost3.vmware.com (unknown [10.200.192.49]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id BE47C40BEB; Tue, 2 Jun 2020 12:51:03 -0700 (PDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Sami Tolvanen , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v4 22/32] objtool: mcount: Use ELF header from objtool Date: Tue, 2 Jun 2020 12:50:15 -0700 Message-ID: X-Mailer: git-send-email 2.25.1 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 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 85e95e1ea6f6..bfed27f53f75 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -523,21 +523,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) { @@ -566,18 +564,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; @@ -618,37 +616,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