Align offset passed to mmap
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 10 Feb 2015 13:28:26 +0000 (05:28 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 10 Feb 2015 13:30:56 +0000 (05:30 -0800)
Offset passed to mmap must be a multiple of the page size.  This patch
aligns offset passed to mmap.

* plugin.c (get_view): Align offset passed to mmap.

ld/ChangeLog
ld/plugin.c

index bf59ab3e176d6dc50eea7a424a6aa6dd3380cab4..facbbc14d8af36bc836bba6891ce5536cb765081 100644 (file)
@@ -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
index 5b8a7cfa1173fe554d78f44f5853f3158477bf6d..325481791d6212fe57c3f4cbbf3c5aa498078939 100644 (file)
@@ -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;
This page took 0.028026 seconds and 4 git commands to generate.