Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1078924ybm; Wed, 22 May 2019 17:05:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqz31LiXr3QV1Q4quzy+tfTPgama6LTMsxDc792MCfNvXjQP/j5ZC8ZpoJJNfgZMfFgkosMF X-Received: by 2002:a62:570a:: with SMTP id l10mr99552648pfb.151.1558569931697; Wed, 22 May 2019 17:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558569931; cv=none; d=google.com; s=arc-20160816; b=D/E5ZeNqtsvPHw8r9AFoWTIV9udlHeVqZiBYzfmpTWNh3AJrOI3TOM1QfZrAlHe5jt m5lhwvPqGdVYB9K11jGhvO4YhZ6IZvJreXporxe06LVPoSMWDMxSYR7JAsDxdWbARN+3 4OKlMMlSEWkBeDldtjsPcHV8BqNshbxivCarRwynwm1oUJAkkVQkuiFt2uUcp94e2ioK airM38+MgrmpJUd83JQyZyXJmVoQ6UKd6qncLpuxBgozv44lfO9xzfmPDyyJWjz2p2ao xcSbh3XEdDg+YqvKWYbdPGzxirbuxK0JkVe1ut9p/+ElanRBDfbgpFu3k8WjTPLxInsx IcPA== 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=luwLBDKIn3z25fnz7lGki9GjqpNrTNudgWaLCW/tR28=; b=O8cBoi9qMmvWazNd/3T8Xr+3o5oJLbsqwmXVKbW9olh4H91Eze3c83qFQCBFvWcR0z TSwTpxka4yyo2ws9uDq64TAPEhfrlIryGl2yZshcdwVrGoaO7bi/WQEnp4D/aIDMba1b kewrBJhDna6hfmTBnHcvZ4QAb8DRUnGWSbla4obxKwlPusyfJZ88CsRO2Ivgidgd8VwH lavDgjEiTXwbS6iRwDRbz76CHbW/muXK0F8Z/MgVVkg5DHjGavdDYIzFQy27r3EQCLuy Mv9AoUkGa6eoW7rdvk/GxsgnygbV9zcfFYZE/BntcDF2wRyJABUWq25nmIBfbhZtdYso 6VPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34si6392638plp.305.2019.05.22.17.05.16; Wed, 22 May 2019 17:05:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729730AbfEWAEE (ORCPT + 99 others); Wed, 22 May 2019 20:04:04 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:9705 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728415AbfEWAEA (ORCPT ); Wed, 22 May 2019 20:04:00 -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; Wed, 22 May 2019 17:03:52 -0700 Received: from rlwimi.localdomain (unknown [10.129.221.32]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 31757B2068; Wed, 22 May 2019 20:03:59 -0400 (EDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [RFC][PATCH 11/13] objtool: recordmcount: Start using objtool's elf wrapper Date: Wed, 22 May 2019 17:03:34 -0700 Message-ID: X-Mailer: git-send-email 2.20.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 Use struct elf to grab the file descriptor. We will later move these calls into other functions as we expand the lifetime of the struct elf so that it can be passed to objtool elf.[ch] functions. This creates the libelf/objcount data structures and gives us two separte ways to walk the ELF file -- the libelf/objtool way and the old recordmcount wrapper way which avoids these extra data structures by using indices, offsets, and pointers into the mmapped ELF file. Subsequent patches will convert from the old recordmcount accessors to the libelf/objtool accessors. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c index 8345eb5b681b..71dae95deddc 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -33,6 +33,8 @@ #include "builtin-mcount.h" +#include "elf.h" + #ifndef EM_AARCH64 #define EM_AARCH64 183 #define R_AARCH64_NONE 0 @@ -53,6 +55,8 @@ static void *file_ptr; /* current file pointer location */ static void *file_append; /* added to the end of the file */ static size_t file_append_size; /* how much is added to end of file */ +static struct elf *lf; + /* Per-file resource cleanup when multiple files. */ static void file_append_cleanup(void) { @@ -69,6 +73,9 @@ static void mmap_cleanup(void) else free(file_map); file_map = NULL; + if (lf) + elf_close(lf); + lf = NULL; } /* ulseek, uwrite, ...: Check return value for errors. */ @@ -166,11 +173,12 @@ static void *mmap_file(char const *fname) file_updated = 0; sb.st_size = 0; - fd_map = open(fname, O_RDONLY); - if (fd_map < 0) { + lf = elf_open(fname, O_RDONLY); + if (!lf) { perror(fname); return NULL; } + fd_map = lf->fd; if (fstat(fd_map, &sb) < 0) { perror(fname); goto out; @@ -190,14 +198,14 @@ static void *mmap_file(char const *fname) } if (read(fd_map, file_map, sb.st_size) != sb.st_size) { perror(fname); - free(file_map); - file_map = NULL; + mmap_cleanup(); goto out; } } else mmap_failed = 0; out: - close(fd_map); + elf_close(lf); + lf = NULL; fd_map = -1; file_end = file_map + sb.st_size; -- 2.20.1