Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10010884ybi; Wed, 24 Jul 2019 14:07:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDWugb8z4TPcVnvkKWpUzCBB5VdTbxLVcEmBXmzXC7FapcYERUKEa/utmyj8X2QIZ7lqjG X-Received: by 2002:a17:90a:22aa:: with SMTP id s39mr88802344pjc.39.1564002459895; Wed, 24 Jul 2019 14:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564002459; cv=none; d=google.com; s=arc-20160816; b=T1ILEzjhQG7y+gqgkgd0oJgUes7Vd4xWNawN/Qh5Am5i6Tg8PCZ/lBbWe++sYj+Wlq xrx2Dyqd6wxf4Lth1uMW7J1TiGCd0eurKz7rXo15OtXSGlQ9rq8eHIU53L+cfMxO9M0L 4KxfR4IMnhVa49hJSDoOttiM8ImvUcKwMOso241XaogMdbLHf8sWrgF9G/BtAmmiT9fR wa/Zqx0xDB2UYQVzXPjmDGRxZyDLUE0+EuYgd70McUTIjGeOgbEMK0UKfoNmLPx54OYq XW/Ebq0vlO6ovSZ2Esk/KuMaJC4T7MEle2JGiJMFySie2+2B7TFeNpi58AiYpFDer6uN VLHQ== 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=bY9o4GDhnWkErmC6up4p91YpkifwYwERoib7/zEURaQ=; b=NxAC9t5vl23ZZLplReY0M5hhd/O5vfQsD7w6tArl9HCsxofeJXHfMuZmNHZM+5CnW3 Upk+HNFIv3wpiLVHC1V+RwI4JSkifU+88klB69D9LszpR3sGd2aRzAPAsDsCyXIm71lk fHrDU0KBpN279ak00BAZLACbKpYYI/y4jMDUj+WXr6UgpMPdTT+hwI1+4BFB1hpirFKr y65enIT5yS+JPuLCAEM7701HRo0KV6MKIKMak5gl3t2lE67S7kphe3rCcLLD09dnw2uu nwMbH4+dphUxkdZ7jpfnCW4Y2uti8nZNQbSSktMzycHxWr0n5Tt5kEtKTAUH7aoN7+tG ckmw== 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 w62si14782408pgd.209.2019.07.24.14.07.25; Wed, 24 Jul 2019 14:07:39 -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 S2388342AbfGXVGI (ORCPT + 99 others); Wed, 24 Jul 2019 17:06:08 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:9569 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387990AbfGXVFb (ORCPT ); Wed, 24 Jul 2019 17:05:31 -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; Wed, 24 Jul 2019 14:05:14 -0700 Received: from rlwimi.localdomain (unknown [10.166.65.164]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id F0C6340708; Wed, 24 Jul 2019 14:05:29 -0700 (PDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [PATCH v3 11/13] objtool: recordmcount: Start using objtool's elf wrapper Date: Wed, 24 Jul 2019 14:05:05 -0700 Message-ID: <5a7c9800dea10ebcc7deeafa8bb8b4b53c68e458.1563992889.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-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 2de31e2913d1..28b5c5e4beae 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_read(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