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