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