Fixes to allow sources to compile under Solaris 2.8
[deliverable/binutils-gdb.git] / bfd / vms-hdr.c
1 /* vms-hdr.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
4
5 HDR record handling functions
6 EMH record handling functions
7 and
8 EOM record handling functions
9 EEOM record handling functions
10
11 Written by Klaus K"ampf (kkaempf@rmi.de)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26
27 #include <ctype.h>
28
29 #include "bfd.h"
30 #include "sysdep.h"
31 #include "bfdlink.h"
32 #include "libbfd.h"
33
34 #include "vms.h"
35
36 #ifdef HAVE_ALLOCA_H
37 #include <alloca.h>
38 #endif
39 /*---------------------------------------------------------------------------*/
40
41
42 /* Read & process emh record
43 return 0 on success, -1 on error */
44
45 int
46 _bfd_vms_slurp_hdr (abfd, objtype)
47 bfd *abfd;
48 int objtype;
49 {
50 unsigned char *ptr;
51 unsigned char *vms_rec;
52 int subtype;
53
54 vms_rec = PRIV(vms_rec);
55
56 #if VMS_DEBUG
57 vms_debug(2, "HDR/EMH\n");
58 #endif
59
60 switch (objtype)
61 {
62 case OBJ_S_C_HDR:
63 subtype = vms_rec[1];
64 break;
65 case EOBJ_S_C_EMH:
66 subtype = bfd_getl16 (vms_rec + 4) + EVAX_OFFSET;
67 break;
68 default:
69 subtype = -1;
70 }
71
72 #if VMS_DEBUG
73 vms_debug(3, "subtype %d\n", subtype);
74 #endif
75
76 switch (subtype)
77 {
78
79 case MHD_S_C_MHD:
80 /*
81 * module header
82 */
83 PRIV(hdr_data).hdr_b_strlvl = vms_rec[2];
84 PRIV(hdr_data).hdr_l_recsiz = bfd_getl16 (vms_rec + 3);
85 PRIV(hdr_data).hdr_t_name = _bfd_vms_save_counted_string (vms_rec + 5);
86 ptr = vms_rec + 5 + vms_rec[5] + 1;
87 PRIV(hdr_data).hdr_t_version = _bfd_vms_save_counted_string (ptr);
88 ptr += *ptr + 1;
89 PRIV(hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
90
91 break;
92
93 case MHD_S_C_LNM:
94 /*
95 *
96 */
97 PRIV(hdr_data).hdr_c_lnm = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
98 break;
99
100 case MHD_S_C_SRC:
101 /*
102 *
103 */
104 PRIV(hdr_data).hdr_c_src = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
105 break;
106
107 case MHD_S_C_TTL:
108 /*
109 *
110 */
111 PRIV(hdr_data).hdr_c_ttl = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
112 break;
113
114 case MHD_S_C_CPR:
115 /*
116 *
117 */
118 break;
119
120 case MHD_S_C_MTC:
121 /*
122 *
123 */
124 break;
125
126 case MHD_S_C_GTX:
127 /*
128 *
129 */
130 break;
131
132 case EMH_S_C_MHD + EVAX_OFFSET:
133 /*
134 * module header
135 */
136 PRIV(hdr_data).hdr_b_strlvl = vms_rec[6];
137 PRIV(hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8);
138 PRIV(hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12);
139 PRIV(hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
140 PRIV(hdr_data).hdr_t_name =
141 _bfd_vms_save_counted_string (vms_rec + 20);
142 ptr = vms_rec + 20 + vms_rec[20] + 1;
143 PRIV(hdr_data).hdr_t_version =
144 _bfd_vms_save_counted_string (ptr);
145 ptr += *ptr + 1;
146 PRIV(hdr_data).hdr_t_date =
147 _bfd_vms_save_sized_string (ptr, 17);
148
149 break;
150
151 case EMH_S_C_LNM + EVAX_OFFSET:
152 /*
153 *
154 */
155 PRIV(hdr_data).hdr_c_lnm =
156 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
157 break;
158
159 case EMH_S_C_SRC + EVAX_OFFSET:
160 /*
161 *
162 */
163 PRIV(hdr_data).hdr_c_src =
164 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
165 break;
166
167 case EMH_S_C_TTL + EVAX_OFFSET:
168 /*
169 *
170 */
171 PRIV(hdr_data).hdr_c_ttl =
172 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
173 break;
174
175 case EMH_S_C_CPR + EVAX_OFFSET:
176 /*
177 *
178 */
179 break;
180
181 case EMH_S_C_MTC + EVAX_OFFSET:
182 /*
183 *
184 */
185 break;
186
187 case EMH_S_C_GTX + EVAX_OFFSET:
188 /*
189 *
190 */
191 break;
192
193 default:
194 bfd_set_error (bfd_error_wrong_format);
195 return -1;
196
197 } /* switch */
198
199 return 0;
200 }
201
202
203 /*-----------------------------------------------------------------------------*/
204 /* Output routines. */
205
206
207 /* Manufacure a VMS like time on a unix based system.
208 stolen from obj-vms.c */
209
210 static unsigned char *
211 get_vms_time_string ()
212 {
213 static unsigned char tbuf[18];
214 #ifndef VMS
215 #include <time.h>
216
217 char *pnt;
218 time_t timeb;
219 time (&timeb);
220 pnt = ctime (&timeb);
221 pnt[3] = 0;
222 pnt[7] = 0;
223 pnt[10] = 0;
224 pnt[16] = 0;
225 pnt[24] = 0;
226 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
227 #else
228 #include <starlet.h>
229 struct
230 {
231 int Size;
232 unsigned char *Ptr;
233 } Descriptor;
234 Descriptor.Size = 17;
235 Descriptor.Ptr = tbuf;
236 SYS$ASCTIM (0, &Descriptor, 0, 0);
237 #endif /* not VMS */
238
239 #if VMS_DEBUG
240 vms_debug (6, "vmstimestring:'%s'\n", tbuf);
241 #endif
242
243 return tbuf;
244 }
245
246
247 /* write object header for bfd abfd */
248
249 int
250 _bfd_vms_write_hdr (abfd, objtype)
251 bfd *abfd;
252 int objtype;
253 {
254 asymbol *symbol;
255 unsigned int symnum;
256 int had_case = 0;
257 int had_file = 0;
258
259
260 #if VMS_DEBUG
261 vms_debug (2, "vms_write_hdr (%p)\n", abfd);
262 #endif
263
264 _bfd_vms_output_alignment (abfd, 2);
265
266 /* MHD */
267
268 if (objtype == OBJ_S_C_HDR)
269 {
270 }
271 else
272 {
273 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
274 _bfd_vms_output_short (abfd, EOBJ_S_C_STRLVL);
275 _bfd_vms_output_long (abfd, 0);
276 _bfd_vms_output_long (abfd, 0);
277 _bfd_vms_output_long (abfd, MAX_OUTREC_SIZE);
278 }
279
280 if (bfd_get_filename (abfd) != 0)
281 {
282 /* strip path and suffix information */
283
284 char *fname, *fout, *fptr;
285
286 fptr = bfd_get_filename (abfd);
287 fname = (char *) alloca (strlen (fptr) + 1);
288 strcpy (fname, fptr);
289 fout = strrchr (fname, ']');
290 if (fout == 0)
291 fout = strchr (fname, ':');
292 if (fout != 0)
293 fout++;
294 else
295 fout = fname;
296
297 /* strip .obj suffix */
298
299 fptr = strrchr (fname, '.');
300 if ((fptr != 0)
301 && (strcasecmp (fptr, ".OBJ") == 0))
302 *fptr = 0;
303
304 fptr = fout;
305 while (*fptr != 0)
306 {
307 if (islower (*fptr))
308 *fptr = toupper (*fptr);
309 fptr++;
310 if ((*fptr == ';')
311 || ((fptr - fout) > 31))
312 *fptr = 0;
313 }
314 _bfd_vms_output_counted (abfd, fout);
315 }
316 else
317 _bfd_vms_output_counted (abfd, "NONAME");
318
319 _bfd_vms_output_counted (abfd, BFD_VERSION);
320 _bfd_vms_output_dump (abfd, get_vms_time_string (), 17);
321 _bfd_vms_output_fill (abfd, 0, 17);
322 _bfd_vms_output_flush (abfd);
323
324 /* LMN */
325
326 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
327 _bfd_vms_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
328 _bfd_vms_output_flush (abfd);
329
330 /* SRC */
331
332 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
333
334 for (symnum = 0; symnum < abfd->symcount; symnum++)
335 {
336 symbol = abfd->outsymbols[symnum];
337
338 if (symbol->flags & BSF_FILE)
339 {
340 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
341 {
342 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
343 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
344
345 if (had_file)
346 break;
347 had_case = 1;
348 continue;
349 }
350
351 _bfd_vms_output_dump (abfd, (unsigned char *)symbol->name, strlen (symbol->name));
352 if (had_case)
353 break;
354 had_file = 1;
355 }
356 }
357
358 if (symnum == abfd->symcount)
359 _bfd_vms_output_dump (abfd, (unsigned char *)"noname", 6);
360
361 _bfd_vms_output_flush (abfd);
362
363 /* TTL */
364
365 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
366 _bfd_vms_output_dump (abfd, (unsigned char *)"TTL", 3);
367 _bfd_vms_output_flush (abfd);
368
369 /* CPR */
370
371 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
372 _bfd_vms_output_dump (abfd,
373 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
374 39);
375 _bfd_vms_output_flush (abfd);
376
377 return 0;
378 }
379
380 /*-----------------------------------------------------------------------------*/
381
382 /* Process EOM/EEOM record
383 return 0 on success, -1 on error */
384
385 int
386 _bfd_vms_slurp_eom (abfd, objtype)
387 bfd *abfd;
388 int objtype;
389 {
390 unsigned char *vms_rec;
391
392 #if VMS_DEBUG
393 vms_debug(2, "EOM/EEOM\n");
394 #endif
395
396 vms_rec = PRIV(vms_rec);
397
398 if ((objtype == OBJ_S_C_EOM)
399 || (objtype == OBJ_S_C_EOMW))
400 {
401 }
402 else
403 {
404 PRIV(eom_data).eom_l_total_lps = bfd_getl32 (vms_rec + 4);
405 PRIV(eom_data).eom_b_comcod = *(vms_rec + 8);
406 if (PRIV(eom_data).eom_b_comcod > 1)
407 {
408 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
409 bfd_set_error (bfd_error_bad_value);
410 return -1;
411 }
412 PRIV(eom_data).eom_has_transfer = false;
413 if (PRIV(rec_size) > 10)
414 {
415 PRIV(eom_data).eom_has_transfer = true;
416 PRIV(eom_data).eom_b_tfrflg = *(vms_rec + 9);
417 PRIV(eom_data).eom_l_psindx = bfd_getl32 (vms_rec + 12);
418 PRIV(eom_data).eom_l_tfradr = bfd_getl32 (vms_rec + 16);
419
420 abfd->start_address = PRIV(eom_data).eom_l_tfradr;
421 }
422 }
423 return 0;
424 }
425
426
427 /* Write eom record for bfd abfd */
428
429 int
430 _bfd_vms_write_eom (abfd, objtype)
431 bfd *abfd;
432 int objtype;
433 {
434 #if VMS_DEBUG
435 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd, objtype);
436 #endif
437
438 _bfd_vms_output_begin (abfd, objtype, -1);
439 _bfd_vms_output_long (abfd, (unsigned long)(PRIV(vms_linkage_index) >> 1));
440 _bfd_vms_output_byte (abfd, 0); /* completion code */
441 _bfd_vms_output_byte (abfd, 0); /* fill byte */
442
443 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
444 {
445 asection *section;
446
447 section = bfd_get_section_by_name (abfd, ".link");
448 if (section == 0)
449 {
450 bfd_set_error (bfd_error_nonrepresentable_section);
451 return -1;
452 }
453 _bfd_vms_output_short (abfd, 0);
454 _bfd_vms_output_long (abfd, (unsigned long)(section->index));
455 _bfd_vms_output_long (abfd,
456 (unsigned long) bfd_get_start_address (abfd));
457 _bfd_vms_output_long (abfd, 0);
458 }
459
460 _bfd_vms_output_end (abfd);
461 return 0;
462 }
This page took 0.048978 seconds and 5 git commands to generate.