]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/obj-som.c
Update copyright years
[thirdparty/binutils-gdb.git] / gas / config / obj-som.c
CommitLineData
252b5132 1/* SOM object file format.
4b95cf5c 2 Copyright (C) 1993-2014 Free Software Foundation, Inc.
252b5132
RH
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
ec2655a6 8 published by the Free Software Foundation; either version 3,
252b5132
RH
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
4b4da160
NC
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA.
252b5132
RH
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
252b5132
RH
29static int version_seen = 0;
30static int copyright_seen = 0;
31static int compiler_seen = 0;
32
33/* Unused by SOM. */
28e4f854
KH
34
35void
ea1562b3 36obj_read_begin_hook (void)
28e4f854
KH
37{
38}
252b5132
RH
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
28e4f854 43 string is "sourcefile language version" and is delimited by blanks. */
252b5132
RH
44
45void
ea1562b3 46obj_som_compiler (int unused ATTRIBUTE_UNUSED)
252b5132
RH
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 {
bd3ba5d1 57 as_bad (_("Only one .compiler pseudo-op per file!"));
252b5132
RH
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 {
bd3ba5d1 74 as_bad (_("Expected quoted string"));
252b5132
RH
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 {
bd3ba5d1 87 as_bad (_(".compiler directive missing language and version"));
252b5132
RH
88 return;
89 }
90 *p = '\000';
91
28e4f854
KH
92 language_name = ++p;
93 while (*p != ' ' && *p != '\000')
94 p++;
252b5132
RH
95 if (*p == '\000')
96 {
bd3ba5d1 97 as_bad (_(".compiler directive missing version"));
252b5132
RH
98 return;
99 }
100 *p = '\000';
101
28e4f854
KH
102 version_id = ++p;
103 while (*p != '\000')
104 p++;
252b5132
RH
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);
bd3ba5d1 113 as_fatal (_("FATAL: Attaching compiler header %s"), stdoutput->filename);
252b5132
RH
114 }
115 *input_line_pointer = c;
116 demand_empty_rest_of_line ();
117}
118
119/* Handle a .version directive. */
120
121void
ea1562b3 122obj_som_version (int unused ATTRIBUTE_UNUSED)
252b5132
RH
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;
b34976b6 151 if (!bfd_som_attach_aux_hdr (stdoutput, VERSION_AUX_ID, version))
885afe7b
AM
152 as_fatal (_("attaching version header %s: %s"),
153 stdoutput->filename, bfd_errmsg (bfd_get_error ()));
154
252b5132
RH
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
163void
ea1562b3 164obj_som_copyright (int unused ATTRIBUTE_UNUSED)
252b5132
RH
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;
b34976b6 193 if (!bfd_som_attach_aux_hdr (stdoutput, COPYRIGHT_AUX_ID, copyright))
885afe7b
AM
194 as_fatal (_("attaching copyright header %s: %s"),
195 stdoutput->filename, bfd_errmsg (bfd_get_error ()));
196
252b5132
RH
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
208void
ea1562b3 209obj_som_init_stab_section (segT seg)
252b5132
RH
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
28e4f854 221 the space "defined", "private", "sort_key", and "spnum" values.
252b5132
RH
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. */
351e2b5a 233 obj_set_subsection_attributes (seg, space, 0x1f, 73, 0, 0, 0, 0);
252b5132
RH
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
28e4f854 238 stab string and the like. Using it avoids the need to
252b5132
RH
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$");
351e2b5a 256 obj_set_subsection_attributes (seg, space, 0x1f, 72, 0, 0, 0, 0);
252b5132
RH
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
264static void
5a49b8ac 265adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
252b5132
RH
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;
9c2799c2 282 gas_assert (p != 0);
252b5132
RH
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
aaa2624b 288/* Called late in the assembly phase to adjust the special
252b5132
RH
289 stab entry and to set the starting address for each code subspace. */
290
291void
ea1562b3 292som_frob_file (void)
252b5132 293{
5a49b8ac 294 bfd_map_over_sections (stdoutput, adjust_stab_sections, (void *) 0);
252b5132 295}
f5795b08
CM
296
297static void
ea1562b3 298obj_som_weak (int ignore ATTRIBUTE_UNUSED)
f5795b08
CM
299{
300 char *name;
301 int c;
302 symbolS *symbolP;
28e4f854 303
f5795b08
CM
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);
f5795b08 312 if (c == ',')
28e4f854
KH
313 {
314 input_line_pointer++;
315 SKIP_WHITESPACE ();
316 if (*input_line_pointer == '\n')
317 c = '\n';
318 }
f5795b08
CM
319 }
320 while (c == ',');
321 demand_empty_rest_of_line ();
322}
ea1562b3
NC
323
324const pseudo_typeS obj_pseudo_table[] =
325{
326 {"weak", obj_som_weak, 0},
327 {NULL, NULL, 0}
328};