summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/binutils/binutils-2.23.1/backport/0018-bfd.patch
blob: a29f424abf6f25194619799f19756cc038d338c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 6a7ec91db1a2a7d60d225ee613c9ebaf1e222acd Mon Sep 17 00:00:00 2001
From: Roland McGrath <roland@gnu.org>
Date: Wed, 21 Nov 2012 20:14:41 +0000
Subject: [PATCH 18/27] bfd/ 	* elf-nacl.c
 (segment_nonexecutable_and_has_contents): Renamed to
 ... 	(segment_eligible_for_headers): ... this. 
 Take new arguments 	MAXPAGESIZE and
 SIZEOF_HEADERS.  Return false if the first section's 
 start address doesn't leave space for the headers. 
 (nacl_modify_segment_map): Update caller.

---
 bfd/ChangeLog  |    8 ++++++++
 bfd/elf-nacl.c |   14 ++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 59c36a7..cf65838 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2012-11-21  Roland McGrath  <mcgrathr@google.com>
+
+	* elf-nacl.c (segment_nonexecutable_and_has_contents): Renamed to ...
+	(segment_eligible_for_headers): ... this.  Take new arguments
+	MAXPAGESIZE and SIZEOF_HEADERS.  Return false if the first section's
+	start address doesn't leave space for the headers.
+	(nacl_modify_segment_map): Update caller.
+
 2012-11-19  Joey Ye  <joey.ye@arm.com>
 
 	* elf32-arm.c (elf32_arm_final_link_relocate, 
diff --git a/bfd/elf-nacl.c b/bfd/elf-nacl.c
index 842e367..04659e7 100644
--- a/bfd/elf-nacl.c
+++ b/bfd/elf-nacl.c
@@ -42,11 +42,18 @@ segment_executable (struct elf_segment_map *seg)
   return FALSE;
 }
 
+/* Determine if this segment is eligible to receive the file and program
+   headers.  It must be non-executable and have contents.  Its first
+   section must start far enough past the page boundary to allow space
+   for the headers.  */
 static bfd_boolean
-segment_nonexecutable_and_has_contents (struct elf_segment_map *seg)
+segment_eligible_for_headers (struct elf_segment_map *seg,
+                              bfd_vma maxpagesize, bfd_vma sizeof_headers)
 {
   bfd_boolean any_contents = FALSE;
   unsigned int i;
+  if (seg->count == 0 || seg->sections[0]->lma % maxpagesize < sizeof_headers)
+    return FALSE;
   for (i = 0; i < seg->count; ++i)
     {
       if (seg->sections[i]->flags & SEC_CODE)
@@ -68,6 +75,8 @@ nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
   struct elf_segment_map **first_load = NULL;
   struct elf_segment_map **last_load = NULL;
   bfd_boolean moved_headers = FALSE;
+  int sizeof_headers = bfd_sizeof_headers (abfd, info);
+  bfd_vma maxpagesize = get_elf_backend_data (abfd)->maxpagesize;
 
   if (info != NULL && info->user_phdrs)
     /* The linker script used PHDRS explicitly, so don't change what the
@@ -93,7 +102,8 @@ nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
           /* Now that we've noted the first PT_LOAD, we're looking for
              the first non-executable PT_LOAD with a nonempty p_filesz.  */
           else if (!moved_headers
-                   && segment_nonexecutable_and_has_contents (seg))
+                   && segment_eligible_for_headers (seg, maxpagesize,
+                                                    sizeof_headers))
             {
               /* This is the one we were looking for!
 
-- 
1.7.9.5

OpenPOWER on IntegriCloud