Update copyright years
[deliverable/binutils-gdb.git] / gas / config / obj-som.c
1 /* SOM object file format.
2 Copyright (C) 1993-2014 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 3,
9 or (at your option) any later version.
10
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA.
20
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
23
24 #include "as.h"
25 #include "subsegs.h"
26 #include "aout/stab_gnu.h"
27 #include "obstack.h"
28
29 static int version_seen = 0;
30 static int copyright_seen = 0;
31 static int compiler_seen = 0;
32
33 /* Unused by SOM. */
34
35 void
36 obj_read_begin_hook (void)
37 {
38 }
39
40 /* Handle a .compiler directive. This is intended to create the
41 compilation unit auxiliary header for MPE such that the linkeditor
42 can handle SOM extraction from archives. The format of the quoted
43 string is "sourcefile language version" and is delimited by blanks. */
44
45 void
46 obj_som_compiler (int unused ATTRIBUTE_UNUSED)
47 {
48 char *buf;
49 char c;
50 char *filename;
51 char *language_name;
52 char *p;
53 char *version_id;
54
55 if (compiler_seen)
56 {
57 as_bad (_("Only one .compiler pseudo-op per file!"));
58 ignore_rest_of_line ();
59 return;
60 }
61
62 SKIP_WHITESPACE ();
63 if (*input_line_pointer == '\"')
64 {
65 buf = input_line_pointer;
66 ++input_line_pointer;
67 while (is_a_char (next_char_of_string ()))
68 ;
69 c = *input_line_pointer;
70 *input_line_pointer = '\000';
71 }
72 else
73 {
74 as_bad (_("Expected quoted string"));
75 ignore_rest_of_line ();
76 return;
77 }
78
79 /* Parse the quoted string into its component parts. Skip the
80 quote. */
81 filename = buf + 1;
82 p = filename;
83 while (*p != ' ' && *p != '\000')
84 p++;
85 if (*p == '\000')
86 {
87 as_bad (_(".compiler directive missing language and version"));
88 return;
89 }
90 *p = '\000';
91
92 language_name = ++p;
93 while (*p != ' ' && *p != '\000')
94 p++;
95 if (*p == '\000')
96 {
97 as_bad (_(".compiler directive missing version"));
98 return;
99 }
100 *p = '\000';
101
102 version_id = ++p;
103 while (*p != '\000')
104 p++;
105 /* Remove the trailing quote. */
106 *(--p) = '\000';
107
108 compiler_seen = 1;
109 if (! bfd_som_attach_compilation_unit (stdoutput, filename, language_name,
110 "GNU Tools", version_id))
111 {
112 bfd_perror (stdoutput->filename);
113 as_fatal (_("FATAL: Attaching compiler header %s"), stdoutput->filename);
114 }
115 *input_line_pointer = c;
116 demand_empty_rest_of_line ();
117 }
118
119 /* Handle a .version directive. */
120
121 void
122 obj_som_version (int unused ATTRIBUTE_UNUSED)
123 {
124 char *version, c;
125
126 if (version_seen)
127 {
128 as_bad (_("Only one .version pseudo-op per file!"));
129 ignore_rest_of_line ();
130 return;
131 }
132
133 SKIP_WHITESPACE ();
134 if (*input_line_pointer == '\"')
135 {
136 version = input_line_pointer;
137 ++input_line_pointer;
138 while (is_a_char (next_char_of_string ()))
139 ;
140 c = *input_line_pointer;
141 *input_line_pointer = '\000';
142 }
143 else
144 {
145 as_bad (_("Expected quoted string"));
146 ignore_rest_of_line ();
147 return;
148 }
149
150 version_seen = 1;
151 if (!bfd_som_attach_aux_hdr (stdoutput, VERSION_AUX_ID, version))
152 as_fatal (_("attaching version header %s: %s"),
153 stdoutput->filename, bfd_errmsg (bfd_get_error ()));
154
155 *input_line_pointer = c;
156 demand_empty_rest_of_line ();
157 }
158
159 /* Handle a .copyright directive. This probably isn't complete, but
160 it's of dubious value anyway and (IMHO) not worth the time to finish.
161 If you care about copyright strings that much, you fix it. */
162
163 void
164 obj_som_copyright (int unused ATTRIBUTE_UNUSED)
165 {
166 char *copyright, c;
167
168 if (copyright_seen)
169 {
170 as_bad (_("Only one .copyright pseudo-op per file!"));
171 ignore_rest_of_line ();
172 return;
173 }
174
175 SKIP_WHITESPACE ();
176 if (*input_line_pointer == '\"')
177 {
178 copyright = input_line_pointer;
179 ++input_line_pointer;
180 while (is_a_char (next_char_of_string ()))
181 ;
182 c = *input_line_pointer;
183 *input_line_pointer = '\000';
184 }
185 else
186 {
187 as_bad (_("Expected quoted string"));
188 ignore_rest_of_line ();
189 return;
190 }
191
192 copyright_seen = 1;
193 if (!bfd_som_attach_aux_hdr (stdoutput, COPYRIGHT_AUX_ID, copyright))
194 as_fatal (_("attaching copyright header %s: %s"),
195 stdoutput->filename, bfd_errmsg (bfd_get_error ()));
196
197 *input_line_pointer = c;
198 demand_empty_rest_of_line ();
199 }
200
201 /* Perform any initialization necessary for stabs support.
202
203 For SOM we need to create the space which will contain the
204 two stabs subspaces. Additionally we need to set up the
205 space/subspace relationships and set space/subspace attributes
206 which BFD does not understand. */
207
208 void
209 obj_som_init_stab_section (segT seg)
210 {
211 segT saved_seg = now_seg;
212 segT space;
213 subsegT saved_subseg = now_subseg;
214 char *p, *file;
215 unsigned int stroff;
216
217 /* Make the space which will contain the debug subspaces. */
218 space = bfd_make_section_old_way (stdoutput, "$GDB_DEBUG$");
219
220 /* Set SOM specific attributes for the space. In particular we set
221 the space "defined", "private", "sort_key", and "spnum" values.
222
223 Due to a bug in pxdb (called by hpux linker), the sort keys
224 of the various stabs spaces/subspaces need to be "small". We
225 reserve range 72/73 which appear to work well. */
226 obj_set_section_attributes (space, 1, 1, 72, 2);
227 bfd_set_section_alignment (stdoutput, space, 2);
228
229 /* Set the containing space for both stab sections to be $GDB_DEBUG$
230 (just created above). Also set some attributes which BFD does
231 not understand. In particular, access bits, sort keys, and load
232 quadrant. */
233 obj_set_subsection_attributes (seg, space, 0x1f, 73, 0, 0, 0, 0);
234 bfd_set_section_alignment (stdoutput, seg, 2);
235
236 /* Make some space for the first special stab entry and zero the memory.
237 It contains information about the length of this file's
238 stab string and the like. Using it avoids the need to
239 relocate the stab strings.
240
241 The $GDB_STRINGS$ space will be created as a side effect of
242 the call to get_stab_string_offset. */
243 p = frag_more (12);
244 memset (p, 0, 12);
245 as_where (&file, (unsigned int *) NULL);
246 stroff = get_stab_string_offset (file, "$GDB_STRINGS$");
247 know (stroff == 1);
248 md_number_to_chars (p, stroff, 4);
249 seg_info (seg)->stabu.p = p;
250
251 /* Set the containing space for both stab sections to be $GDB_DEBUG$
252 (just created above). Also set some attributes which BFD does
253 not understand. In particular, access bits, sort keys, and load
254 quadrant. */
255 seg = bfd_get_section_by_name (stdoutput, "$GDB_STRINGS$");
256 obj_set_subsection_attributes (seg, space, 0x1f, 72, 0, 0, 0, 0);
257 bfd_set_section_alignment (stdoutput, seg, 2);
258
259 subseg_set (saved_seg, saved_subseg);
260 }
261
262 /* Fill in the counts in the first entry in a .stabs section. */
263
264 static void
265 adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
266 {
267 asection *strsec;
268 char *p;
269 int strsz, nsyms;
270
271 if (strcmp ("$GDB_SYMBOLS$", sec->name))
272 return;
273
274 strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
275 if (strsec)
276 strsz = bfd_section_size (abfd, strsec);
277 else
278 strsz = 0;
279 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
280
281 p = seg_info (sec)->stabu.p;
282 gas_assert (p != 0);
283
284 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
285 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
286 }
287
288 /* Called late in the assembly phase to adjust the special
289 stab entry and to set the starting address for each code subspace. */
290
291 void
292 som_frob_file (void)
293 {
294 bfd_map_over_sections (stdoutput, adjust_stab_sections, (void *) 0);
295 }
296
297 static void
298 obj_som_weak (int ignore ATTRIBUTE_UNUSED)
299 {
300 char *name;
301 int c;
302 symbolS *symbolP;
303
304 do
305 {
306 name = input_line_pointer;
307 c = get_symbol_end ();
308 symbolP = symbol_find_or_make (name);
309 *input_line_pointer = c;
310 SKIP_WHITESPACE ();
311 S_SET_WEAK (symbolP);
312 if (c == ',')
313 {
314 input_line_pointer++;
315 SKIP_WHITESPACE ();
316 if (*input_line_pointer == '\n')
317 c = '\n';
318 }
319 }
320 while (c == ',');
321 demand_empty_rest_of_line ();
322 }
323
324 const pseudo_typeS obj_pseudo_table[] =
325 {
326 {"weak", obj_som_weak, 0},
327 {NULL, NULL, 0}
328 };
This page took 0.038888 seconds and 5 git commands to generate.