Add patch against GNU Binutils-2.20 to support "meminfo".
[libmeminfo.git] / patches / binutils-2.19.51.0.1.patch
blob26a82877bad633fcd8dba01015c17b3134f27a45
1 diff -Nawur binutils-2.19.51.0.1.orig/ld/ldgram.y binutils-2.19.51.0.1/ld/ldgram.y
2 --- binutils-2.19.51.0.1.orig/ld/ldgram.y 2009-01-26 10:00:54.048764000 +0100
3 +++ binutils-2.19.51.0.1/ld/ldgram.y 2009-01-26 10:24:46.356552000 +0100
4 @@ -144,6 +144,7 @@
5 %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
6 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
7 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
8 +%token CREATE_MEMINFO_TABLE
9 %token <name> VERS_TAG VERS_IDENTIFIER
10 %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
11 %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL
12 @@ -581,6 +582,8 @@
13 { ldlex_script (); ldfile_open_command_file($2); }
14 statement_list_opt END
15 { ldlex_popstate (); }
16 + | CREATE_MEMINFO_TABLE
17 + { lang_add_meminfo_table (); }
20 statement_list:
21 diff -Nawur binutils-2.19.51.0.1.orig/ld/ldlang.c binutils-2.19.51.0.1/ld/ldlang.c
22 --- binutils-2.19.51.0.1.orig/ld/ldlang.c 2009-01-26 10:00:26.569287000 +0100
23 +++ binutils-2.19.51.0.1/ld/ldlang.c 2009-01-26 10:24:23.986804000 +0100
24 @@ -6401,6 +6401,70 @@
25 new_statement (attribute, sizeof (lang_statement_header_type), stat_ptr);
28 +static inline flagword
29 +meminfo_flags (flagword mem_flags)
31 + flagword flags = 0;
32 + enum
33 + {
34 + MEMINFO_READONLY = 0,
35 + MEMINFO_READWRITE = 1,
36 + MEMINFO_EXECUTABLE = 2,
37 + MEMINFO_ALLOCATABLE = 3,
38 + MEMINFO_INITIALIZED = 4
39 + };
41 + flags |= (mem_flags & SEC_READONLY) != 0 ? 1 << MEMINFO_READONLY : 0;
42 + flags |= (mem_flags & SEC_DATA) != 0 ? 1 << MEMINFO_READWRITE : 0;
43 + flags |= (mem_flags & SEC_CODE) != 0 ? 1 << MEMINFO_EXECUTABLE : 0;
44 + flags |= (mem_flags & SEC_ALLOC) != 0 ? 1 << MEMINFO_ALLOCATABLE : 0;
45 + flags |= (mem_flags & SEC_LOAD) != 0 ? 1 << MEMINFO_INITIALIZED : 0;
47 + return flags;
50 +void lang_add_meminfo_table ()
52 + lang_memory_region_type *mem = NULL;
53 + const size_t max_length = 31; /* +1 for the terminating '\0' */
55 + if (link_info.relocatable != 0)
56 + return;
58 + lang_add_assignment (exp_assop ('=', "__meminfo_start", exp_nameop (NAME, ".")));
60 + for (mem = lang_memory_region_list; mem != NULL; mem = mem->next)
61 + {
62 + unsigned int i = 0;
63 + char name[max_length + 1];
65 + /* Skip the DEFAULT_MEMORY_REGION */
66 + if ( strcmp (mem->name,DEFAULT_MEMORY_REGION) == 0)
67 + continue;
69 + memset (name, 0, sizeof (name));
71 + lang_add_data (LONG, exp_intop (mem->origin));
72 + lang_add_data (LONG, exp_intop (mem->length));
73 + lang_add_data (LONG, exp_intop (meminfo_flags(mem->flags)));
74 + lang_add_data (LONG, exp_intop (meminfo_flags(mem->not_flags)));
76 + if (strlen (mem->name) > max_length)
77 + einfo (_("%P: warning: the name of memory region `%s'"
78 + "will be truncated in the meminfo table\n"), mem->name);
80 + strncpy (name, mem->name, max_length);
82 + /* name[max_length] = '\0';
83 + Useless, because of the previous memset(). CV */
85 + for (i = 0; i < max_length + 1; i++)
86 + lang_add_data (BYTE, exp_intop(name[i]));
87 + }
89 + lang_add_assignment (exp_assop ('=', "__meminfo_end", exp_nameop (NAME, ".")));
92 void
93 lang_startup (const char *name)
95 diff -Nawur binutils-2.19.51.0.1.orig/ld/ldlang.h binutils-2.19.51.0.1/ld/ldlang.h
96 --- binutils-2.19.51.0.1.orig/ld/ldlang.h 2009-01-26 10:00:25.516328000 +0100
97 +++ binutils-2.19.51.0.1/ld/ldlang.h 2009-01-26 10:24:24.046737000 +0100
98 @@ -500,6 +500,8 @@
99 (const char *);
100 extern void lang_float
101 (bfd_boolean);
102 +extern void lang_add_meminfo_table
103 + (void);
104 extern void lang_leave_output_section_statement
105 (fill_type *, const char *, lang_output_section_phdr_list *,
106 const char *);
107 diff -Nawur binutils-2.19.51.0.1.orig/ld/ldlex.l binutils-2.19.51.0.1/ld/ldlex.l
108 --- binutils-2.19.51.0.1.orig/ld/ldlex.l 2009-01-26 10:00:54.039786000 +0100
109 +++ binutils-2.19.51.0.1/ld/ldlex.l 2009-01-26 10:24:24.101682000 +0100
110 @@ -295,6 +295,7 @@
111 <BOTH,SCRIPT>"SORT_BY_NAME" { RTOKEN(SORT_BY_NAME); }
112 <BOTH,SCRIPT>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); }
113 <BOTH,SCRIPT>"SORT" { RTOKEN(SORT_BY_NAME); }
114 +<BOTH,SCRIPT>"CREATE_MEMINFO_TABLE" { RTOKEN(CREATE_MEMINFO_TABLE);}
115 <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
116 <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
117 <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
118 diff -Nawur binutils-2.19.51.0.1.orig/ld/ld.texinfo binutils-2.19.51.0.1/ld/ld.texinfo
119 --- binutils-2.19.51.0.1.orig/ld/ld.texinfo 2009-01-26 10:00:24.370472000 +0100
120 +++ binutils-2.19.51.0.1/ld/ld.texinfo 2009-01-26 10:24:23.827957000 +0100
121 @@ -3013,6 +3013,106 @@
122 architecture of an object file by using the @code{objdump} program with
123 the @samp{-f} option.
124 @end ifclear
126 +@kindex CREATE_MEMINFO_TABLE
127 +@cindex memory regions
128 +@cindex meminfo
129 +@item CREATE_MEMINFO
130 +The command @code{CREATE_MEMINFO_TABLE} creates two symbols named
131 +``__meminfo_start'' and ``__meminfo_end'', and a table where
132 +entries are in the following format :
134 +@table @asis
135 +@item origin
136 +32 bits unsigned
137 +@item length
138 +32 bits unsigned
139 +@item flags
140 +32 bits unsigned
141 +@item not_flags
142 +32 bits unsigned
143 +@item name
144 +32 x 8 bits unsigned (including the terminating '\0' character)
145 +@end table
147 +@ref{MEMORY} describes flags (and the meaning of @code{not_flags}), their values
148 +can be extracted from the declaration of @code{struct sec} in @file{bfd.h}:
150 +@table @asis
151 +@item read-only (R)
152 +0x10
153 +@item read/write (W)
154 +0x40
155 +@item executable (X)
156 +0x20
157 +@item allocatable (A)
158 +0x01
159 +@item initialized (I or L)
160 +0x02
161 +@end table
163 +For instance, this memory description:
164 +@smallexample
165 +MEMORY
167 + mem4data (wi) : ORIGIN = 0x00000000, LENGTH = 0x00010000
168 + mem4text (xi) : ORIGIN = 0x40000000, LENGTH = 0x00300000
170 +@end smallexample
171 +will produce these entries :
172 +@smallexample
173 +origin := 0x00000000
174 +length := 0x00010000
175 +flags := 0x40
176 +not_flags := 0x02
177 +name := 'm' 'e' 'm' '4' 'b' 's' 's' '\0'x25
179 +origin := 0x40000000
180 +length := 0x00300000
181 +flags := 0x20 | 0x40
182 +not_flags := 0x00
183 +name := 'm' 'e' 'm' '4' 't' 'e' 'x' 't' '\0'x24
184 +@end smallexample
186 +This allows loaders and runners to check if the memory description
187 +(used to create an executable) is compatible with the target.
189 +The following fragment of linker-script is an example for loaders:
190 +@smallexample
191 +SECTIONS
193 + [...]
194 + .meminfo (NOLOAD) : @{ CREATE_MEMINFO_TABLE @}
195 + [...]
197 +@end smallexample
199 +The following fragment of linker-script is an example for runners:
200 +@smallexample
201 +SECTIONS
203 + [...]
204 + .meminfo : @{ CREATE_MEMINFO_TABLE @} > .data
205 + [...]
207 +@end smallexample
209 +The following fragment of C code is an example for runners:
210 +@smallexample
211 +extern void _meminfo_start;
212 +extern void _meminfo_end;
214 +int main(void)
216 + return printf("meminfo: %p -> %p\n",
217 + &_meminfo_start,
218 + &_meminfo_end);
220 +@end smallexample
222 +Don't forget to use a single leading @code{_} (for C code) and to add @code{&}
223 +to read the value of the start/end of the memory information.
225 @end table
227 @node Assignments
228 diff -Nawur binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.d binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.d
229 --- binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.d 1970-01-01 01:00:00.000000000 +0100
230 +++ binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.d 2009-01-26 10:24:24.145639000 +0100
231 @@ -0,0 +1,13 @@
232 +#source: meminfo.s
233 +#ld: -T meminfo.t
234 +#objdump: -s --section=.meminfo
236 +.*: file format .*
238 +Contents of section .meminfo:
239 + 0000 00000000 00(01)?00(01)?00 (12)?000000(12)? 00000000 ................
240 + 0010 6d656d34 64617461 00000000 00000000 mem4data........
241 + 0020 00000000 00000000 00000000 00000000 ................
242 + 0030 (40)?000000(40)? 00(30)?00(30)?00 (14)?000000(14)? 00000000 ...@..0.........
243 + 0040 6d656d34 74657874 00000000 00000000 mem4text........
244 + 0050 00000000 00000000 00000000 00000000 ................
245 diff -Nawur binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.s binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.s
246 --- binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.s 1970-01-01 01:00:00.000000000 +0100
247 +++ binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.s 2009-01-26 10:24:24.177606000 +0100
248 @@ -0,0 +1 @@
250 diff -Nawur binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.t binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.t
251 --- binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/meminfo.t 1970-01-01 01:00:00.000000000 +0100
252 +++ binutils-2.19.51.0.1/ld/testsuite/ld-scripts/meminfo.t 2009-01-26 10:24:24.207580000 +0100
253 @@ -0,0 +1,10 @@
254 +MEMORY
256 + mem4data (wi) : ORIGIN = 0x00000000, LENGTH = 0x00010000
257 + mem4text (xi) : ORIGIN = 0x40000000, LENGTH = 0x00300000
260 +SECTIONS
262 + .meminfo (NOLOAD) : { CREATE_MEMINFO_TABLE }
264 diff -Nawur binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/script.exp binutils-2.19.51.0.1/ld/testsuite/ld-scripts/script.exp
265 --- binutils-2.19.51.0.1.orig/ld/testsuite/ld-scripts/script.exp 2009-01-26 10:00:50.531289000 +0100
266 +++ binutils-2.19.51.0.1/ld/testsuite/ld-scripts/script.exp 2009-01-26 10:24:24.245543000 +0100
267 @@ -126,3 +126,5 @@
268 } else {
269 check_script
272 +run_dump_test meminfo