This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] Use mmap and cache the view buffer for get_view
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Tue, 10 Feb 2015 05:35:23 -0800
- Subject: Re: [committed, PATCH] Use mmap and cache the view buffer for get_view
- Authentication-results: sourceware.org; auth=none
- References: <20150206170428 dot GA20936 at intel dot com>
On Fri, Feb 6, 2015 at 9:04 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> This patch uses mmap if it is available and works. It also caches the
> view buffer for get_view. I am checking it in.
>
>
> H.J.
> ---
> * configure.ac: Add AC_FUNC_MMAP.
> * config.in: Regenerated.
> * configure: Likewise.
> * plugin.c: Include <sys/mman.h>.
> (MAP_FAILED): New. Defined if not defined.
> (PROT_READ): Likewise.
> (MAP_PRIVATE): Likewise.
> (view_buffer_t): New.
> (plugin_input_file_t): Add view_buffer.
> (get_view): Try mmap and cache the view buffer.
> (plugin_maybe_claim): Initialize view_buffer.
Offset passed to mmap must be a multiple of the page size. This patch
aligns offset passed to mmap. I checked it in.
* plugin.c (get_view): Align offset passed to mmap.
---
ld/ChangeLog | 4 ++++
ld/plugin.c | 15 ++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index bf59ab3..facbbc1 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-10 H.J. Lu <hongjiu.lu@intel.com>
+
+ * plugin.c (get_view): Align offset passed to mmap.
+
2015-02-08 H.J. Lu <hongjiu.lu@intel.com>
* ldfile.c (ldfile_try_open_bfd): Don't call bfd_check_format
diff --git a/ld/plugin.c b/ld/plugin.c
index 5b8a7cf..3254817 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -499,6 +499,9 @@ get_view (const void *handle, const void **viewp)
plugin_input_file_t *input = (plugin_input_file_t *) handle;
char *buffer;
size_t size = input->filesize;
+#if HAVE_GETPAGESIZE
+ off_t offset, bias;
+#endif
ASSERT (called_plugin);
@@ -520,9 +523,15 @@ get_view (const void *handle, const void **viewp)
input->view_buffer.offset = input->offset;
#if HAVE_MMAP
- buffer = mmap (NULL, size, PROT_READ, MAP_PRIVATE, input->fd,
- input->offset);
- if (buffer == MAP_FAILED)
+# if HAVE_GETPAGESIZE
+ bias = input->offset % getpagesize ();;
+ offset = input->offset - bias;
+ size += bias;
+# endif
+ buffer = mmap (NULL, size, PROT_READ, MAP_PRIVATE, input->fd, offset);
+ if (buffer != MAP_FAILED)
+ buffer += bias;
+ else
#endif
{
char *p;
--
2.1.0
--
H.J.