Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5218329ybi; Tue, 11 Jun 2019 22:02:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUWYHVcE98KFiQfr2pfGQC2zzDzU+zFP9YDM8jdHOs5JF70NBY6PIjIoc/e4OU+pYECDm5 X-Received: by 2002:a17:90a:9f93:: with SMTP id o19mr31140961pjp.70.1560315727652; Tue, 11 Jun 2019 22:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560315727; cv=none; d=google.com; s=arc-20160816; b=rgYvnA/uZO0qN/WnEuQZpsIKyzjt1WWlYdznDEoT9MuJ0Vg5JYTJSBty/Do/kBcI+5 DvhlsZLn8hBEk2AkvvdyxTpv61DxZ40Ojyv3gFTF1TJMbCN7u10UA8V/6w0B1uqmdef9 xWKfgT89rYE+0kE1vFGDHLKEViy42qttoRrfG1PMCPCSsT3GIoamR24OqddSATplJUQ3 avCIy+jB9bplboBaZXpTcDVFfGOEFydYBJkk/C4lcqw4dk5oxgYFIOlezWU9GI5xfNqB 6NSxSeh9kYVXpsRhjRn1K/PsPgRHULbcQMofAkkyU/TvWmr/W31v5dRy2awR4AdTimYW Uzvw== 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=LjB9vDf+51IsqL5YTd+ow5xfFoLLAquq71+hruC9D4E=; b=LeaunPkFy2UAg2+DuPvlwbujvLzWLgT5OzgTA84qpU9kEF0KsfECiHUQjb41vh0U/q pXthSmcXal0wkDdeDc2djuGVkT/LWXu/nBdJ8SQrJKSeQ+NXBbD6NQYr3w3GooX23/aA IXBveN2zLLnp4gfijhWnULAZNa2Al0rOuGK3hFhelDpzBvD3o1n2VBAHHPwE+7m3x5Gp 485BgO+2wc93hYNUpfhO5d7b9UttmVdQp3rxTDdBHAYW91a00GpwJfrruG0s9VVoHb3G b0BrM5iwHzyRaNVIq5UETscUn/yghd5JRXHaOZ5u4mw58rpW0zIH0+PJZKSchklzC079 4F3g== 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 y21si10636888pfe.116.2019.06.11.22.01.50; Tue, 11 Jun 2019 22:02:07 -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 S2391640AbfFKWWo (ORCPT + 99 others); Tue, 11 Jun 2019 18:22:44 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:3298 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436796AbfFKWWV (ORCPT ); Tue, 11 Jun 2019 18:22:21 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 11 Jun 2019 15:22:12 -0700 Received: from rlwimi.localdomain (unknown [10.129.220.121]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id D536241BAF; Tue, 11 Jun 2019 15:22:18 -0700 (PDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [PATCH v2 11/13] objtool: recordmcount: Start using objtool's elf wrapper Date: Tue, 11 Jun 2019 15:21:53 -0700 Message-ID: <0e19d11de05d6d989c8f97d5afff713bf406a6eb.1560285597.git.mhelsley@vmware.com> 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-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 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 2de31e2913d1..61050b78d5a0 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