2004-08-31 Robert Bowdidge <bowdidge@apple.com>
[binutils.git] / gas / config / obj-som.c
blob396b500951dd449b43cf31110a0cf676b46da2a3
1 /* SOM object file format.
2 Copyright 1993, 1994, 1998, 2000, 2002 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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.
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.
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.
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
24 #include "as.h"
25 #include "subsegs.h"
26 #include "aout/stab_gnu.h"
27 #include "obstack.h"
29 static void obj_som_weak PARAMS ((int));
30 static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));
32 const pseudo_typeS obj_pseudo_table[] =
34 {"weak", obj_som_weak, 0},
35 {NULL, NULL, 0}
38 static int version_seen = 0;
39 static int copyright_seen = 0;
40 static int compiler_seen = 0;
42 /* Unused by SOM. */
44 void
45 obj_read_begin_hook ()
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
52 string is "sourcefile language version" and is delimited by blanks. */
54 void
55 obj_som_compiler (unused)
56 int unused ATTRIBUTE_UNUSED;
58 char *buf;
59 char c;
60 char *filename;
61 char *language_name;
62 char *p;
63 char *version_id;
65 if (compiler_seen)
67 as_bad ("Only one .compiler pseudo-op per file!");
68 ignore_rest_of_line ();
69 return;
72 SKIP_WHITESPACE ();
73 if (*input_line_pointer == '\"')
75 buf = input_line_pointer;
76 ++input_line_pointer;
77 while (is_a_char (next_char_of_string ()))
79 c = *input_line_pointer;
80 *input_line_pointer = '\000';
82 else
84 as_bad ("Expected quoted string");
85 ignore_rest_of_line ();
86 return;
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')
97 as_bad (".compiler directive missing language and version");
98 return;
100 *p = '\000';
102 language_name = ++p;
103 while (*p != ' ' && *p != '\000')
104 p++;
105 if (*p == '\000')
107 as_bad (".compiler directive missing version");
108 return;
110 *p = '\000';
112 version_id = ++p;
113 while (*p != '\000')
114 p++;
115 /* Remove the trailing quote. */
116 *(--p) = '\000';
118 compiler_seen = 1;
119 if (! bfd_som_attach_compilation_unit (stdoutput, filename, language_name,
120 "GNU Tools", version_id))
122 bfd_perror (stdoutput->filename);
123 as_fatal ("FATAL: Attaching compiler header %s", stdoutput->filename);
125 *input_line_pointer = c;
126 demand_empty_rest_of_line ();
129 /* Handle a .version directive. */
131 void
132 obj_som_version (unused)
133 int unused ATTRIBUTE_UNUSED;
135 char *version, c;
137 if (version_seen)
139 as_bad (_("Only one .version pseudo-op per file!"));
140 ignore_rest_of_line ();
141 return;
144 SKIP_WHITESPACE ();
145 if (*input_line_pointer == '\"')
147 version = input_line_pointer;
148 ++input_line_pointer;
149 while (is_a_char (next_char_of_string ()))
151 c = *input_line_pointer;
152 *input_line_pointer = '\000';
154 else
156 as_bad (_("Expected quoted string"));
157 ignore_rest_of_line ();
158 return;
161 version_seen = 1;
162 if (!bfd_som_attach_aux_hdr (stdoutput, VERSION_AUX_ID, version))
164 bfd_perror (stdoutput->filename);
165 as_perror (_("FATAL: Attaching version header %s"),
166 stdoutput->filename);
167 exit (EXIT_FAILURE);
169 *input_line_pointer = c;
170 demand_empty_rest_of_line ();
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. */
177 void
178 obj_som_copyright (unused)
179 int unused ATTRIBUTE_UNUSED;
181 char *copyright, c;
183 if (copyright_seen)
185 as_bad (_("Only one .copyright pseudo-op per file!"));
186 ignore_rest_of_line ();
187 return;
190 SKIP_WHITESPACE ();
191 if (*input_line_pointer == '\"')
193 copyright = input_line_pointer;
194 ++input_line_pointer;
195 while (is_a_char (next_char_of_string ()))
197 c = *input_line_pointer;
198 *input_line_pointer = '\000';
200 else
202 as_bad (_("Expected quoted string"));
203 ignore_rest_of_line ();
204 return;
207 copyright_seen = 1;
208 if (!bfd_som_attach_aux_hdr (stdoutput, COPYRIGHT_AUX_ID, copyright))
210 bfd_perror (stdoutput->filename);
211 as_perror (_("FATAL: Attaching copyright header %s"),
212 stdoutput->filename);
213 exit (EXIT_FAILURE);
215 *input_line_pointer = c;
216 demand_empty_rest_of_line ();
219 /* Perform any initialization necessary for stabs support.
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. */
226 void
227 obj_som_init_stab_section (seg)
228 segT seg;
230 segT saved_seg = now_seg;
231 segT space;
232 subsegT saved_subseg = now_subseg;
233 char *p, *file;
234 unsigned int stroff;
236 /* Make the space which will contain the debug subspaces. */
237 space = bfd_make_section_old_way (stdoutput, "$GDB_DEBUG$");
239 /* Set SOM specific attributes for the space. In particular we set
240 the space "defined", "private", "sort_key", and "spnum" values.
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);
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. */
252 obj_set_subsection_attributes (seg, space, 0x1f, 73, 0, 0, 0, 0);
253 bfd_set_section_alignment (stdoutput, seg, 2);
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
257 stab string and the like. Using it avoids the need to
258 relocate the stab strings.
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;
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$");
275 obj_set_subsection_attributes (seg, space, 0x1f, 72, 0, 0, 0, 0);
276 bfd_set_section_alignment (stdoutput, seg, 2);
278 subseg_set (saved_seg, saved_subseg);
281 /* Fill in the counts in the first entry in a .stabs section. */
283 static void
284 adjust_stab_sections (abfd, sec, xxx)
285 bfd *abfd;
286 asection *sec;
287 PTR xxx ATTRIBUTE_UNUSED;
289 asection *strsec;
290 char *p;
291 int strsz, nsyms;
293 if (strcmp ("$GDB_SYMBOLS$", sec->name))
294 return;
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;
303 p = seg_info (sec)->stabu.p;
304 assert (p != 0);
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);
310 /* Called late in the assembly phase to adjust the special
311 stab entry and to set the starting address for each code subspace. */
313 void
314 som_frob_file ()
316 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
319 static void
320 obj_som_weak (ignore)
321 int ignore ATTRIBUTE_UNUSED;
323 char *name;
324 int c;
325 symbolS *symbolP;
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 == ',')
340 input_line_pointer++;
341 SKIP_WHITESPACE ();
342 if (*input_line_pointer == '\n')
343 c = '\n';
346 while (c == ',');
347 demand_empty_rest_of_line ();