]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/vms-hdr.c
* Makefile.am: Run "make dep-am".
[thirdparty/binutils-gdb.git] / bfd / vms-hdr.c
CommitLineData
252b5132
RH
1/* vms-hdr.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
524f76c9 3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
252b5132
RH
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
13This program is free software; you can redistribute it and/or modify
14it under the terms of the GNU General Public License as published by
15the Free Software Foundation; either version 2 of the License, or
16(at your option) any later version.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26
252b5132 27#include "bfd.h"
6a0735ef 28#include "bfdver.h"
252b5132
RH
29#include "sysdep.h"
30#include "bfdlink.h"
3882b010 31#include "safe-ctype.h"
252b5132
RH
32#include "libbfd.h"
33
34#include "vms.h"
35
23ccc829
NC
36#ifdef HAVE_ALLOCA_H
37#include <alloca.h>
38#endif
524f76c9
AJ
39
40static unsigned char *get_vms_time_string PARAMS ((void));
41
42
252b5132
RH
43/*---------------------------------------------------------------------------*/
44
252b5132
RH
45/* Read & process emh record
46 return 0 on success, -1 on error */
47
48int
49_bfd_vms_slurp_hdr (abfd, objtype)
50 bfd *abfd;
51 int objtype;
52{
53 unsigned char *ptr;
54 unsigned char *vms_rec;
55 int subtype;
56
57 vms_rec = PRIV(vms_rec);
58
59#if VMS_DEBUG
60 vms_debug(2, "HDR/EMH\n");
61#endif
62
63 switch (objtype)
64 {
65 case OBJ_S_C_HDR:
66 subtype = vms_rec[1];
67 break;
68 case EOBJ_S_C_EMH:
69 subtype = bfd_getl16 (vms_rec + 4) + EVAX_OFFSET;
70 break;
71 default:
72 subtype = -1;
73 }
74
75#if VMS_DEBUG
76 vms_debug(3, "subtype %d\n", subtype);
77#endif
78
79 switch (subtype)
80 {
81
82 case MHD_S_C_MHD:
83 /*
84 * module header
85 */
86 PRIV(hdr_data).hdr_b_strlvl = vms_rec[2];
87 PRIV(hdr_data).hdr_l_recsiz = bfd_getl16 (vms_rec + 3);
88 PRIV(hdr_data).hdr_t_name = _bfd_vms_save_counted_string (vms_rec + 5);
89 ptr = vms_rec + 5 + vms_rec[5] + 1;
90 PRIV(hdr_data).hdr_t_version = _bfd_vms_save_counted_string (ptr);
91 ptr += *ptr + 1;
92 PRIV(hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
93
94 break;
95
96 case MHD_S_C_LNM:
97 /*
98 *
99 */
100 PRIV(hdr_data).hdr_c_lnm = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
101 break;
102
103 case MHD_S_C_SRC:
104 /*
105 *
106 */
107 PRIV(hdr_data).hdr_c_src = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
108 break;
109
110 case MHD_S_C_TTL:
111 /*
112 *
113 */
114 PRIV(hdr_data).hdr_c_ttl = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
115 break;
116
117 case MHD_S_C_CPR:
118 /*
119 *
120 */
121 break;
122
123 case MHD_S_C_MTC:
124 /*
125 *
126 */
127 break;
128
129 case MHD_S_C_GTX:
130 /*
131 *
132 */
133 break;
134
135 case EMH_S_C_MHD + EVAX_OFFSET:
136 /*
137 * module header
138 */
139 PRIV(hdr_data).hdr_b_strlvl = vms_rec[6];
140 PRIV(hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8);
141 PRIV(hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12);
142 PRIV(hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
143 PRIV(hdr_data).hdr_t_name =
144 _bfd_vms_save_counted_string (vms_rec + 20);
145 ptr = vms_rec + 20 + vms_rec[20] + 1;
146 PRIV(hdr_data).hdr_t_version =
147 _bfd_vms_save_counted_string (ptr);
148 ptr += *ptr + 1;
149 PRIV(hdr_data).hdr_t_date =
150 _bfd_vms_save_sized_string (ptr, 17);
151
152 break;
153
154 case EMH_S_C_LNM + EVAX_OFFSET:
155 /*
156 *
157 */
158 PRIV(hdr_data).hdr_c_lnm =
159 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
160 break;
161
162 case EMH_S_C_SRC + EVAX_OFFSET:
163 /*
164 *
165 */
166 PRIV(hdr_data).hdr_c_src =
167 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
168 break;
169
170 case EMH_S_C_TTL + EVAX_OFFSET:
171 /*
172 *
173 */
174 PRIV(hdr_data).hdr_c_ttl =
175 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
176 break;
177
178 case EMH_S_C_CPR + EVAX_OFFSET:
179 /*
180 *
181 */
182 break;
183
184 case EMH_S_C_MTC + EVAX_OFFSET:
185 /*
186 *
187 */
188 break;
189
190 case EMH_S_C_GTX + EVAX_OFFSET:
191 /*
192 *
193 */
194 break;
195
196 default:
197 bfd_set_error (bfd_error_wrong_format);
198 return -1;
199
200 } /* switch */
201
202 return 0;
203}
204
252b5132
RH
205/*-----------------------------------------------------------------------------*/
206/* Output routines. */
207
252b5132
RH
208/* Manufacure a VMS like time on a unix based system.
209 stolen from obj-vms.c */
210
211static unsigned char *
212get_vms_time_string ()
213{
214 static unsigned char tbuf[18];
215#ifndef VMS
216#include <time.h>
217
218 char *pnt;
219 time_t timeb;
220 time (&timeb);
221 pnt = ctime (&timeb);
222 pnt[3] = 0;
223 pnt[7] = 0;
224 pnt[10] = 0;
225 pnt[16] = 0;
226 pnt[24] = 0;
227 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
228#else
229#include <starlet.h>
230 struct
231 {
232 int Size;
233 unsigned char *Ptr;
234 } Descriptor;
235 Descriptor.Size = 17;
236 Descriptor.Ptr = tbuf;
237 SYS$ASCTIM (0, &Descriptor, 0, 0);
238#endif /* not VMS */
239
240#if VMS_DEBUG
241 vms_debug (6, "vmstimestring:'%s'\n", tbuf);
242#endif
243
244 return tbuf;
245}
246
252b5132
RH
247/* write object header for bfd abfd */
248
249int
250_bfd_vms_write_hdr (abfd, objtype)
251 bfd *abfd;
252 int objtype;
253{
254 asymbol *symbol;
5f771d47 255 unsigned int symnum;
252b5132
RH
256 int had_case = 0;
257 int had_file = 0;
258
252b5132
RH
259#if VMS_DEBUG
260 vms_debug (2, "vms_write_hdr (%p)\n", abfd);
261#endif
262
263 _bfd_vms_output_alignment (abfd, 2);
264
265 /* MHD */
266
267 if (objtype == OBJ_S_C_HDR)
268 {
269 }
270 else
271 {
272 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
273 _bfd_vms_output_short (abfd, EOBJ_S_C_STRLVL);
274 _bfd_vms_output_long (abfd, 0);
275 _bfd_vms_output_long (abfd, 0);
276 _bfd_vms_output_long (abfd, MAX_OUTREC_SIZE);
277 }
278
279 if (bfd_get_filename (abfd) != 0)
280 {
281 /* strip path and suffix information */
282
283 char *fname, *fout, *fptr;
284
285 fptr = bfd_get_filename (abfd);
286 fname = (char *) alloca (strlen (fptr) + 1);
287 strcpy (fname, fptr);
288 fout = strrchr (fname, ']');
289 if (fout == 0)
290 fout = strchr (fname, ':');
291 if (fout != 0)
292 fout++;
293 else
294 fout = fname;
295
296 /* strip .obj suffix */
297
298 fptr = strrchr (fname, '.');
299 if ((fptr != 0)
300 && (strcasecmp (fptr, ".OBJ") == 0))
301 *fptr = 0;
302
303 fptr = fout;
304 while (*fptr != 0)
305 {
3882b010 306 *fptr = TOUPPER (*fptr);
252b5132
RH
307 fptr++;
308 if ((*fptr == ';')
309 || ((fptr - fout) > 31))
310 *fptr = 0;
311 }
312 _bfd_vms_output_counted (abfd, fout);
313 }
314 else
315 _bfd_vms_output_counted (abfd, "NONAME");
316
e43d48cc 317 _bfd_vms_output_counted (abfd, BFD_VERSION_STRING);
252b5132
RH
318 _bfd_vms_output_dump (abfd, get_vms_time_string (), 17);
319 _bfd_vms_output_fill (abfd, 0, 17);
320 _bfd_vms_output_flush (abfd);
321
322 /* LMN */
323
324 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
325 _bfd_vms_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
326 _bfd_vms_output_flush (abfd);
327
328 /* SRC */
329
330 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
331
332 for (symnum = 0; symnum < abfd->symcount; symnum++)
333 {
334 symbol = abfd->outsymbols[symnum];
335
336 if (symbol->flags & BSF_FILE)
337 {
252b5132
RH
338 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
339 {
340 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
341 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
342
343 if (had_file)
344 break;
345 had_case = 1;
346 continue;
347 }
348
dc810e39
AM
349 _bfd_vms_output_dump (abfd, (unsigned char *) symbol->name,
350 (int) strlen (symbol->name));
252b5132
RH
351 if (had_case)
352 break;
353 had_file = 1;
354 }
355 }
356
357 if (symnum == abfd->symcount)
358 _bfd_vms_output_dump (abfd, (unsigned char *)"noname", 6);
359
360 _bfd_vms_output_flush (abfd);
361
362 /* TTL */
363
364 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
365 _bfd_vms_output_dump (abfd, (unsigned char *)"TTL", 3);
366 _bfd_vms_output_flush (abfd);
367
368 /* CPR */
369
370 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
371 _bfd_vms_output_dump (abfd,
372