Upload Tizen:Base source
[external/binutils.git] / gas / config / obj-som.c
1 /* SOM object file format.
2    Copyright 1993, 1994, 1998, 2000, 2002, 2003, 2004, 2005, 2006,
3    2007, 2008, 2009  Free Software Foundation, Inc.
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 3,
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
19    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20    02110-1301, USA.
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
30 static int version_seen = 0;
31 static int copyright_seen = 0;
32 static int compiler_seen = 0;
33
34 /* Unused by SOM.  */
35
36 void
37 obj_read_begin_hook (void)
38 {
39 }
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
44    string is "sourcefile language version" and is delimited by blanks.  */
45
46 void
47 obj_som_compiler (int unused ATTRIBUTE_UNUSED)
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
93   language_name = ++p;
94   while (*p != ' ' && *p != '\000')
95     p++;
96   if (*p == '\000')
97     {
98       as_bad (_(".compiler directive missing version"));
99       return;
100     }
101   *p = '\000';
102
103   version_id = ++p;
104   while (*p != '\000')
105     p++;
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
122 void
123 obj_som_version (int unused ATTRIBUTE_UNUSED)
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;
152   if (!bfd_som_attach_aux_hdr (stdoutput, VERSION_AUX_ID, version))
153     as_fatal (_("attaching version header %s: %s"),
154               stdoutput->filename, bfd_errmsg (bfd_get_error ()));
155
156   *input_line_pointer = c;
157   demand_empty_rest_of_line ();
158 }
159
160 /* Handle a .copyright directive.   This probably isn't complete, but
161    it's of dubious value anyway and (IMHO) not worth the time to finish.
162    If you care about copyright strings that much, you fix it.  */
163
164 void
165 obj_som_copyright (int unused ATTRIBUTE_UNUSED)
166 {
167   char *copyright, c;
168
169   if (copyright_seen)
170     {
171       as_bad (_("Only one .copyright pseudo-op per file!"));
172       ignore_rest_of_line ();
173       return;
174     }
175
176   SKIP_WHITESPACE ();
177   if (*input_line_pointer == '\"')
178     {
179       copyright = input_line_pointer;
180       ++input_line_pointer;
181       while (is_a_char (next_char_of_string ()))
182         ;
183       c = *input_line_pointer;
184       *input_line_pointer = '\000';
185     }
186   else
187     {
188       as_bad (_("Expected quoted string"));
189       ignore_rest_of_line ();
190       return;
191     }
192
193   copyright_seen = 1;
194   if (!bfd_som_attach_aux_hdr (stdoutput, COPYRIGHT_AUX_ID, copyright))
195     as_fatal (_("attaching copyright header %s: %s"),
196               stdoutput->filename, bfd_errmsg (bfd_get_error ()));
197
198   *input_line_pointer = c;
199   demand_empty_rest_of_line ();
200 }
201
202 /* Perform any initialization necessary for stabs support.
203
204    For SOM we need to create the space which will contain the
205    two stabs subspaces.  Additionally we need to set up the
206    space/subspace relationships and set space/subspace attributes
207    which BFD does not understand.  */
208
209 void
210 obj_som_init_stab_section (segT seg)
211 {
212   segT saved_seg = now_seg;
213   segT space;
214   subsegT saved_subseg = now_subseg;
215   char *p, *file;
216   unsigned int stroff;
217
218   /* Make the space which will contain the debug subspaces.  */
219   space = bfd_make_section_old_way (stdoutput, "$GDB_DEBUG$");
220
221   /* Set SOM specific attributes for the space.  In particular we set
222      the space "defined", "private", "sort_key", and "spnum" values.
223
224      Due to a bug in pxdb (called by hpux linker), the sort keys
225      of the various stabs spaces/subspaces need to be "small".  We
226      reserve range 72/73 which appear to work well.  */
227   obj_set_section_attributes (space, 1, 1, 72, 2);
228   bfd_set_section_alignment (stdoutput, space, 2);
229
230   /* Set the containing space for both stab sections to be $GDB_DEBUG$
231      (just created above).  Also set some attributes which BFD does
232      not understand.  In particular, access bits, sort keys, and load
233      quadrant.  */
234   obj_set_subsection_attributes (seg, space, 0x1f, 73, 0, 0, 0, 0);
235   bfd_set_section_alignment (stdoutput, seg, 2);
236
237   /* Make some space for the first special stab entry and zero the memory.
238      It contains information about the length of this file's
239      stab string and the like.  Using it avoids the need to
240      relocate the stab strings.
241
242      The $GDB_STRINGS$ space will be created as a side effect of
243      the call to get_stab_string_offset.  */
244   p = frag_more (12);
245   memset (p, 0, 12);
246   as_where (&file, (unsigned int *) NULL);
247   stroff = get_stab_string_offset (file, "$GDB_STRINGS$");
248   know (stroff == 1);
249   md_number_to_chars (p, stroff, 4);
250   seg_info (seg)->stabu.p = p;
251
252   /* Set the containing space for both stab sections to be $GDB_DEBUG$
253      (just created above).  Also set some attributes which BFD does
254      not understand.  In particular, access bits, sort keys, and load
255      quadrant.  */
256   seg = bfd_get_section_by_name (stdoutput, "$GDB_STRINGS$");
257   obj_set_subsection_attributes (seg, space, 0x1f, 72, 0, 0, 0, 0);
258   bfd_set_section_alignment (stdoutput, seg, 2);
259
260   subseg_set (saved_seg, saved_subseg);
261 }
262
263 /* Fill in the counts in the first entry in a .stabs section.  */
264
265 static void
266 adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
267 {
268   asection *strsec;
269   char *p;
270   int strsz, nsyms;
271
272   if (strcmp ("$GDB_SYMBOLS$", sec->name))
273     return;
274
275   strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
276   if (strsec)
277     strsz = bfd_section_size (abfd, strsec);
278   else
279     strsz = 0;
280   nsyms = bfd_section_size (abfd, sec) / 12 - 1;
281
282   p = seg_info (sec)->stabu.p;
283   gas_assert (p != 0);
284
285   bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
286   bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
287 }
288
289 /* Called late in the assembly phase to adjust the special
290    stab entry and to set the starting address for each code subspace.  */
291
292 void
293 som_frob_file (void)
294 {
295   bfd_map_over_sections (stdoutput, adjust_stab_sections, (void *) 0);
296 }
297
298 static void
299 obj_som_weak (int ignore ATTRIBUTE_UNUSED)
300 {
301   char *name;
302   int c;
303   symbolS *symbolP;
304
305   do
306     {
307       name = input_line_pointer;
308       c = get_symbol_end ();
309       symbolP = symbol_find_or_make (name);
310       *input_line_pointer = c;
311       SKIP_WHITESPACE ();
312       S_SET_WEAK (symbolP);
313       if (c == ',')
314         {
315           input_line_pointer++;
316           SKIP_WHITESPACE ();
317           if (*input_line_pointer == '\n')
318             c = '\n';
319         }
320     }
321   while (c == ',');
322   demand_empty_rest_of_line ();
323 }
324
325 const pseudo_typeS obj_pseudo_table[] =
326 {
327   {"weak", obj_som_weak, 0},
328   {NULL, NULL, 0}
329 };