mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matt Helsley <mhelsley@vmware.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Matt Helsley <mhelsley@vmware.com>
Subject: [RFC][PATCH 11/13] objtool: recordmcount: Start using objtool's elf wrapper
Date: Wed, 22 May 2019 17:03:34 -0700	[thread overview]
Message-ID: <f02bf7b47d8bf7307051ebe0e205edd97f4f4c6d.1558569448.git.mhelsley@vmware.com> (raw)
In-Reply-To: <cover.1558569448.git.mhelsley@vmware.com>

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 <mhelsley@vmware.com>
---
 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


  parent reply	other threads:[~2019-05-23  0:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23  0:03 [RFC][PATCH 00/13] Cleanup recordmcount and begin objtool conversion Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 01/13] recordmcount: Remove redundant strcmp Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 02/13] recordmcount: Remove uread() Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 03/13] recordmcount: Remove unused fd from uwrite() and ulseek() Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 04/13] recordmcount: Rewrite error/success handling Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 05/13] recordmcount: Kernel style function signature formatting Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 06/13] recordmcount: Kernel style formatting Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 07/13] recordmcount: Remove redundant cleanup() calls Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 08/13] recordmcount: Clarify what cleanup() does Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 09/13] objtool: Prepare to merge recordmcount Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 10/13] objtool: Make recordmcount into an objtool subcmd Matt Helsley
2019-05-28 14:54   ` Josh Poimboeuf
2019-05-23  0:03 ` Matt Helsley [this message]
2019-05-23  0:03 ` [RFC][PATCH 12/13] objtool: recordmcount: Search for __mcount_loc before walking the sections Matt Helsley
2019-05-23  0:03 ` [RFC][PATCH 13/13] objtool: recordmcount: Convert do_func() relhdrs Matt Helsley
2019-05-28 14:43 ` [RFC][PATCH 00/13] Cleanup recordmcount and begin objtool conversion Josh Poimboeuf
2019-05-28 14:50   ` Steven Rostedt
2019-05-29 13:41   ` Peter Zijlstra
2019-05-29 14:11     ` Josh Poimboeuf
2019-05-30 23:52       ` Matt Helsley
2019-05-31 18:34         ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f02bf7b47d8bf7307051ebe0e205edd97f4f4c6d.1558569448.git.mhelsley@vmware.com \
    --to=mhelsley@vmware.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®