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