summaryrefslogtreecommitdiff
path: root/ld/plugin.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2015-02-10 05:28:26 -0800
committerH.J. Lu <hjl.tools@gmail.com>2015-02-10 05:30:56 -0800
commitfe9057895e9224b764c905de470e0e38d6c5efac (patch)
tree2a0baabe0e375b1f2c8de0d637c13342e8aa8425 /ld/plugin.c
parentc1ee941477569693777617d2f5defbba21085216 (diff)
downloadbinutils-gdb-fe9057895e9224b764c905de470e0e38d6c5efac.tar.gz
Align offset passed to mmap
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.
Diffstat (limited to 'ld/plugin.c')
-rw-r--r--ld/plugin.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ld/plugin.c b/ld/plugin.c
index 5b8a7cfa117..325481791d6 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;