1 /* vms.c -- Write out a VAX/VMS object file
2 Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by David L. Kashtan */
21 /* Modified by Eric Youngdale to write VMS debug records for program
24 /* Want all of obj-vms.h (as obj-format.h, via targ-env.h, via as.h). */
25 #define WANT_VMS_OBJ_DEFS
32 /* What we do if there is a goof. */
33 #define error as_fatal
35 #ifdef VMS /* These are of no use if we are cross assembling. */
36 #include <fab.h> /* Define File Access Block */
37 #include <nam.h> /* Define NAM Block */
38 #include <xab.h> /* Define XAB - all different types*/
39 extern int sys$
open(), sys$
close(), sys$
asctim();
43 * Version string of the compiler that produced the code we are
44 * assembling. (And this assembler, if we do not have compiler info.)
46 char *compiler_version_string
;
48 extern int flag_hash_long_names
; /* -+ */
49 extern int flag_one
; /* -1; compatibility with gcc 1.x */
50 extern int flag_show_after_trunc
; /* -H */
51 extern int flag_no_hash_mixed_case
; /* -h NUM */
53 /* Flag that determines how we map names. This takes several values, and
54 * is set with the -h switch. A value of zero implies names should be
55 * upper case, and the presence of the -h switch inhibits the case hack.
56 * No -h switch at all sets vms_name_mapping to 0, and allows case hacking.
57 * A value of 2 (set with -h2) implies names should be
58 * all lower case, with no case hack. A value of 3 (set with -h3) implies
59 * that case should be preserved. */
61 /* If the -+ switch is given, then the hash is appended to any name that is
62 * longer than 31 characters, regardless of the setting of the -h switch.
65 char vms_name_mapping
= 0;
67 static symbolS
*Entry_Point_Symbol
= 0; /* Pointer to "_main" */
70 * We augment the "gas" symbol structure with this
74 struct VMS_Symbol
*Next
;
81 struct VMS_Symbol
*VMS_Symbols
= 0;
83 /* We need this to keep track of the various input files, so that we can
84 * give the debugger the correct source line.
89 struct input_file
*next
;
90 struct input_file
*same_file_fpnt
;
100 static struct input_file
*file_root
= (struct input_file
*) NULL
;
104 * Styles of PSECTS (program sections) that we generate; just shorthand
105 * to avoid lists of section attributes. Used by VMS_Psect_Spec().
109 ps_TEXT
, ps_DATA
, ps_COMMON
, ps_CONST
113 * This enum is used to keep track of the various types of variables that
119 BASIC
, POINTER
, ARRAY
, ENUM
, STRUCT
, UNION
, FUNCTION
, VOID
, ALIAS
, UNKNOWN
123 * This structure contains the information from the stabs directives, and the
124 * information is filled in by VMS_typedef_parse. Everything that is needed
125 * to generate the debugging record for a given symbol is present here.
126 * This could be done more efficiently, using nested struct/unions, but for now
127 * I am happy that it works.
129 struct VMS_DBG_Symbol
131 struct VMS_DBG_Symbol
*next
;
132 /* description of what this is */
133 enum advanced_type advanced
;
134 /* this record is for this type */
136 /* For advanced types this is the type referred to. I.e., the type
137 a pointer points to, or the type of object that makes up an
140 /* Use this type when generating a variable def */
142 /* used for arrays - this will be present for all */
144 /* entries, but will be meaningless for non-arrays */
146 /* Size in bytes of the data type. For an array, this is the size
147 of one element in the array */
149 /* Number of the structure/union/enum - used for ref */
153 #define SYMTYPLST_SIZE (1<<4) /* 16; must be power of two */
154 #define SYMTYP_HASH(x) ((unsigned)(x) & (SYMTYPLST_SIZE-1))
155 struct VMS_DBG_Symbol
*VMS_Symbol_type_list
[SYMTYPLST_SIZE
];
158 * We need this structure to keep track of forward references to
159 * struct/union/enum that have not been defined yet. When they are ultimately
160 * defined, then we can go back and generate the TIR commands to make a back
166 struct forward_ref
*next
;
172 struct forward_ref
*f_ref_root
= (struct forward_ref
*) NULL
;
175 * This routine is used to compare the names of certain types to various
176 * fixed types that are known by the debugger.
178 #define type_check(X) !strcmp (symbol_name, X)
181 * This variable is used to keep track of the name of the symbol we are
182 * working on while we are parsing the stabs directives.
184 static const char *symbol_name
;
186 /* We use this counter to assign numbers to all of the structures, unions
187 * and enums that we define. When we actually declare a variable to the
188 * debugger, we can simply do it by number, rather than describing the
189 * whole thing each time.
192 static structure_count
= 0;
194 /* This variable is used to indicate that we are making the last attempt to
195 parse the stabs, and that we should define as much as we can, and ignore
198 static int final_pass
;
200 /* This variable is used to keep track of the current structure number
201 * for a given variable. If this is < 0, that means that the structure
202 * has not yet been defined to the debugger. This is still cool, since
203 * the VMS object language has ways of fixing things up after the fact,
204 * so we just make a note of this, and generate fixups at the end.
206 static int struct_number
;
208 /* This is used to distinguish between D_float and G_float for telling
209 the debugger about doubles. gcc outputs the same .stabs regardless
210 of whether -mg is used to select alternate doubles. */
212 static int vax_g_doubles
= 0;
214 /* Local symbol references (used to handle N_ABS symbols; gcc does not
215 generate those, but they're possible with hand-coded assembler input)
216 are always made relative to some particular environment. If the current
217 input has any such symbols, then we expect this to get incremented
218 exactly once and end up having all of them be in environment #0. */
220 static int Current_Environment
= -1;
222 /* Every object file must specify an module name, which is also used by
223 traceback records. Set in Write_VMS_MHD_Records(). */
225 static char Module_Name
[255+1];
228 * Variable descriptors are used tell the debugger the data types of certain
229 * more complicated variables (basically anything involving a structure,
230 * union, enum, array or pointer). Some non-pointer variables of the
231 * basic types that the debugger knows about do not require a variable
234 * Since it is impossible to have a variable descriptor longer than 128
235 * bytes by virtue of the way that the VMS object language is set up,
236 * it makes not sense to make the arrays any longer than this, or worrying
237 * about dynamic sizing of the array.
239 * These are the arrays and counters that we use to build a variable
243 #define MAX_DEBUG_RECORD 128
244 static char Local
[MAX_DEBUG_RECORD
]; /* buffer for variable descriptor */
245 static char Asuffix
[MAX_DEBUG_RECORD
]; /* buffer for array descriptor */
246 static int Lpnt
; /* index into Local */
247 static int Apoint
; /* index into Asuffix */
248 static char overflow
; /* flag to indicate we have written too much*/
249 static int total_len
; /* used to calculate the total length of variable
250 descriptor plus array descriptor - used for len byte*/
252 /* Flag if we have told user about finding global constants in the text
254 static int gave_compiler_message
= 0;
258 * Global data (Object records limited to 512 bytes by VAX-11 "C" runtime)
260 static int VMS_Object_File_FD
; /* File Descriptor for object file */
261 static char Object_Record_Buffer
[512]; /* Buffer for object file records */
262 static int Object_Record_Offset
;/* Offset to end of data */
263 static int Current_Object_Record_Type
; /* Type of record in above */
266 * Macros for moving data around. Must work on big-endian systems.
268 #ifdef VMS /* These are more efficient for VMS->VMS systems */
269 #define COPY_LONG(dest,val) ( *(long *)(dest) = (val) )
270 #define COPY_SHORT(dest,val) ( *(short *)(dest) = (val) )
272 #define COPY_LONG(dest,val) md_number_to_chars ((dest), (val), 4)
273 #define COPY_SHORT(dest,val) md_number_to_chars ((dest), (val), 2)
276 * Macros for placing data into the object record buffer.
278 #define PUT_LONG(val) \
279 ( COPY_LONG (&Object_Record_Buffer[Object_Record_Offset], (val)), \
280 Object_Record_Offset += 4 )
282 #define PUT_SHORT(val) \
283 ( COPY_SHORT (&Object_Record_Buffer[Object_Record_Offset], (val)), \
284 Object_Record_Offset += 2 )
286 #define PUT_CHAR(val) ( Object_Record_Buffer[Object_Record_Offset++] = (val) )
288 #define PUT_COUNTED_STRING(cp) do { \
289 register const char *p = (cp); \
290 PUT_CHAR ((char) strlen (p)); \
291 while (*p) PUT_CHAR (*p++); } while (0)
294 * Macro for determining if a Name has psect attributes attached
297 #define PSECT_ATTRIBUTES_STRING "$$PsectAttributes_"
298 #define PSECT_ATTRIBUTES_STRING_LENGTH 18
300 #define HAS_PSECT_ATTRIBUTES(Name) \
301 (strncmp ((*Name == '_' ? Name + 1 : Name), \
302 PSECT_ATTRIBUTES_STRING, \
303 PSECT_ATTRIBUTES_STRING_LENGTH) == 0)
306 /* in: segT out: N_TYPE bits */
307 const short seg_N_TYPE
[] =
313 N_UNDF
, /* unknown */
315 N_UNDF
, /* expression */
319 N_REGISTER
, /* register */
322 const segT N_TYPE_seg
[N_TYPE
+ 2] =
323 { /* N_TYPE == 0x1E = 32-2 */
324 SEG_UNKNOWN
, /* N_UNDF == 0 */
326 SEG_ABSOLUTE
, /* N_ABS == 2 */
328 SEG_TEXT
, /* N_TEXT == 4 */
330 SEG_DATA
, /* N_DATA == 6 */
332 SEG_BSS
, /* N_BSS == 8 */
334 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
335 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
336 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
337 SEG_REGISTER
, /* dummy N_REGISTER for regs = 30 */
342 /* Local support routines which return a value. */
344 static struct input_file
*find_file
PARAMS ((symbolS
*));
345 static struct VMS_DBG_Symbol
*find_symbol
PARAMS ((int));
346 static symbolS
*Define_Routine
PARAMS ((symbolS
*,int,symbolS
*,int));
348 static char *cvt_integer
PARAMS ((char *,int *));
349 static char *fix_name
PARAMS ((char *));
350 static char *get_struct_name
PARAMS ((char *));
352 static offsetT VMS_Initialized_Data_Size
PARAMS ((symbolS
*,unsigned));
354 static int VMS_TBT_Source_File
PARAMS ((char *,int));
355 static int gen1
PARAMS ((struct VMS_DBG_Symbol
*,int));
356 static int forward_reference
PARAMS ((char *));
357 static int final_forward_reference
PARAMS ((struct VMS_DBG_Symbol
*));
358 static int VMS_typedef_parse
PARAMS ((char *));
359 static int hash_string
PARAMS ((const char *));
360 static int VMS_Psect_Spec
PARAMS ((const char *,int,enum ps_type
,
361 struct VMS_Symbol
*));
363 /* Local support routines which don't directly return any value. */
365 static void s_const
PARAMS ((int));
366 static void Create_VMS_Object_File
PARAMS ((void));
367 static void Flush_VMS_Object_Record_Buffer
PARAMS ((void));
368 static void Set_VMS_Object_File_Record
PARAMS ((int));
369 static void Close_VMS_Object_File
PARAMS ((void));
370 static void vms_tir_stack_psect
PARAMS ((int,int,int));
371 static void VMS_Store_Immediate_Data
PARAMS ((const char *,int,int));
372 static void VMS_Set_Data
PARAMS ((int,int,int,int));
373 static void VMS_Store_Struct
PARAMS ((int));
374 static void VMS_Def_Struct
PARAMS ((int));
375 static void VMS_Set_Struct
PARAMS ((int));
376 static void VMS_TBT_Module_Begin
PARAMS ((void));
377 static void VMS_TBT_Module_End
PARAMS ((void));
378 static void VMS_TBT_Routine_Begin
PARAMS ((symbolS
*,int));
379 static void VMS_TBT_Routine_End
PARAMS ((int,symbolS
*));
380 static void VMS_TBT_Block_Begin
PARAMS ((symbolS
*,int,char *));
381 static void VMS_TBT_Block_End
PARAMS ((valueT
));
382 static void VMS_TBT_Line_PC_Correlation
PARAMS ((int,int,int,int));
383 static void VMS_TBT_Source_Lines
PARAMS ((int,int,int));
384 static void fpush
PARAMS ((int,int));
385 static void rpush
PARAMS ((int,int));
386 static void array_suffix
PARAMS ((struct VMS_DBG_Symbol
*));
387 static void new_forward_ref
PARAMS ((int));
388 static void generate_suffix
PARAMS ((struct VMS_DBG_Symbol
*,int));
389 static void bitfield_suffix
PARAMS ((struct VMS_DBG_Symbol
*,int));
390 static void setup_basic_type
PARAMS ((struct VMS_DBG_Symbol
*));
391 static void VMS_DBG_record
PARAMS ((struct VMS_DBG_Symbol
*,int,int,char *));
392 static void VMS_local_stab_Parse
PARAMS ((symbolS
*));
393 static void VMS_stab_parse
PARAMS ((symbolS
*,int,int,int,int));
394 static void VMS_GSYM_Parse
PARAMS ((symbolS
*,int));
395 static void VMS_LCSYM_Parse
PARAMS ((symbolS
*,int));
396 static void VMS_STSYM_Parse
PARAMS ((symbolS
*,int));
397 static void VMS_RSYM_Parse
PARAMS ((symbolS
*,symbolS
*,int));
398 static void VMS_LSYM_Parse
PARAMS ((void));
399 static void Define_Local_Symbols
PARAMS ((symbolS
*,symbolS
*,symbolS
*,int));
400 static void Write_VMS_MHD_Records
PARAMS ((void));
401 static void Write_VMS_EOM_Record
PARAMS ((int,valueT
));
402 static void VMS_Case_Hack_Symbol
PARAMS ((const char *,char *));
403 static void VMS_Modify_Psect_Attributes
PARAMS ((const char *,int *));
404 static void VMS_Global_Symbol_Spec
PARAMS ((const char *,int,int,int));
405 static void VMS_Local_Environment_Setup
PARAMS ((const char *));
406 static void VMS_Emit_Globalvalues
PARAMS ((unsigned,unsigned,char *));
407 static void VMS_Procedure_Entry_Pt
PARAMS ((char *,int,int,int));
408 static void VMS_Set_Psect
PARAMS ((int,int,int));
409 static void VMS_Store_Repeated_Data
PARAMS ((int,char *,int,int));
410 static void VMS_Store_PIC_Symbol_Reference
PARAMS ((symbolS
*,int,
412 static void VMS_Fix_Indirect_Reference
PARAMS ((int,int,fragS
*,fragS
*));
414 /* Support code which used to be inline within vms_write_object_file. */
415 static void vms_fixup_text_section
PARAMS ((unsigned,struct frag
*,struct frag
*));
416 static void synthesize_data_segment
PARAMS ((unsigned,unsigned,struct frag
*));
417 static void vms_fixup_data_section
PARAMS ((unsigned,unsigned));
418 static void global_symbol_directory
PARAMS ((unsigned,unsigned));
419 static void local_symbols_DST
PARAMS ((symbolS
*,symbolS
*));
420 static void vms_build_DST
PARAMS ((unsigned));
423 /* The following code defines the special types of pseudo-ops that we
426 unsigned char const_flag
= IN_DEFAULT_SECTION
;
430 int arg
; /* 3rd field from obj_pseudo_table[]; not needed here */
432 /* Since we don't need `arg', use it as our scratch variable so that
433 we won't get any "not used" warnings about it. */
434 arg
= get_absolute_expression ();
435 subseg_set (SEG_DATA
, (subsegT
) arg
);
437 demand_empty_rest_of_line ();
440 const pseudo_typeS obj_pseudo_table
[] =
442 {"const", s_const
, 0},
444 }; /* obj_pseudo_table */
447 /* Routine to perform RESOLVE_SYMBOL_REDEFINITION(). */
450 vms_resolve_symbol_redef (sym
)
454 * If the new symbol is .comm AND it has a size of zero,
455 * we ignore it (i.e. the old symbol overrides it)
457 if (SEGMENT_TO_SYMBOL_TYPE ((int) now_seg
) == (N_UNDF
| N_EXT
)
458 && frag_now_fix () == 0)
460 as_warn ("compiler emitted zero-size common symbol `%s' already defined",
465 * If the old symbol is .comm and it has a size of zero,
466 * we override it with the new symbol value.
468 if (S_IS_EXTERNAL (sym
) && S_IS_DEFINED (sym
) && S_GET_VALUE (sym
) == 0)
470 as_warn ("compiler redefined zero-size common symbol `%s'",
472 sym
->sy_frag
= frag_now
;
473 S_SET_OTHER (sym
, const_flag
);
474 S_SET_VALUE (sym
, frag_now_fix ());
475 /* Keep N_EXT bit. */
476 sym
->sy_symbol
.n_type
|= SEGMENT_TO_SYMBOL_TYPE ((int) now_seg
);
484 /* `tc_frob_label' handler for colon(symbols.c), used to examine the
485 dummy label(s) gcc inserts at the beginning of each file it generates.
486 gcc 1.x put "gcc_compiled."; gcc 2.x (as of 2.7) puts "gcc2_compiled."
487 and "__gnu_language_<name>" and possibly "__vax_<type>_doubles". */
490 vms_check_for_special_label (symbolP
)
493 /* Special labels only occur prior to explicit section directives. */
494 if ((const_flag
& IN_DEFAULT_SECTION
) != 0)
496 char *sym_name
= S_GET_NAME (symbolP
);
498 if (*sym_name
== '_')
501 if (!strcmp (sym_name
, "__vax_g_doubles"))
503 #if 0 /* not necessary */
504 else if (!strcmp (sym_name
, "__vax_d_doubles"))
507 #if 0 /* these are potential alternatives to tc-vax.c's md_parse_options() */
508 else if (!strcmp (sym_name
, "gcc_compiled."))
510 else if (!strcmp (sym_name
, "__gnu_language_cplusplus"))
511 flag_hash_long_names
= 1;
519 obj_read_begin_hook ()
526 obj_crawl_symbol_chain (headers
)
527 object_headers
*headers
;
531 int symbol_number
= 0;
533 symbolPP
= &symbol_rootP
; /* -> last symbol chain link. */
534 while ((symbolP
= *symbolPP
) != NULL
)
536 resolve_symbol_value (symbolP
);
538 /* OK, here is how we decide which symbols go out into the
539 brave new symtab. Symbols that do are:
541 * symbols with no name (stabd's?)
542 * symbols with debug info in their N_TYPE
543 * symbols with \1 as their 3rd character (numeric labels)
544 * "local labels" needed for PIC fixups
546 Symbols that don't are:
547 * symbols that are registers
549 All other symbols are output. We complain if a deleted
550 symbol was marked external. */
552 if (!S_IS_REGISTER (symbolP
))
554 symbolP
->sy_number
= symbol_number
++;
555 symbolP
->sy_name_offset
= 0;
556 symbolPP
= &(symbol_next (symbolP
));
560 if (S_IS_EXTERNAL (symbolP
) || !S_IS_DEFINED (symbolP
))
562 as_bad ("Local symbol %s never defined", S_GET_NAME (symbolP
));
565 /* Unhook it from the chain. */
566 *symbolPP
= symbol_next (symbolP
);
567 } /* if this symbol should be in the output */
569 } /* for each symbol */
571 H_SET_STRING_SIZE (headers
, string_byte_count
);
572 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
573 } /* obj_crawl_symbol_chain() */
576 /****** VMS OBJECT FILE HACKING ROUTINES *******/
579 /* Create the VMS object file. */
582 Create_VMS_Object_File ()
584 #if defined(eunice) || !defined(VMS)
585 VMS_Object_File_FD
= creat (out_file_name
, 0777, "var");
587 VMS_Object_File_FD
= creat (out_file_name
, 0, "rfm=var",
588 "mbc=16", "deq=64", "fop=tef", "shr=nil");
590 /* Deal with errors. */
591 if (VMS_Object_File_FD
< 0)
592 as_fatal ("Couldn't create VMS object file \"%s\"", out_file_name
);
593 /* Initialize object file hacking variables. */
594 Object_Record_Offset
= 0;
595 Current_Object_Record_Type
= -1;
599 /* Flush the object record buffer to the object file. */
602 Flush_VMS_Object_Record_Buffer ()
604 /* If the buffer is empty, there's nothing to do. */
605 if (Object_Record_Offset
== 0)
608 #ifndef VMS /* For cross-assembly purposes. */
612 /* "Variable-length record" files have a two byte length field
613 prepended to each record. It's normally out-of-band, and native
614 VMS output will insert it automatically for this type of file.
615 When cross-assembling, we must write it explicitly. */
616 md_number_to_chars (RecLen
, Object_Record_Offset
, 2);
617 if (write (VMS_Object_File_FD
, RecLen
, 2) != 2)
618 error ("I/O error writing VMS object file (length prefix)");
619 /* We also need to force the actual record to be an even number of
620 bytes. For native output, that's automatic; when cross-assembling,
621 pad with a NUL byte if length is odd. Do so _after_ writing the
622 pre-padded length. Since our buffer is defined with even size,
623 an odd offset implies that it has some room left. */
624 if ((Object_Record_Offset
& 1) != 0)
625 Object_Record_Buffer
[Object_Record_Offset
++] = '\0';
629 /* Write the data to the file. */
630 if (write (VMS_Object_File_FD
, Object_Record_Buffer
, Object_Record_Offset
)
631 != Object_Record_Offset
)
632 error ("I/O error writing VMS object file");
634 /* The buffer is now empty. */
635 Object_Record_Offset
= 0;
639 /* Declare a particular type of object file record. */
642 Set_VMS_Object_File_Record (Type
)
645 /* If the type matches, we are done. */
646 if (Type
== Current_Object_Record_Type
)
648 /* Otherwise: flush the buffer. */
649 Flush_VMS_Object_Record_Buffer ();
650 /* Remember the new type. */
651 Current_Object_Record_Type
= Type
;
655 /* Close the VMS Object file. */
658 Close_VMS_Object_File ()
660 /* Flush (should never be necessary) and reset saved record-type context. */
661 Set_VMS_Object_File_Record (-1);
663 #ifndef VMS /* For cross-assembly purposes. */
668 /* Write a 2 byte record-length field of -1 into the file, which
669 means end-of-block when read, hence end-of-file when occurring
670 in the file's last block. It is only needed for variable-length
671 record files transferred to VMS as fixed-length record files
672 (typical for binary FTP; NFS shouldn't need it, but it won't hurt). */
673 md_number_to_chars (RecLen
, minus_one
, 2);
674 write (VMS_Object_File_FD
, RecLen
, 2);
677 /* When written on a VMS system, the file header (cf inode) will record
678 the actual end-of-file position and no inline marker is needed. */
681 close (VMS_Object_File_FD
);
685 /****** Text Information and Relocation routines ******/
688 /* Stack Psect base followed by signed, varying-sized offset.
689 Common to several object records. */
692 vms_tir_stack_psect (Psect_Index
, Offset
, Force
)
697 int psect_width
, offset_width
;
699 psect_width
= ((unsigned) Psect_Index
> 255) ? 2 : 1;
700 offset_width
= (Force
|| Offset
> 32767 || Offset
< -32768) ? 4
701 : (Offset
> 127 || Offset
< -128) ? 2 : 1;
702 #define Sta_P(p,o) (((o)<<1) | ((p)-1))
703 /* byte or word psect; byte, word, or longword offset */
704 switch (Sta_P(psect_width
,offset_width
))
706 case Sta_P(1,1): PUT_CHAR (TIR_S_C_STA_PB
);
707 PUT_CHAR ((char)(unsigned char) Psect_Index
);
708 PUT_CHAR ((char) Offset
);
710 case Sta_P(1,2): PUT_CHAR (TIR_S_C_STA_PW
);
711 PUT_CHAR ((char)(unsigned char) Psect_Index
);
714 case Sta_P(1,4): PUT_CHAR (TIR_S_C_STA_PL
);
715 PUT_CHAR ((char)(unsigned char) Psect_Index
);
718 case Sta_P(2,1): PUT_CHAR (TIR_S_C_STA_WPB
);
719 PUT_SHORT (Psect_Index
);
720 PUT_CHAR ((char) Offset
);
722 case Sta_P(2,2): PUT_CHAR (TIR_S_C_STA_WPW
);
723 PUT_SHORT (Psect_Index
);
726 case Sta_P(2,4): PUT_CHAR (TIR_S_C_STA_WPL
);
727 PUT_SHORT (Psect_Index
);
735 /* Store immediate data in current Psect. */
738 VMS_Store_Immediate_Data (Pointer
, Size
, Record_Type
)
745 Set_VMS_Object_File_Record (Record_Type
);
746 /* We can only store as most 128 bytes at a time due to the way that
747 TIR commands are encoded. */
750 i
= (Size
> 128) ? 128 : Size
;
752 /* If we cannot accommodate this record, flush the buffer. */
753 if ((Object_Record_Offset
+ i
+ 1) >= sizeof Object_Record_Buffer
)
754 Flush_VMS_Object_Record_Buffer ();
755 /* If the buffer is empty we must insert record type. */
756 if (Object_Record_Offset
== 0)
757 PUT_CHAR (Record_Type
);
758 /* Store the count. The Store Immediate TIR command is implied by
759 a negative command byte, and the length of the immediate data
760 is abs(command_byte). So, we write the negated length value. */
761 PUT_CHAR ((char) (-i
& 0xff));
762 /* Now store the data. */
764 PUT_CHAR (*Pointer
++);
766 /* Flush the buffer if it is more than 75% full. */
767 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
768 Flush_VMS_Object_Record_Buffer ();
772 /* Make a data reference. */
775 VMS_Set_Data (Psect_Index
, Offset
, Record_Type
, Force
)
781 Set_VMS_Object_File_Record (Record_Type
);
782 /* If the buffer is empty we must insert the record type. */
783 if (Object_Record_Offset
== 0)
784 PUT_CHAR (Record_Type
);
785 /* Stack the Psect base with its offset. */
786 vms_tir_stack_psect (Psect_Index
, Offset
, Force
);
787 /* Set relocation base. */
788 PUT_CHAR (TIR_S_C_STO_PIDR
);
789 /* Flush the buffer if it is more than 75% full. */
790 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
791 Flush_VMS_Object_Record_Buffer ();
795 /* Make a debugger reference to a struct, union or enum. */
798 VMS_Store_Struct (Struct_Index
)
801 /* We are writing a debug record. */
802 Set_VMS_Object_File_Record (OBJ_S_C_DBG
);
803 /* If the buffer is empty we must insert the record type. */
804 if (Object_Record_Offset
== 0)
805 PUT_CHAR (OBJ_S_C_DBG
);
806 PUT_CHAR (TIR_S_C_STA_UW
);
807 PUT_SHORT (Struct_Index
);
808 PUT_CHAR (TIR_S_C_CTL_STKDL
);
809 PUT_CHAR (TIR_S_C_STO_L
);
810 /* Flush the buffer if it is more than 75% full. */
811 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
812 Flush_VMS_Object_Record_Buffer ();
816 /* Make a debugger reference to partially define a struct, union or enum. */
819 VMS_Def_Struct (Struct_Index
)
822 /* We are writing a debug record. */
823 Set_VMS_Object_File_Record (OBJ_S_C_DBG
);
824 /* If the buffer is empty we must insert the record type. */
825 if (Object_Record_Offset
== 0)
826 PUT_CHAR (OBJ_S_C_DBG
);
827 PUT_CHAR (TIR_S_C_STA_UW
);
828 PUT_SHORT (Struct_Index
);
829 PUT_CHAR (TIR_S_C_CTL_DFLOC
);
830 /* Flush the buffer if it is more than 75% full. */
831 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
832 Flush_VMS_Object_Record_Buffer ();
836 VMS_Set_Struct (Struct_Index
)
838 { /* see previous functions for comments */
839 Set_VMS_Object_File_Record (OBJ_S_C_DBG
);
840 if (Object_Record_Offset
== 0)
841 PUT_CHAR (OBJ_S_C_DBG
);
842 PUT_CHAR (TIR_S_C_STA_UW
);
843 PUT_SHORT (Struct_Index
);
844 PUT_CHAR (TIR_S_C_CTL_STLOC
);
845 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
846 Flush_VMS_Object_Record_Buffer ();
850 /****** Traceback Information routines ******/
853 /* Write the Traceback Module Begin record. */
856 VMS_TBT_Module_Begin ()
858 register char *cp
, *cp1
;
862 /* Arrange to store the data locally (leave room for size byte). */
865 *cp
++ = DST_S_C_MODBEG
;
866 *cp
++ = 0; /* flags; not used */
868 * Language type == "C"
870 * (FIXME: this should be based on the input...)
872 COPY_LONG (cp
, DST_S_C_C
);
874 /* Store the module name. */
875 *cp
++ = (char) strlen (Module_Name
);
879 /* Now we can store the record size. */
882 /* Put it into the object record. */
883 VMS_Store_Immediate_Data (Local
, Size
, OBJ_S_C_TBT
);
887 /* Write the Traceback Module End record. */
890 VMS_TBT_Module_End ()
896 Local
[1] = DST_S_C_MODEND
;
897 /* Put it into the object record. */
898 VMS_Store_Immediate_Data (Local
, 2, OBJ_S_C_TBT
);
902 /* Write a Traceback Routine Begin record. */
905 VMS_TBT_Routine_Begin (symbolP
, Psect
)
909 register char *cp
, *cp1
;
915 /* Strip the leading "_" from the name. */
916 Name
= S_GET_NAME (symbolP
);
919 /* Get the text psect offset. */
920 Offset
= S_GET_VALUE (symbolP
);
921 /* Set the record size. */
922 Size
= 1 + 1 + 4 + 1 + strlen (Name
);
924 /* DST type "routine begin". */
925 Local
[1] = DST_S_C_RTNBEG
;
926 /* Uses CallS/CallG. */
928 /* Store the data so far. */
929 VMS_Store_Immediate_Data (Local
, 3, OBJ_S_C_TBT
);
930 /* Make sure we are still generating a OBJ_S_C_TBT record. */
931 if (Object_Record_Offset
== 0)
932 PUT_CHAR (OBJ_S_C_TBT
);
933 /* Stack the address. */
934 vms_tir_stack_psect (Psect
, Offset
, 0);
935 /* Store the data reference. */
936 PUT_CHAR (TIR_S_C_STO_PIDR
);
937 /* Store the counted string as data. */
940 Size
= strlen (cp1
) + 1;
944 VMS_Store_Immediate_Data (Local
, Size
, OBJ_S_C_TBT
);
948 /* Write a Traceback Routine End record.
950 We *must* search the symbol table to find the next routine, since the
951 assember has a way of reassembling the symbol table OUT OF ORDER Thus
952 the next routine in the symbol list is not necessarily the next one in
953 memory. For debugging to work correctly we must know the size of the
957 VMS_TBT_Routine_End (Max_Size
, sp
)
962 int Size
= 0x7fffffff;
964 valueT sym_value
, sp_value
= S_GET_VALUE (sp
);
966 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
968 if (!S_IS_DEBUG (symbolP
) && S_GET_TYPE (symbolP
) == N_TEXT
)
970 if (*S_GET_NAME (symbolP
) == 'L')
972 sym_value
= S_GET_VALUE (symbolP
);
973 if (sym_value
> sp_value
&& sym_value
< Size
)
977 * Dummy labels like "gcc_compiled." should no longer reach here.
981 /* check if gcc_compiled. has size of zero */
982 if (sym_value
== sp_value
&&
984 (!strcmp (S_GET_NAME (sp
), "gcc_compiled.") ||
985 !strcmp (S_GET_NAME (sp
), "gcc2_compiled.")))
990 if (Size
== 0x7fffffff)
992 Size
-= sp_value
; /* and get the size of the routine */
995 /* DST type is "routine end". */
996 Local
[1] = DST_S_C_RTNEND
;
997 Local
[2] = 0; /* unused */
998 /* Size of routine. */
999 COPY_LONG (&Local
[3], Size
);
1000 /* Store the record. */
1001 VMS_Store_Immediate_Data (Local
, 7, OBJ_S_C_TBT
);
1005 /* Write a Traceback Block Begin record. */
1008 VMS_TBT_Block_Begin (symbolP
, Psect
, Name
)
1013 register char *cp
, *cp1
;
1018 /* Set the record size. */
1019 Size
= 1 + 1 + 4 + 1 + strlen (Name
);
1021 /* DST type is "begin block"; we simulate with a phony routine. */
1022 Local
[1] = DST_S_C_BLKBEG
;
1023 /* Uses CallS/CallG. */
1025 /* Store the data so far. */
1026 VMS_Store_Immediate_Data (Local
, 3, OBJ_S_C_DBG
);
1027 /* Make sure we are still generating a debug record. */
1028 if (Object_Record_Offset
== 0)
1029 PUT_CHAR (OBJ_S_C_DBG
);
1030 /* Now get the symbol address. */
1031 PUT_CHAR (TIR_S_C_STA_WPL
);
1033 /* Get the text psect offset. */
1034 Offset
= S_GET_VALUE (symbolP
);
1036 /* Store the data reference. */
1037 PUT_CHAR (TIR_S_C_STO_PIDR
);
1038 /* Store the counted string as data. */
1041 Size
= strlen (cp1
) + 1;
1045 VMS_Store_Immediate_Data (Local
, Size
, OBJ_S_C_DBG
);
1049 /* Write a Traceback Block End record. */
1052 VMS_TBT_Block_End (Size
)
1057 Local
[0] = 6; /* record length */
1058 /* DST type is "block end"; simulate with a phony end routine. */
1059 Local
[1] = DST_S_C_BLKEND
;
1060 Local
[2] = 0; /* unused, must be zero */
1061 COPY_LONG (&Local
[3], Size
);
1062 VMS_Store_Immediate_Data (Local
, 7, OBJ_S_C_DBG
);
1066 /* Write a Line number <-> Program Counter correlation record. */
1069 VMS_TBT_Line_PC_Correlation (Line_Number
, Offset
, Psect
, Do_Delta
)
1081 * If not delta, set our PC/Line number correlation.
1083 cp
= &Local
[1]; /* Put size in Local[0] later. */
1084 /* DST type is "Line Number/PC correlation". */
1085 *cp
++ = DST_S_C_LINE_NUM
;
1086 /* Set Line number. */
1087 if (Line_Number
- 1 <= 255)
1089 *cp
++ = DST_S_C_SET_LINUM_B
;
1090 *cp
++ = (char) (Line_Number
- 1);
1092 else if (Line_Number
- 1 <= 65535)
1094 *cp
++ = DST_S_C_SET_LINE_NUM
;
1095 COPY_SHORT (cp
, Line_Number
- 1), cp
+= 2;
1099 *cp
++ = DST_S_C_SET_LINUM_L
;
1100 COPY_LONG (cp
, Line_Number
- 1), cp
+= 4;
1103 *cp
++ = DST_S_C_SET_ABS_PC
;
1104 /* Store size now that we know it, then output the data. */
1105 Local
[0] = cp
- &Local
[1];
1106 /* Account for the space that TIR_S_C_STO_PIDR will use for the PC. */
1107 Local
[0] += 4; /* size includes length of another longword */
1108 VMS_Store_Immediate_Data (Local
, cp
- Local
, OBJ_S_C_TBT
);
1109 /* Make sure we are still generating a OBJ_S_C_TBT record. */
1110 if (Object_Record_Offset
== 0)
1111 PUT_CHAR (OBJ_S_C_TBT
);
1112 vms_tir_stack_psect (Psect
, Offset
, 0);
1113 PUT_CHAR (TIR_S_C_STO_PIDR
);
1114 /* Do a PC offset of 0 to register the line number. */
1116 Local
[1] = DST_S_C_LINE_NUM
;
1117 Local
[2] = 0; /* Increment PC by 0 and register line # */
1118 VMS_Store_Immediate_Data (Local
, 3, OBJ_S_C_TBT
);
1125 * When delta is negative, terminate the line numbers.
1127 Local
[0] = 1 + 1 + 4;
1128 Local
[1] = DST_S_C_LINE_NUM
;
1129 Local
[2] = DST_S_C_TERM_L
;
1130 COPY_LONG (&Local
[3], Offset
);
1131 VMS_Store_Immediate_Data (Local
, 7, OBJ_S_C_TBT
);
1135 * Do a PC/Line delta.
1138 *cp
++ = DST_S_C_LINE_NUM
;
1139 if (Line_Number
> 1)
1141 /* We need to increment the line number. */
1142 if (Line_Number
- 1 <= 255)
1144 *cp
++ = DST_S_C_INCR_LINUM
;
1145 *cp
++ = Line_Number
- 1;
1147 else if (Line_Number
- 1 <= 65535)
1149 *cp
++ = DST_S_C_INCR_LINUM_W
;
1150 COPY_SHORT (cp
, Line_Number
- 1), cp
+= 2;
1154 *cp
++ = DST_S_C_INCR_LINUM_L
;
1155 COPY_LONG (cp
, Line_Number
- 1), cp
+= 4;
1163 /* Small offsets are encoded as negative numbers, rather than the
1164 usual non-negative type code followed by another data field. */
1165 *cp
++ = (char) -Offset
;
1167 else if (Offset
<= 65535)
1169 *cp
++ = DST_S_C_DELTA_PC_W
;
1170 COPY_SHORT (cp
, Offset
), cp
+= 2;
1174 *cp
++ = DST_S_C_DELTA_PC_L
;
1175 COPY_LONG (cp
, Offset
), cp
+= 4;
1177 /* Set size now that be know it, then output the data. */
1178 Local
[0] = cp
- &Local
[1];
1179 VMS_Store_Immediate_Data (Local
, cp
- Local
, OBJ_S_C_TBT
);
1184 /* Describe a source file to the debugger. */
1187 VMS_TBT_Source_File (Filename
, ID_Number
)
1192 int len
, rfo
, ffb
, ebk
;
1195 #ifdef VMS /* Used for native assembly */
1197 struct FAB fab
; /* RMS file access block */
1198 struct NAM nam
; /* file name information */
1199 struct XABDAT xabdat
; /* date+time fields */
1200 struct XABFHC xabfhc
; /* file header characteristics */
1201 char resultant_string_buffer
[255 + 1];
1204 * Set up RMS structures:
1206 /* FAB -- file access block */
1207 memset ((char *) &fab
, 0, sizeof fab
);
1208 fab
.fab$b_bid
= FAB$C_BID
;
1209 fab
.fab$b_bln
= (unsigned char) sizeof fab
;
1210 fab
.fab$l_fna
= Filename
;
1211 fab
.fab$b_fns
= (unsigned char) strlen (Filename
);
1212 fab
.fab$l_nam
= (char *) &nam
;
1213 fab
.fab$l_xab
= (char *) &xabdat
;
1214 /* NAM -- file name block */
1215 memset ((char *) &nam
, 0, sizeof nam
);
1216 nam
.nam$b_bid
= NAM$C_BID
;
1217 nam
.nam$b_bln
= (unsigned char) sizeof nam
;
1218 nam
.nam$l_rsa
= resultant_string_buffer
;
1219 nam
.nam$b_rss
= (unsigned char) (sizeof resultant_string_buffer
- 1);
1220 /* XABs -- extended attributes blocks */
1221 memset ((char *) &xabdat
, 0, sizeof xabdat
);
1222 xabdat
.xab$b_cod
= XAB$C_DAT
;
1223 xabdat
.xab$b_bln
= (unsigned char) sizeof xabdat
;
1224 xabdat
.xab$l_nxt
= (char *) &xabfhc
;
1225 memset ((char *) &xabfhc
, 0, sizeof xabfhc
);
1226 xabfhc
.xab$b_cod
= XAB$C_FHC
;
1227 xabfhc
.xab$b_bln
= (unsigned char) sizeof xabfhc
;
1228 xabfhc
.xab$l_nxt
= 0;
1230 * Get the file information
1232 Status
= sys$
open (&fab
);
1235 as_tsktsk ("Couldn't find source file \"%s\", status=%%X%x",
1240 /* Now extract fields of interest. */
1241 memcpy (cdt
, (char *) &xabdat
.xab$q_cdt
, 8); /* creation date */
1242 ebk
= xabfhc
.xab$l_ebk
; /* end-of-file block */
1243 ffb
= xabfhc
.xab$w_ffb
; /* first free byte of last block */
1244 rfo
= xabfhc
.xab$b_rfo
; /* record format */
1245 len
= nam
.nam$b_rsl
; /* length of Filename */
1246 resultant_string_buffer
[len
] = '\0';
1247 Filename
= resultant_string_buffer
; /* full filename */
1248 #else /* Cross-assembly */
1249 /* [Perhaps we ought to use actual values derived from stat() here?] */
1250 memset (cdt
, 0, 8); /* null VMS quadword binary time */
1251 ebk
= ffb
= rfo
= 0;
1252 len
= strlen (Filename
);
1253 if (len
> 255) /* a single byte is used as count prefix */
1255 Filename
+= (len
- 255); /* tail end is more significant */
1260 cp
= &Local
[1]; /* fill in record length later */
1261 *cp
++ = DST_S_C_SOURCE
; /* DST type is "source file" */
1262 *cp
++ = DST_S_C_SRC_FORMFEED
; /* formfeeds count as source records */
1263 *cp
++ = DST_S_C_SRC_DECLFILE
; /* declare source file */
1264 know (cp
== &Local
[4]);
1265 *cp
++ = 0; /* fill in this length below */
1266 *cp
++ = 0; /* flags; must be zero */
1267 COPY_SHORT (cp
, ID_Number
), cp
+= 2; /* file ID number */
1268 memcpy (cp
, cdt
, 8), cp
+= 8; /* creation date+time */
1269 COPY_LONG (cp
, ebk
), cp
+= 4; /* end-of-file block */
1270 COPY_SHORT (cp
, ffb
), cp
+= 2; /* first free byte of last block */
1271 *cp
++ = (char) rfo
; /* RMS record format */
1275 *cp
++ = *Filename
++;
1276 /* Library module name (none). */
1278 /* Now that size is known, fill it in and write out the record. */
1279 Local
[4] = cp
- &Local
[5]; /* source file declaration size */
1280 Local
[0] = cp
- &Local
[1]; /* TBT record size */
1281 VMS_Store_Immediate_Data (Local
, cp
- Local
, OBJ_S_C_TBT
);
1286 /* Traceback information is described in terms of lines from compiler
1287 listing files, not lines from source files. We need to set up the
1288 correlation between listing line numbers and source line numbers.
1289 Since gcc's .stabn directives refer to the source lines, we just
1290 need to describe a one-to-one correspondence. */
1293 VMS_TBT_Source_Lines (ID_Number
, Starting_Line_Number
, Number_Of_Lines
)
1295 int Starting_Line_Number
;
1296 int Number_Of_Lines
;
1300 char Local
[128]; /* room enough to describe 1310700 lines... */
1302 cp
= &Local
[1]; /* Put size in Local[0] later. */
1303 *cp
++ = DST_S_C_SOURCE
; /* DST type is "source file". */
1304 *cp
++ = DST_S_C_SRC_SETFILE
; /* Set Source File. */
1305 COPY_SHORT (cp
, ID_Number
), cp
+= 2; /* File ID Number. */
1306 /* Set record number and define lines. Since no longword form of
1307 SRC_DEFLINES is available, we need to be able to cope with any huge
1308 files a chunk at a time. It doesn't matter for tracebacks, since
1309 unspecified lines are mapped one-to-one and work out right, but it
1310 does matter within the debugger. Without this explicit mapping,
1311 it will complain about lines not existing in the module. */
1312 chunk_limit
= (sizeof Local
- 5) / 6;
1313 if (Number_Of_Lines
> 65535 * chunk_limit
) /* avoid buffer overflow */
1314 Number_Of_Lines
= 65535 * chunk_limit
;
1315 while (Number_Of_Lines
> 65535)
1317 *cp
++ = DST_S_C_SRC_SETREC_L
;
1318 COPY_LONG (cp
, Starting_Line_Number
), cp
+= 4;
1319 *cp
++ = DST_S_C_SRC_DEFLINES_W
;
1320 COPY_SHORT (cp
, 65535), cp
+= 2;
1321 Starting_Line_Number
+= 65535;
1322 Number_Of_Lines
-= 65535;
1324 /* Set record number and define lines, normal case. */
1325 if (Starting_Line_Number
<= 65535)
1327 *cp
++ = DST_S_C_SRC_SETREC_W
;
1328 COPY_SHORT (cp
, Starting_Line_Number
), cp
+= 2;
1332 *cp
++ = DST_S_C_SRC_SETREC_L
;
1333 COPY_LONG (cp
, Starting_Line_Number
), cp
+= 4;
1335 *cp
++ = DST_S_C_SRC_DEFLINES_W
;
1336 COPY_SHORT (cp
, Number_Of_Lines
), cp
+= 2;
1337 /* Set size now that be know it, then output the data. */
1338 Local
[0] = cp
- &Local
[1];
1339 VMS_Store_Immediate_Data (Local
, cp
- Local
, OBJ_S_C_TBT
);
1343 /****** Debugger Information support routines ******/
1346 /* This routine locates a file in the list of files. If an entry does
1347 not exist, one is created. For include files, a new entry is always
1348 created such that inline functions can be properly debugged. */
1350 static struct input_file
*
1354 struct input_file
*same_file
= 0;
1355 struct input_file
*fpnt
, *last
= 0;
1358 for (fpnt
= file_root
; fpnt
; fpnt
= fpnt
->next
)
1360 if (fpnt
->spnt
== sp
)
1364 sp_name
= S_GET_NAME (sp
);
1365 for (fpnt
= file_root
; fpnt
; fpnt
= fpnt
->next
)
1367 if (strcmp (sp_name
, fpnt
->name
) == 0)
1369 if (fpnt
->flag
== 1)
1375 fpnt
= (struct input_file
*) xmalloc (sizeof (struct input_file
));
1381 fpnt
->name
= sp_name
;
1382 fpnt
->min_line
= 0x7fffffff;
1386 fpnt
->file_number
= 0;
1388 fpnt
->same_file_fpnt
= same_file
;
1393 /* This routine converts a number string into an integer, and stops when
1394 it sees an invalid character. The return value is the address of the
1395 character just past the last character read. No error is generated. */
1398 cvt_integer (str
, rtn
)
1402 int ival
= 0, sgn
= 1;
1406 while (*str
>= '0' && *str
<= '9')
1407 ival
= 10 * ival
+ *str
++ - '0';
1414 * The following functions and definitions are used to generate object
1415 * records that will describe program variables to the VMS debugger.
1417 * This file contains many of the routines needed to output debugging info
1418 * into the object file that the VMS debugger needs to understand symbols.
1419 * These routines are called very late in the assembly process, and thus
1420 * we can be fairly lax about changing things, since the GSD and the TIR
1421 * sections have already been output.
1425 /* This routine fixes the names that are generated by C++, ".this" is a good
1426 example. The period does not work for the debugger, since it looks like
1427 the syntax for a structure element, and thus it gets mightily confused.
1429 We also use this to strip the PsectAttribute hack from the name before we
1430 write a debugger record. */
1438 /* Kill any leading "_". */
1442 /* Is there a Psect Attribute to skip?? */
1443 if (HAS_PSECT_ATTRIBUTES (pnt
))
1446 pnt
+= PSECT_ATTRIBUTES_STRING_LENGTH
;
1449 if ((pnt
[0] == '$') && (pnt
[1] == '$'))
1458 /* Here we fix the .this -> $this conversion. */
1459 for (pnt1
= pnt
; *pnt1
!= 0; pnt1
++)
1467 /* When defining a structure, this routine is called to find the name of
1468 the actual structure. It is assumed that str points to the equal sign
1469 in the definition, and it moves backward until it finds the start of the
1470 name. If it finds a 0, then it knows that this structure def is in the
1471 outermost level, and thus symbol_name points to the symbol name. */
1474 get_struct_name (str
)
1479 while ((*pnt
!= ':') && (*pnt
!= '\0'))
1482 return (char *) symbol_name
;
1484 while ((*pnt
!= ';') && (*pnt
!= '='))
1488 while ((*pnt
< '0') || (*pnt
> '9'))
1490 while ((*pnt
>= '0') && (*pnt
<= '9'))
1496 /* Search symbol list for type number dbx_type.
1497 Return a pointer to struct. */
1499 static struct VMS_DBG_Symbol
*
1500 find_symbol (dbx_type
)
1503 struct VMS_DBG_Symbol
*spnt
;
1505 spnt
= VMS_Symbol_type_list
[SYMTYP_HASH (dbx_type
)];
1508 if (spnt
->dbx_type
== dbx_type
)
1512 if (!spnt
|| spnt
->advanced
!= ALIAS
)
1514 return find_symbol (spnt
->type2
);
1518 #if 0 /* obsolete */
1519 /* this routine puts info into either Local or Asuffix, depending on the sign
1520 * of size. The reason is that it is easier to build the variable descriptor
1521 * backwards, while the array descriptor is best built forwards. In the end
1522 * they get put together, if there is not a struct/union/enum along the way
1538 md_number_to_chars (&Local
[Lpnt
+ 1], value
, size1
);
1542 if (Apoint
+ size1
>= MAX_DEBUG_RECORD
)
1545 Apoint
= MAX_DEBUG_RECORD
- 1;
1548 md_number_to_chars (&Asuffix
[Apoint
], value
, size1
);
1559 if (Apoint
+ size
>= MAX_DEBUG_RECORD
)
1562 Apoint
= MAX_DEBUG_RECORD
- 1;
1566 Asuffix
[Apoint
++] = (char) value
;
1569 md_number_to_chars (&Asuffix
[Apoint
], value
, size
);
1585 Local
[Lpnt
--] = (char) value
;
1589 md_number_to_chars (&Local
[Lpnt
+ 1], value
, size
);
1594 /* This routine generates the array descriptor for a given array. */
1597 array_suffix (spnt2
)
1598 struct VMS_DBG_Symbol
*spnt2
;
1600 struct VMS_DBG_Symbol
*spnt
;
1601 struct VMS_DBG_Symbol
*spnt1
;
1607 while (spnt
->advanced
!= ARRAY
)
1609 spnt
= find_symbol (spnt
->type2
);
1615 while (spnt1
->advanced
== ARRAY
)
1618 total_size
*= (spnt1
->index_max
- spnt1
->index_min
+ 1);
1619 spnt1
= find_symbol (spnt1
->type2
);
1621 total_size
= total_size
* spnt1
->data_size
;
1622 fpush (spnt1
->data_size
, 2); /* element size */
1623 if (spnt1
->VMS_type
== DBG_S_C_ADVANCED_TYPE
)
1626 fpush (spnt1
->VMS_type
, 1); /* element type */
1627 fpush (DSC_K_CLASS_A
, 1); /* descriptor class */
1628 fpush (0, 4); /* base address */
1629 fpush (0, 1); /* scale factor -- not applicable */
1630 fpush (0, 1); /* digit count -- not applicable */
1631 fpush (0xc0, 1); /* flags: multiplier block & bounds present */
1632 fpush (rank
, 1); /* number of dimensions */
1633 fpush (total_size
, 4);
1634 fpush (0, 4); /* pointer to element [0][0]...[0] */
1636 while (spnt1
->advanced
== ARRAY
)
1638 fpush (spnt1
->index_max
- spnt1
->index_min
+ 1, 4);
1639 spnt1
= find_symbol (spnt1
->type2
);
1642 while (spnt1
->advanced
== ARRAY
)
1644 fpush (spnt1
->index_min
, 4);
1645 fpush (spnt1
->index_max
, 4);
1646 spnt1
= find_symbol (spnt1
->type2
);
1651 /* This routine generates the start of a variable descriptor based upon
1652 a struct/union/enum that has yet to be defined. We define this spot as
1653 a new location, and save four bytes for the address. When the struct is
1654 finally defined, then we can go back and plug in the correct address. */
1657 new_forward_ref (dbx_type
)
1660 struct forward_ref
*fpnt
;
1661 fpnt
= (struct forward_ref
*) xmalloc (sizeof (struct forward_ref
));
1662 fpnt
->next
= f_ref_root
;
1664 fpnt
->dbx_type
= dbx_type
;
1665 fpnt
->struc_numb
= ++structure_count
;
1666 fpnt
->resolved
= 'N';
1667 rpush (DST_K_TS_IND
, 1); /* indirect type specification */
1669 rpush (total_len
, 2);
1670 struct_number
= -fpnt
->struc_numb
;
1674 /* This routine generates the variable descriptor used to describe non-basic
1675 variables. It calls itself recursively until it gets to the bottom of it
1676 all, and then builds the descriptor backwards. It is easiest to do it
1677 this way since we must periodically write length bytes, and it is easiest
1678 if we know the value when it is time to write it. */
1681 gen1 (spnt
, array_suffix_len
)
1682 struct VMS_DBG_Symbol
*spnt
;
1683 int array_suffix_len
;
1685 struct VMS_DBG_Symbol
*spnt1
;
1688 switch (spnt
->advanced
)
1691 rpush (DBG_S_C_VOID
, 1);
1693 rpush (total_len
, 2);
1697 if (array_suffix_len
== 0)
1699 rpush (spnt
->VMS_type
, 1);
1700 rpush (DBG_S_C_BASIC
, 1);
1702 rpush (total_len
, 2);
1706 rpush (DST_K_VFLAGS_DSC
, 1);
1707 rpush (DST_K_TS_DSC
, 1); /* descriptor type specification */
1713 struct_number
= spnt
->struc_numb
;
1714 if (struct_number
< 0)
1716 new_forward_ref (spnt
->dbx_type
);
1719 rpush (DBG_S_C_STRUCT
, 1);
1721 rpush (total_len
, 2);
1724 spnt1
= find_symbol (spnt
->type2
);
1727 new_forward_ref (spnt
->type2
);
1729 i
= gen1 (spnt1
, 0);
1731 { /* (*void) is a special case, do not put pointer suffix */
1732 rpush (DBG_S_C_POINTER
, 1);
1734 rpush (total_len
, 2);
1739 while (spnt1
->advanced
== ARRAY
)
1741 spnt1
= find_symbol (spnt1
->type2
);
1744 as_tsktsk ("debugger forward reference error, dbx type %d",
1749 /* It is too late to generate forward references, so the user gets a message.
1750 * This should only happen on a compiler error */
1751 (void) gen1 (spnt1
, 1);
1753 array_suffix (spnt
);
1754 array_suffix_len
= Apoint
- i
;
1755 switch (spnt1
->advanced
)
1763 rpush (total_len
, 2);
1764 rpush (DST_K_VFLAGS_DSC
, 1);
1765 rpush (1, 1); /* flags: element value spec included */
1766 rpush (1, 1); /* one dimension */
1767 rpush (DBG_S_C_COMPLEX_ARRAY
, 1);
1769 total_len
+= array_suffix_len
+ 8;
1770 rpush (total_len
, 2);
1772 default: /* lint suppression */
1779 /* This generates a suffix for a variable. If it is not a defined type yet,
1780 then dbx_type contains the type we are expecting so we can generate a
1781 forward reference. This calls gen1 to build most of the descriptor, and
1782 then it puts the icing on at the end. It then dumps whatever is needed
1783 to get a complete descriptor (i.e. struct reference, array suffix). */
1786 generate_suffix (spnt
, dbx_type
)
1787 struct VMS_DBG_Symbol
*spnt
;
1790 static const char pvoid
[6] = {
1791 5, /* record.length == 5 */
1792 DST_K_TYPSPEC
, /* record.type == 1 (type specification) */
1793 0, /* name.length == 0, no name follows */
1794 1, 0, /* type.length == 1 {2 bytes, little endian} */
1795 DBG_S_C_VOID
/* type.type == 5 (pointer to unspecified) */
1800 Lpnt
= MAX_DEBUG_RECORD
- 1;
1805 new_forward_ref (dbx_type
);
1808 if (spnt
->VMS_type
!= DBG_S_C_ADVANCED_TYPE
)
1809 return; /* no suffix needed */
1812 rpush (0, 1); /* no name (len==0) */
1813 rpush (DST_K_TYPSPEC
, 1);
1815 rpush (total_len
, 1);
1816 /* If the variable descriptor overflows the record, output a descriptor
1817 for a pointer to void. */
1818 if ((total_len
>= MAX_DEBUG_RECORD
) || overflow
)
1820 as_warn ("Variable descriptor %d too complicated. Defined as `void *'.",
1822 VMS_Store_Immediate_Data (pvoid
, 6, OBJ_S_C_DBG
);
1826 while (Lpnt
< MAX_DEBUG_RECORD
- 1)
1827 Local
[i
++] = Local
[++Lpnt
];
1829 /* we use this for reference to structure that has already been defined */
1830 if (struct_number
> 0)
1832 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1834 VMS_Store_Struct (struct_number
);
1836 /* We use this for a forward reference to a structure that has yet to
1837 be defined. We store four bytes of zero to make room for the actual
1838 address once it is known. */
1839 if (struct_number
< 0)
1841 struct_number
= -struct_number
;
1842 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1844 VMS_Def_Struct (struct_number
);
1845 COPY_LONG (&Local
[Lpnt
], 0L);
1847 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1852 Local
[Lpnt
++] = Asuffix
[i
++];
1854 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1859 /* "novel length" type doesn't work for simple atomic types */
1860 #define USE_BITSTRING_DESCRIPTOR(t) ((t)->advanced == BASIC)
1861 #undef SETUP_BASIC_TYPES
1863 /* This routine generates a type description for a bitfield. */
1866 bitfield_suffix (spnt
, width
)
1867 struct VMS_DBG_Symbol
*spnt
;
1870 Local
[Lpnt
++] = 13; /* rec.len==13 */
1871 Local
[Lpnt
++] = DST_K_TYPSPEC
; /* a type specification record */
1872 Local
[Lpnt
++] = 0; /* not named */
1873 COPY_SHORT (&Local
[Lpnt
], 9); /* typ.len==9 */
1875 Local
[Lpnt
++] = DST_K_TS_NOV_LENG
; /* This type is a "novel length"
1876 incarnation of some other type. */
1877 COPY_LONG (&Local
[Lpnt
], width
); /* size in bits == novel length */
1879 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1881 /* assert( spnt->struc_numb > 0 ); */
1882 VMS_Store_Struct (spnt
->struc_numb
); /* output 4 more bytes */
1886 /* Formally define a builtin type, so that it can serve as the target of
1887 an indirect reference. It makes bitfield_suffix() easier by avoiding
1888 the need to use a forward reference for the first occurrence of each
1889 type used in a bitfield. */
1892 setup_basic_type (spnt
)
1893 struct VMS_DBG_Symbol
*spnt
;
1895 #ifdef SETUP_BASIC_TYPES
1896 /* This would be very useful if "novel length" fields actually worked
1897 with basic types like they do with enumerated types. However,
1898 they do not, so this isn't worth doing just so that you can use
1899 EXAMINE/TYPE=(__long_long_int) instead of EXAMINE/QUAD. */
1901 #ifndef SETUP_SYNONYM_TYPES
1902 /* This determines whether compatible things like `int' and `long int'
1903 ought to have distinct type records rather than sharing one. */
1904 struct VMS_DBG_Symbol
*spnt2
;
1906 /* first check whether this type has already been seen by another name */
1907 for (spnt2
= VMS_Symbol_type_list
[SYMTYP_HASH (spnt
->VMS_type
)];
1909 spnt2
= spnt2
->next
)
1910 if (spnt2
!= spnt
&& spnt2
->VMS_type
== spnt
->VMS_type
)
1912 spnt
->struc_numb
= spnt2
->struc_numb
;
1917 /* `structure number' doesn't really mean `structure'; it means an index
1918 into a linker maintained set of saved locations which can be referenced
1920 spnt
->struc_numb
= ++structure_count
;
1921 VMS_Def_Struct (spnt
->struc_numb
); /* remember where this type lives */
1922 /* define the simple scalar type */
1923 Local
[Lpnt
++] = 6 + strlen (symbol_name
) + 2; /* rec.len */
1924 Local
[Lpnt
++] = DST_K_TYPSPEC
; /* rec.typ==type specification */
1925 Local
[Lpnt
++] = strlen (symbol_name
) + 2;
1926 Local
[Lpnt
++] = '_'; /* prefix name with "__" */
1927 Local
[Lpnt
++] = '_';
1928 for (p
= symbol_name
; *p
; p
++)
1929 Local
[Lpnt
++] = *p
== ' ' ? '_' : *p
;
1930 COPY_SHORT (&Local
[Lpnt
], 2); /* typ.len==2 */
1932 Local
[Lpnt
++] = DST_K_TS_ATOM
; /* typ.kind is simple type */
1933 Local
[Lpnt
++] = spnt
->VMS_type
; /* typ.type */
1934 VMS_Store_Immediate_Data (Local
, Lpnt
, OBJ_S_C_DBG
);
1936 #endif /* SETUP_BASIC_TYPES */
1941 /* This routine generates a symbol definition for a C symbol for the debugger.
1942 It takes a psect and offset for global symbols; if psect < 0, then this is
1943 a local variable and the offset is relative to FP. In this case it can
1944 be either a variable (Offset < 0) or a parameter (Offset > 0). */
1947 VMS_DBG_record (spnt
, Psect
, Offset
, Name
)
1948 struct VMS_DBG_Symbol
*spnt
;
1957 /* if there are bad characters in name, convert them */
1958 Name_pnt
= fix_name (Name
);
1960 len
= strlen (Name_pnt
);
1962 { /* this is a local variable, referenced to SP */
1963 Local
[i
++] = 7 + len
;
1964 Local
[i
++] = spnt
->VMS_type
;
1965 Local
[i
++] = (Offset
> 0) ? DBG_C_FUNCTION_PARAM
: DBG_C_LOCAL_SYM
;
1966 COPY_LONG (&Local
[i
], Offset
);
1971 Local
[i
++] = 7 + len
;
1972 Local
[i
++] = spnt
->VMS_type
;
1973 Local
[i
++] = DST_K_VALKIND_ADDR
;
1974 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
1976 VMS_Set_Data (Psect
, Offset
, OBJ_S_C_DBG
, 0);
1979 while (*Name_pnt
!= '\0')
1980 Local
[i
++] = *Name_pnt
++;
1981 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
1982 if (spnt
->VMS_type
== DBG_S_C_ADVANCED_TYPE
)
1983 generate_suffix (spnt
, 0);
1987 /* This routine parses the stabs entries in order to make the definition
1988 for the debugger of local symbols and function parameters. */
1991 VMS_local_stab_Parse (sp
)
1994 struct VMS_DBG_Symbol
*spnt
;
2001 str
= S_GET_NAME (sp
);
2002 pnt
= (char *) strchr (str
, ':');
2004 return; /* no colon present */
2005 pnt1
= pnt
++; /* save this for later, and skip colon */
2007 return; /* ignore static constants */
2009 /* there is one little catch that we must be aware of. Sometimes function
2010 * parameters are optimized into registers, and the compiler, in its infiite
2011 * wisdom outputs stabs records for *both*. In general we want to use the
2012 * register if it is present, so we must search the rest of the symbols for
2013 * this function to see if this parameter is assigned to a register.
2022 for (sp1
= symbol_next (sp
); sp1
; sp1
= symbol_next (sp1
))
2024 if (!S_IS_DEBUG (sp1
))
2026 if (S_GET_RAW_TYPE (sp1
) == N_FUN
)
2028 pnt2
= (char *) strchr (S_GET_NAME (sp1
), ':') + 1;
2029 if (*pnt2
== 'F' || *pnt2
== 'f')
2032 if (S_GET_RAW_TYPE (sp1
) != N_RSYM
)
2034 str1
= S_GET_NAME (sp1
); /* and get the name */
2036 while (*pnt2
!= ':')
2043 if (*str1
== ':' && *pnt2
== ':')
2044 return; /* they are the same! lets skip this one */
2046 pnt
++; /* skip p in case no register */
2050 pnt
= cvt_integer (pnt
, &dbx_type
);
2051 spnt
= find_symbol (dbx_type
);
2053 return; /*Dunno what this is*/
2055 VMS_DBG_record (spnt
, -1, S_GET_VALUE (sp
), str
);
2056 *pnt1
= ':'; /* and restore the string */
2061 /* This routine parses a stabs entry to find the information required
2062 to define a variable. It is used for global and static variables.
2063 Basically we need to know the address of the symbol. With older
2064 versions of the compiler, const symbols are treated differently, in
2065 that if they are global they are written into the text psect. The
2066 global symbol entry for such a const is actually written as a program
2067 entry point (Yuk!!), so if we cannot find a symbol in the list of
2068 psects, we must search the entry points as well. static consts are
2069 even harder, since they are never assigned a memory address. The
2070 compiler passes a stab to tell us the value, but I am not sure what
2074 VMS_stab_parse (sp
, expected_type
, type1
, type2
, Text_Psect
)
2076 int expected_type
; /* char */
2077 int type1
, type2
, Text_Psect
;
2083 struct VMS_DBG_Symbol
*spnt
;
2084 struct VMS_Symbol
*vsp
;
2088 str
= S_GET_NAME (sp
);
2089 pnt
= (char *) strchr (str
, ':');
2091 return; /* no colon present */
2092 pnt1
= pnt
; /* save this for later*/
2094 if (*pnt
== expected_type
)
2096 pnt
= cvt_integer (pnt
+ 1, &dbx_type
);
2097 spnt
= find_symbol (dbx_type
);
2099 return; /*Dunno what this is*/
2101 * Now we need to search the symbol table to find the psect and
2102 * offset for this variable.
2108 pnt
= S_GET_NAME (vsp
->Symbol
);
2109 if (pnt
&& *pnt
++ == '_'
2110 /* make sure name is the same and symbol type matches */
2111 && strcmp (pnt
, str
) == 0
2112 && (S_GET_RAW_TYPE (vsp
->Symbol
) == type1
2113 || S_GET_RAW_TYPE (vsp
->Symbol
) == type2
))
2119 VMS_DBG_record (spnt
, vsp
->Psect_Index
, vsp
->Psect_Offset
, str
);
2120 *pnt1
= ':'; /* and restore the string */
2123 /* The symbol was not in the symbol list, but it may be an
2124 "entry point" if it was a constant. */
2125 for (sp1
= symbol_rootP
; sp1
; sp1
= symbol_next (sp1
))
2128 * Dispatch on STAB type
2130 if (S_IS_DEBUG (sp1
) || (S_GET_TYPE (sp1
) != N_TEXT
))
2132 pnt
= S_GET_NAME (sp1
);
2135 if (strcmp (pnt
, str
) == 0)
2137 if (!gave_compiler_message
&& expected_type
== 'G')
2139 static const char long_const_msg
[] = "\
2140 ***Warning - the assembly code generated by the compiler has placed \n\
2141 global constant(s) in the text psect. These will not be available to \n\
2142 other modules, since this is not the correct way to handle this. You \n\
2143 have two options: 1) get a patched compiler that does not put global \n\
2144 constants in the text psect, or 2) remove the 'const' keyword from \n\
2145 definitions of global variables in your source module(s). Don't say \n\
2146 I didn't warn you! \n";
2148 as_tsktsk (long_const_msg
);
2149 gave_compiler_message
= 1;
2151 VMS_DBG_record (spnt
,
2156 /* fool assembler to not output this as a routine in the TBT */
2157 pnt1
= S_GET_NAME (sp1
);
2159 S_SET_NAME (sp1
, pnt1
);
2164 *pnt1
= ':'; /* and restore the string */
2169 VMS_GSYM_Parse (sp
, Text_Psect
)
2172 { /* Global variables */
2173 VMS_stab_parse (sp
, 'G', (N_UNDF
| N_EXT
), (N_DATA
| N_EXT
), Text_Psect
);
2178 VMS_LCSYM_Parse (sp
, Text_Psect
)
2181 { /* Static symbols - uninitialized */
2182 VMS_stab_parse (sp
, 'S', N_BSS
, -1, Text_Psect
);
2186 VMS_STSYM_Parse (sp
, Text_Psect
)
2189 { /* Static symbols - initialized */
2190 VMS_stab_parse (sp
, 'S', N_DATA
, -1, Text_Psect
);
2194 /* for register symbols, we must figure out what range of addresses within the
2195 * psect are valid. We will use the brackets in the stab directives to give us
2196 * guidance as to the PC range that this variable is in scope. I am still not
2197 * completely comfortable with this but as I learn more, I seem to get a better
2198 * handle on what is going on.
2202 VMS_RSYM_Parse (sp
, Current_Routine
, Text_Psect
)
2203 symbolS
*sp
, *Current_Routine
;
2210 struct VMS_DBG_Symbol
*spnt
;
2214 int Min_Offset
= -1; /* min PC of validity */
2215 int Max_Offset
= 0; /* max PC of validity */
2218 for (symbolP
= sp
; symbolP
; symbolP
= symbol_next (symbolP
))
2221 * Dispatch on STAB type
2223 switch (S_GET_RAW_TYPE (symbolP
))
2227 Min_Offset
= S_GET_VALUE (symbolP
);
2231 Max_Offset
= S_GET_VALUE (symbolP
) - 1;
2234 if ((Min_Offset
!= -1) && (bcnt
== 0))
2236 if (S_GET_RAW_TYPE (symbolP
) == N_FUN
)
2238 pnt
=(char*) strchr (S_GET_NAME (symbolP
), ':') + 1;
2239 if (*pnt
== 'F' || *pnt
== 'f') break;
2243 /* Check to see that the addresses were defined. If not, then there were no
2244 * brackets in the function, and we must try to search for the next function.
2245 * Since functions can be in any order, we should search all of the symbol
2246 * list to find the correct ending address. */
2247 if (Min_Offset
== -1)
2249 int Max_Source_Offset
;
2251 Min_Offset
= S_GET_VALUE (sp
);
2252 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2255 * Dispatch on STAB type
2257 switch (S_GET_RAW_TYPE (symbolP
))
2259 case N_TEXT
| N_EXT
:
2260 This_Offset
= S_GET_VALUE (symbolP
);
2261 if ((This_Offset
> Min_Offset
) && (This_Offset
< Max_Offset
))
2262 Max_Offset
= This_Offset
;
2265 This_Offset
= S_GET_VALUE (symbolP
);
2266 if (This_Offset
> Max_Source_Offset
)
2267 Max_Source_Offset
= This_Offset
;
2271 /* if this is the last routine, then we use the PC of the last source line
2272 * as a marker of the max PC for which this reg is valid */
2273 if (Max_Offset
== 0x7fffffff)
2274 Max_Offset
= Max_Source_Offset
;
2277 str
= S_GET_NAME (sp
);
2278 pnt
= (char *) strchr (str
, ':');
2279 if (pnt
== (char *) NULL
)
2280 return; /* no colon present */
2281 pnt1
= pnt
; /* save this for later*/
2285 pnt
= cvt_integer (pnt
+ 1, &dbx_type
);
2286 spnt
= find_symbol (dbx_type
);
2288 return; /*Dunno what this is yet*/
2290 pnt
= fix_name (S_GET_NAME (sp
)); /* if there are bad characters in name, convert them */
2292 Local
[i
++] = 25 + len
;
2293 Local
[i
++] = spnt
->VMS_type
;
2294 Local
[i
++] = DST_K_VFLAGS_TVS
; /* trailing value specified */
2295 COPY_LONG (&Local
[i
], 1 + len
); /* relative offset, beyond name */
2297 Local
[i
++] = len
; /* name length (ascic prefix) */
2298 while (*pnt
!= '\0')
2299 Local
[i
++] = *pnt
++;
2300 Local
[i
++] = DST_K_VS_FOLLOWS
; /* value specification follows */
2301 COPY_SHORT (&Local
[i
], 15); /* length of rest of record */
2303 Local
[i
++] = DST_K_VS_ALLOC_SPLIT
; /* split lifetime */
2304 Local
[i
++] = 1; /* one binding follows */
2305 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2307 VMS_Set_Data (Text_Psect
, Min_Offset
, OBJ_S_C_DBG
, 1);
2308 VMS_Set_Data (Text_Psect
, Max_Offset
, OBJ_S_C_DBG
, 1);
2309 Local
[i
++] = DST_K_VALKIND_REG
; /* nested value spec */
2310 COPY_LONG (&Local
[i
], S_GET_VALUE (sp
));
2312 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2314 if (spnt
->VMS_type
== DBG_S_C_ADVANCED_TYPE
)
2315 generate_suffix (spnt
, 0);
2318 /* this function examines a structure definition, checking all of the elements
2319 * to make sure that all of them are fully defined. The only thing that we
2320 * kick out are arrays of undefined structs, since we do not know how big
2321 * they are. All others we can handle with a normal forward reference.
2324 forward_reference (pnt
)
2328 struct VMS_DBG_Symbol
*spnt
;
2329 struct VMS_DBG_Symbol
*spnt1
;
2330 pnt
= cvt_integer (pnt
+ 1, &i
);
2332 return 0; /* no forward references */
2335 pnt
= (char *) strchr (pnt
, ':');
2336 pnt
= cvt_integer (pnt
+ 1, &i
);
2337 spnt
= find_symbol (i
);
2339 while (spnt
->advanced
== POINTER
|| spnt
->advanced
== ARRAY
)
2342 spnt1
= find_symbol (spnt
->type2
);
2343 if ((spnt
->advanced
== ARRAY
) &&
2344 (spnt1
== (struct VMS_DBG_Symbol
*) NULL
))
2346 if (spnt1
== (struct VMS_DBG_Symbol
*) NULL
)
2351 pnt
= cvt_integer (pnt
+ 1, &i
);
2352 pnt
= cvt_integer (pnt
+ 1, &i
);
2353 } while (*++pnt
!= ';');
2354 return 0; /* no forward refences found */
2357 /* Used to check a single element of a structure on the final pass*/
2360 final_forward_reference (spnt
)
2361 struct VMS_DBG_Symbol
*spnt
;
2363 struct VMS_DBG_Symbol
*spnt1
;
2365 while (spnt
&& (spnt
->advanced
== POINTER
|| spnt
->advanced
== ARRAY
))
2367 spnt1
= find_symbol (spnt
->type2
);
2368 if (spnt
->advanced
== ARRAY
&& !spnt1
) return 1;
2371 return 0; /* no forward refences found */
2374 /* This routine parses the stabs directives to find any definitions of dbx type
2375 * numbers. It makes a note of all of them, creating a structure element
2376 * of VMS_DBG_Symbol that describes it. This also generates the info for the
2377 * debugger that describes the struct/union/enum, so that further references
2378 * to these data types will be by number
2379 * We have to process pointers right away, since there can be references
2380 * to them later in the same stabs directive. We cannot have forward
2381 * references to pointers, (but we can have a forward reference to a pointer to
2382 * a structure/enum/union) and this is why we process them immediately.
2383 * After we process the pointer, then we search for defs that are nested even
2385 * 8/15/92: We have to process arrays right away too, because there can
2386 * be multiple references to identical array types in one structure
2387 * definition, and only the first one has the definition. (We tend to
2388 * parse from the back going forward.
2391 VMS_typedef_parse (str
)
2399 struct forward_ref
*fpnt
;
2400 int i1
, i2
, i3
, len
;
2401 struct VMS_DBG_Symbol
*spnt
;
2402 struct VMS_DBG_Symbol
*spnt1
;
2404 /* check for any nested def's */
2405 pnt
= (char *) strchr (str
+ 1, '=');
2406 if ((pnt
!= (char *) NULL
) && (*(str
+ 1) != '*')
2407 && (str
[1] != 'a' || str
[2] != 'r'))
2408 if (VMS_typedef_parse (pnt
) == 1)
2410 /* now find dbx_type of entry */
2413 { /* check for static constants */
2414 *str
= '\0'; /* for now we ignore them */
2417 while ((*pnt
<= '9') && (*pnt
>= '0'))
2419 pnt
++; /* and get back to the number */
2420 cvt_integer (pnt
, &i1
);
2421 spnt
= find_symbol (i1
);
2422 /* first we see if this has been defined already, due to a forward reference*/
2425 i2
= SYMTYP_HASH (i1
);
2426 spnt
= (struct VMS_DBG_Symbol
*) xmalloc (sizeof (struct VMS_DBG_Symbol
));
2427 spnt
->next
= VMS_Symbol_type_list
[i2
];
2428 VMS_Symbol_type_list
[i2
] = spnt
;
2429 spnt
->dbx_type
= i1
; /* and save the type */
2430 spnt
->type2
= spnt
->VMS_type
= spnt
->data_size
= 0;
2431 spnt
->index_min
= spnt
->index_max
= spnt
->struc_numb
= 0;
2433 /* for structs and unions, do a partial parse, otherwise we sometimes get
2434 * circular definitions that are impossible to resolve. We read enough info
2435 * so that any reference to this type has enough info to be resolved
2437 pnt
= str
+ 1; /* point to character past equal sign */
2438 if ((*pnt
== 'u') || (*pnt
== 's'))
2441 if ((*pnt
<= '9') && (*pnt
>= '0'))
2443 if (type_check ("void"))
2444 { /* this is the void symbol */
2446 spnt
->advanced
= VOID
;
2449 if (type_check ("unknown type"))
2452 spnt
->advanced
= UNKNOWN
;
2455 pnt1
= cvt_integer (pnt
, &i1
);
2456 if (i1
!= spnt
->dbx_type
)
2458 spnt
->advanced
= ALIAS
;
2463 as_tsktsk ("debugginer output: %d is an unknown untyped variable.",
2465 return 1; /* do not know what this is */
2467 /* now define this module*/
2468 pnt
= str
+ 1; /* point to character past equal sign */
2472 spnt
->advanced
= BASIC
;
2473 if (type_check ("int"))
2475 spnt
->VMS_type
= DBG_S_C_SLINT
;
2476 spnt
->data_size
= 4;
2478 else if (type_check ("long int"))
2480 spnt
->VMS_type
= DBG_S_C_SLINT
;
2481 spnt
->data_size
= 4;
2483 else if (type_check ("unsigned int"))
2485 spnt
->VMS_type
= DBG_S_C_ULINT
;
2486 spnt
->data_size
= 4;
2488 else if (type_check ("long unsigned int"))
2490 spnt
->VMS_type
= DBG_S_C_ULINT
;
2491 spnt
->data_size
= 4;
2493 else if (type_check ("short int"))
2495 spnt
->VMS_type
= DBG_S_C_SSINT
;
2496 spnt
->data_size
= 2;
2498 else if (type_check ("short unsigned int"))
2500 spnt
->VMS_type
= DBG_S_C_USINT
;
2501 spnt
->data_size
= 2;
2503 else if (type_check ("char"))
2505 spnt
->VMS_type
= DBG_S_C_SCHAR
;
2506 spnt
->data_size
= 1;
2508 else if (type_check ("signed char"))
2510 spnt
->VMS_type
= DBG_S_C_SCHAR
;
2511 spnt
->data_size
= 1;
2513 else if (type_check ("unsigned char"))
2515 spnt
->VMS_type
= DBG_S_C_UCHAR
;
2516 spnt
->data_size
= 1;
2518 else if (type_check ("float"))
2520 spnt
->VMS_type
= DBG_S_C_REAL4
;
2521 spnt
->data_size
= 4;
2523 else if (type_check ("double"))
2525 spnt
->VMS_type
= vax_g_doubles
? DBG_S_C_REAL8_G
: DBG_S_C_REAL8
;
2526 spnt
->data_size
= 8;
2528 else if (type_check ("long double"))
2530 /* same as double, at least for now */
2531 spnt
->VMS_type
= vax_g_doubles
? DBG_S_C_REAL8_G
: DBG_S_C_REAL8
;
2532 spnt
->data_size
= 8;
2534 else if (type_check ("long long int"))
2536 spnt
->VMS_type
= DBG_S_C_SQUAD
; /* signed quadword */
2537 spnt
->data_size
= 8;
2539 else if (type_check ("long long unsigned int"))
2541 spnt
->VMS_type
= DBG_S_C_UQUAD
; /* unsigned quadword */
2542 spnt
->data_size
= 8;
2544 else if (type_check ("complex float"))
2546 spnt
->VMS_type
= DBG_S_C_COMPLX4
;
2547 spnt
->data_size
= 2 * 4;
2549 else if (type_check ("complex double"))
2551 spnt
->VMS_type
= vax_g_doubles
? DBG_S_C_COMPLX8_G
: DBG_S_C_COMPLX8
;
2552 spnt
->data_size
= 2 * 8;
2554 else if (type_check ("complex long double"))
2556 /* same as complex double, at least for now */
2557 spnt
->VMS_type
= vax_g_doubles
? DBG_S_C_COMPLX8_G
: DBG_S_C_COMPLX8
;
2558 spnt
->data_size
= 2 * 8;
2563 * Shouldn't get here, but if we do, something
2564 * more substantial ought to be done...
2567 spnt
->data_size
= 0;
2569 if (spnt
->VMS_type
!= 0)
2570 setup_basic_type (spnt
);
2571 pnt1
= (char *) strchr (str
, ';') + 1;
2575 spnt
->advanced
= (*pnt
== 's') ? STRUCT
: UNION
;
2576 spnt
->VMS_type
= DBG_S_C_ADVANCED_TYPE
;
2577 pnt1
= cvt_integer (pnt
+ 1, &spnt
->data_size
);
2578 if (!final_pass
&& forward_reference (pnt
))
2580 spnt
->struc_numb
= -1;
2583 spnt
->struc_numb
= ++structure_count
;
2585 pnt
= get_struct_name (str
);
2586 VMS_Def_Struct (spnt
->struc_numb
);
2588 for (fpnt
= f_ref_root
; fpnt
; fpnt
= fpnt
->next
)
2589 if (fpnt
->dbx_type
== spnt
->dbx_type
)
2591 fpnt
->resolved
= 'Y';
2592 VMS_Set_Struct (fpnt
->struc_numb
);
2593 VMS_Store_Struct (spnt
->struc_numb
);
2597 VMS_Set_Struct (spnt
->struc_numb
);
2599 Local
[i
++] = 11 + strlen (pnt
);
2600 Local
[i
++] = DBG_S_C_STRUCT_START
;
2601 Local
[i
++] = DST_K_VFLAGS_NOVAL
; /* structure definition only */
2602 COPY_LONG (&Local
[i
], 0L); /* hence value is unused */
2604 Local
[i
++] = strlen (pnt
);
2606 while (*pnt2
!= '\0')
2607 Local
[i
++] = *pnt2
++;
2608 i2
= spnt
->data_size
* 8; /* number of bits */
2609 COPY_LONG (&Local
[i
], i2
);
2611 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2613 if (pnt
!= symbol_name
)
2615 pnt
+= strlen (pnt
);
2617 } /* replace colon for later */
2618 while (*++pnt1
!= ';')
2620 pnt
= (char *) strchr (pnt1
, ':');
2623 pnt1
= cvt_integer (pnt
+ 1, &dtype
);
2624 pnt1
= cvt_integer (pnt1
+ 1, &i2
);
2625 pnt1
= cvt_integer (pnt1
+ 1, &i3
);
2626 spnt1
= find_symbol (dtype
);
2627 len
= strlen (pnt2
);
2628 if (spnt1
&& (spnt1
->advanced
== BASIC
|| spnt1
->advanced
== ENUM
)
2629 && ((i3
!= spnt1
->data_size
* 8) || (i2
% 8 != 0)))
2631 if (USE_BITSTRING_DESCRIPTOR (spnt1
))
2633 /* This uses a type descriptor, which doesn't work if
2634 the enclosing structure has been placed in a register.
2635 Also, enum bitfields degenerate to simple integers. */
2636 int unsigned_type
= (spnt1
->VMS_type
== DBG_S_C_ULINT
2637 || spnt1
->VMS_type
== DBG_S_C_USINT
2638 || spnt1
->VMS_type
== DBG_S_C_UCHAR
2639 || spnt1
->VMS_type
== DBG_S_C_UQUAD
2640 || spnt1
->advanced
== ENUM
); /* (approximate) */
2642 fpush (19 + len
, 1);
2643 fpush (unsigned_type
? DBG_S_C_UBITU
: DBG_S_C_SBITU
, 1);
2644 fpush (DST_K_VFLAGS_DSC
, 1); /* specified by descriptor */
2645 fpush (1 + len
, 4); /* relative offset to descriptor */
2646 fpush (len
, 1); /* length byte (ascic prefix) */
2647 while (*pnt2
!= '\0') /* name bytes */
2649 fpush (i3
, 2); /* dsc length == size of bitfield */
2650 /* dsc type == un?signed bitfield */
2651 fpush (unsigned_type
? DBG_S_C_UBITU
: DBG_S_C_SBITU
, 1);
2652 fpush (DSC_K_CLASS_UBS
, 1); /* dsc class == unaligned bitstring */
2653 fpush (0x00, 4); /* dsc pointer == zeroes */
2654 fpush (i2
, 4); /* start position */
2655 VMS_Store_Immediate_Data (Asuffix
, Apoint
, OBJ_S_C_DBG
);
2660 /* Use a "novel length" type specification, which works
2661 right for register structures and for enum bitfields
2662 but results in larger object modules. */
2663 Local
[i
++] = 7 + len
;
2664 Local
[i
++] = DBG_S_C_ADVANCED_TYPE
; /* type spec follows */
2665 Local
[i
++] = DBG_S_C_STRUCT_ITEM
; /* value is a bit offset */
2666 COPY_LONG (&Local
[i
], i2
); /* bit offset */
2668 Local
[i
++] = strlen (pnt2
);
2669 while (*pnt2
!= '\0')
2670 Local
[i
++] = *pnt2
++;
2671 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2673 bitfield_suffix (spnt1
, i3
);
2677 { /* not a bitfield */
2678 /* check if this is a forward reference */
2679 if (final_pass
&& final_forward_reference (spnt1
))
2681 as_tsktsk ("debugger output: structure element `%s' has undefined type",
2685 Local
[i
++] = 7 + len
;
2686 Local
[i
++] = spnt1
? spnt1
->VMS_type
: DBG_S_C_ADVANCED_TYPE
;
2687 Local
[i
++] = DBG_S_C_STRUCT_ITEM
;
2688 COPY_LONG (&Local
[i
], i2
); /* bit offset */
2690 Local
[i
++] = strlen (pnt2
);
2691 while (*pnt2
!= '\0')
2692 Local
[i
++] = *pnt2
++;
2693 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2696 generate_suffix (spnt1
, dtype
);
2697 else if (spnt1
->VMS_type
== DBG_S_C_ADVANCED_TYPE
)
2698 generate_suffix (spnt1
, 0);
2702 Local
[i
++] = 0x01; /* length byte */
2703 Local
[i
++] = DBG_S_C_STRUCT_END
;
2704 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2708 spnt
->advanced
= ENUM
;
2709 spnt
->VMS_type
= DBG_S_C_ADVANCED_TYPE
;
2710 spnt
->struc_numb
= ++structure_count
;
2711 spnt
->data_size
= 4;
2712 VMS_Def_Struct (spnt
->struc_numb
);
2714 for (fpnt
= f_ref_root
; fpnt
; fpnt
= fpnt
->next
)
2715 if (fpnt
->dbx_type
== spnt
->dbx_type
)
2717 fpnt
->resolved
= 'Y';
2718 VMS_Set_Struct (fpnt
->struc_numb
);
2719 VMS_Store_Struct (spnt
->struc_numb
);
2723 VMS_Set_Struct (spnt
->struc_numb
);
2725 len
= strlen (symbol_name
);
2726 Local
[i
++] = 3 + len
;
2727 Local
[i
++] = DBG_S_C_ENUM_START
;
2728 Local
[i
++] = 4 * 8; /* enum values are 32 bits */
2731 while (*pnt2
!= '\0')
2732 Local
[i
++] = *pnt2
++;
2733 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2735 while (*++pnt
!= ';')
2737 pnt1
= (char *) strchr (pnt
, ':');
2739 pnt1
= cvt_integer (pnt1
, &i1
);
2741 Local
[i
++] = 7 + len
;
2742 Local
[i
++] = DBG_S_C_ENUM_ITEM
;
2743 Local
[i
++] = DST_K_VALKIND_LITERAL
;
2744 COPY_LONG (&Local
[i
], i1
);
2748 while (*pnt
!= '\0')
2749 Local
[i
++] = *pnt
++;
2750 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2752 pnt
= pnt1
; /* Skip final semicolon */
2754 Local
[i
++] = 0x01; /* len byte */
2755 Local
[i
++] = DBG_S_C_ENUM_END
;
2756 VMS_Store_Immediate_Data (Local
, i
, OBJ_S_C_DBG
);
2761 spnt
->advanced
= ARRAY
;
2762 spnt
->VMS_type
= DBG_S_C_ADVANCED_TYPE
;
2763 pnt
= (char *) strchr (pnt
, ';');
2766 pnt1
= cvt_integer (pnt
+ 1, &spnt
->index_min
);
2767 pnt1
= cvt_integer (pnt1
+ 1, &spnt
->index_max
);
2768 pnt1
= cvt_integer (pnt1
+ 1, &spnt
->type2
);
2769 pnt
= (char *) strchr (str
+ 1, '=');
2770 if (pnt
&& VMS_typedef_parse (pnt
) == 1)
2774 spnt
->advanced
= FUNCTION
;
2775 spnt
->VMS_type
= DBG_S_C_FUNCTION_ADDR
;
2776 /* this masquerades as a basic type*/
2777 spnt
->data_size
= 4;
2778 pnt1
= cvt_integer (pnt
+ 1, &spnt
->type2
);
2781 spnt
->advanced
= POINTER
;
2782 spnt
->VMS_type
= DBG_S_C_ADVANCED_TYPE
;
2783 spnt
->data_size
= 4;
2784 pnt1
= cvt_integer (pnt
+ 1, &spnt
->type2
);
2785 pnt
= (char *) strchr (str
+ 1, '=');
2786 if (pnt
&& VMS_typedef_parse (pnt
) == 1)
2790 spnt
->advanced
= UNKNOWN
;
2792 as_tsktsk ("debugger output: %d is an unknown type of variable.",
2794 return 1; /* unable to decipher */
2796 /* this removes the evidence of the definition so that the outer levels of
2797 parsing do not have to worry about it */
2799 while (*pnt1
!= '\0')
2807 * This is the root routine that parses the stabs entries for definitions.
2808 * it calls VMS_typedef_parse, which can in turn call itself.
2809 * We need to be careful, since sometimes there are forward references to
2810 * other symbol types, and these cannot be resolved until we have completed
2813 * Also check and see if we are using continuation stabs, if we are, then
2814 * paste together the entire contents of the stab before we pass it to
2815 * VMS_typedef_parse.
2824 char *parse_buffer
= 0;
2826 int incomplete
, pass
, incom1
;
2827 struct forward_ref
*fpnt
;
2835 incom1
= incomplete
;
2837 for (sp
= symbol_rootP
; sp
; sp
= symbol_next (sp
))
2840 * Deal with STAB symbols
2842 if (S_IS_DEBUG (sp
))
2845 * Dispatch on STAB type
2847 switch (S_GET_RAW_TYPE (sp
))
2855 case N_FUN
: /*sometimes these contain typedefs*/
2856 str
= S_GET_NAME (sp
);
2858 pnt
= str
+ strlen (str
) - 1;
2859 if (*pnt
== '?') /* Continuation stab. */
2866 tlen
+= strlen (str
) - 1;
2867 spnext
= symbol_next (spnext
);
2868 str
= S_GET_NAME (spnext
);
2869 pnt
= str
+ strlen (str
) - 1;
2870 } while (*pnt
== '?');
2871 tlen
+= strlen (str
);
2872 parse_buffer
= (char *) xmalloc (tlen
+ 1);
2873 strcpy (parse_buffer
, S_GET_NAME (sp
));
2874 pnt2
= parse_buffer
+ strlen(parse_buffer
) - 1;
2878 spnext
= symbol_next (spnext
);
2879 str
= S_GET_NAME (spnext
);
2881 pnt2
+= strlen (str
) - 1;
2882 *str
= '\0'; /* Erase this string */
2883 if (*pnt2
!= '?') break;
2889 pnt
= (char *) strchr (str
, ':');
2890 if (pnt
!= (char *) NULL
)
2894 pnt2
= (char *) strchr (pnt1
, '=');
2895 if (pnt2
!= (char *) NULL
)
2896 incomplete
+= VMS_typedef_parse (pnt2
);
2899 /* At this point the parse buffer should just
2900 contain name:nn. If it does not, then we
2901 are in real trouble. Anyway, this is always
2902 shorter than the original line. */
2903 strcpy (S_GET_NAME (sp
), parse_buffer
);
2904 free (parse_buffer
);
2907 *pnt
= ':'; /* put back colon to restore dbx_type */
2914 /* Make one last pass, if needed, and define whatever we can that is left */
2915 if (final_pass
== 0 && incomplete
== incom1
)
2918 incom1
++; /* Force one last pass through */
2920 } while ((incomplete
!= 0) && (incomplete
!= incom1
));
2921 /* repeat until all refs resolved if possible */
2922 /* if (pass > 1) printf (" Required %d passes\n", pass);*/
2923 if (incomplete
!= 0)
2925 as_tsktsk ("debugger output: Unable to resolve %d circular references.",
2930 while (fpnt
!= (struct forward_ref
*) NULL
)
2932 if (fpnt
->resolved
!= 'Y')
2934 if (find_symbol (fpnt
->dbx_type
) !=
2935 (struct VMS_DBG_Symbol
*) NULL
)
2937 as_tsktsk ("debugger forward reference error, dbx type %d",
2942 sprintf (&fixit
[1], "%d=s4;", fpnt
->dbx_type
);
2943 pnt2
= (char *) strchr (&fixit
[1], '=');
2944 VMS_typedef_parse (pnt2
);
2951 Define_Local_Symbols (s0P
, s2P
, Current_Routine
, Text_Psect
)
2953 symbolS
*Current_Routine
;
2956 symbolS
*s1P
; /* each symbol from s0P .. s2P (exclusive) */
2958 for (s1P
= symbol_next (s0P
); s1P
!= s2P
; s1P
= symbol_next (s1P
))
2961 break; /* and return */
2962 if (S_GET_RAW_TYPE (s1P
) == N_FUN
)
2964 char *pnt
= (char *) strchr (S_GET_NAME (s1P
), ':') + 1;
2965 if (*pnt
== 'F' || *pnt
== 'f') break;
2967 if (!S_IS_DEBUG (s1P
))
2970 * Dispatch on STAB type
2972 switch (S_GET_RAW_TYPE (s1P
))
2975 continue; /* not left or right brace */
2979 VMS_local_stab_Parse (s1P
);
2983 VMS_RSYM_Parse (s1P
, Current_Routine
, Text_Psect
);
2990 /* This function crawls the symbol chain searching for local symbols that need
2991 * to be described to the debugger. When we enter a new scope with a "{", it
2992 * creates a new "block", which helps the debugger keep track of which scope
2993 * we are currently in.
2997 Define_Routine (s0P
, Level
, Current_Routine
, Text_Psect
)
3000 symbolS
*Current_Routine
;
3007 for (s1P
= symbol_next (s0P
); s1P
!= 0; s1P
= symbol_next (s1P
))
3009 if (S_GET_RAW_TYPE (s1P
) == N_FUN
)
3011 char *pnt
= (char *) strchr (S_GET_NAME (s1P
), ':') + 1;
3012 if (*pnt
== 'F' || *pnt
== 'f') break;
3014 if (!S_IS_DEBUG (s1P
))
3017 * Dispatch on STAB type
3019 switch (S_GET_RAW_TYPE (s1P
))
3022 continue; /* not left or right brace */
3028 sprintf (str
, "$%d", rcount
++);
3029 VMS_TBT_Block_Begin (s1P
, Text_Psect
, str
);
3031 Offset
= S_GET_VALUE (s1P
); /* side-effect: fully resolve symbol */
3032 Define_Local_Symbols (s0P
, s1P
, Current_Routine
, Text_Psect
);
3033 s1P
= Define_Routine (s1P
, Level
+ 1, Current_Routine
, Text_Psect
);
3035 VMS_TBT_Block_End (S_GET_VALUE (s1P
) - Offset
);
3044 /* We end up here if there were no brackets in this function.
3045 Define everything. */
3046 Define_Local_Symbols (s0P
, (symbolS
*)0, Current_Routine
, Text_Psect
);
3052 #include <sys/types.h>
3054 static void get_VMS_time_on_unix
PARAMS ((char *));
3056 /* Manufacture a VMS-like time string on a Unix based system. */
3058 get_VMS_time_on_unix (Now
)
3065 pnt
= ctime (&timeb
);
3071 sprintf (Now
, "%2s-%3s-%s %s", pnt
+ 8, pnt
+ 4, pnt
+ 20, pnt
+ 11);
3073 #endif /* not VMS */
3076 /* Write the MHD (Module Header) records. */
3079 Write_VMS_MHD_Records ()
3081 register const char *cp
;
3085 struct { unsigned short len
, mbz
; char *ptr
; } Descriptor
;
3089 /* We are writing a module header record. */
3090 Set_VMS_Object_File_Record (OBJ_S_C_HDR
);
3092 * ***************************
3093 * *MAIN MODULE HEADER RECORD*
3094 * ***************************
3096 /* Store record type and header type. */
3097 PUT_CHAR (OBJ_S_C_HDR
);
3098 PUT_CHAR (MHD_S_C_MHD
);
3099 /* Structure level is 0. */
3100 PUT_CHAR (OBJ_S_C_STRLVL
);
3101 /* Maximum record size is size of the object record buffer. */
3102 PUT_SHORT (sizeof (Object_Record_Buffer
));
3105 * FIXME: module name and version should be user
3106 * specifiable via `.ident' and/or `#pragma ident'.
3109 /* Get module name (the FILENAME part of the object file). */
3114 if (*cp
== ']' || *cp
== '>' || *cp
== ':' || *cp
== '/')
3120 *cp1
++ = islower (*cp
) ? toupper (*cp
++) : *cp
++;
3124 /* Limit it to 31 characters and store in the object record. */
3125 while (--cp1
>= Module_Name
)
3128 if (strlen (Module_Name
) > 31)
3130 if (flag_hash_long_names
)
3131 as_tsktsk ("Module name truncated: %s\n", Module_Name
);
3132 Module_Name
[31] = '\0';
3134 PUT_COUNTED_STRING (Module_Name
);
3135 /* Module Version is "V1.0". */
3136 PUT_COUNTED_STRING ("V1.0");
3137 /* Creation time is "now" (17 chars of time string): "dd-MMM-yyyy hh:mm". */
3139 get_VMS_time_on_unix (Now
);
3141 Descriptor
.len
= sizeof Now
- 1;
3142 Descriptor
.mbz
= 0; /* type & class unspecified */
3143 Descriptor
.ptr
= Now
;
3144 (void) sys$
asctim ((unsigned short *)0, &Descriptor
, (long *)0, 0);
3146 for (i
= 0; i
< 17; i
++)
3148 /* Patch time is "never" (17 zeros). */
3149 for (i
= 0; i
< 17; i
++)
3151 /* Force this to be a separate output record. */
3152 Flush_VMS_Object_Record_Buffer ();
3155 * *************************
3156 * *LANGUAGE PROCESSOR NAME*
3157 * *************************
3159 /* Store record type and header type. */
3160 PUT_CHAR (OBJ_S_C_HDR
);
3161 PUT_CHAR (MHD_S_C_LNM
);
3163 * Store language processor name and version (not a counted string!).
3165 * This is normally supplied by the gcc driver for the command line
3166 * which invokes gas. If absent, we fall back to gas's version.
3168 cp
= compiler_version_string
;
3178 /* Force this to be a separate output record. */
3179 Flush_VMS_Object_Record_Buffer ();
3183 /* Write the EOM (End Of Module) record. */
3186 Write_VMS_EOM_Record (Psect
, Offset
)
3191 * We are writing an end-of-module record
3192 * (this assumes that the entry point will always be in a psect
3193 * represented by a single byte, which is the case for code in
3196 Set_VMS_Object_File_Record (OBJ_S_C_EOM
);
3197 PUT_CHAR (OBJ_S_C_EOM
); /* Record type. */
3198 PUT_CHAR (0); /* Error severity level (we ignore it). */
3200 * Store the entry point, if it exists
3207 /* Flush the record; this will be our final output. */
3208 Flush_VMS_Object_Record_Buffer ();
3212 /* this hash routine borrowed from GNU-EMACS, and strengthened slightly ERY*/
3218 register const unsigned char *p
= (unsigned char *) ptr
;
3219 register const unsigned char *end
= p
+ strlen (ptr
);
3220 register unsigned char c
;
3221 register int hash
= 0;
3226 hash
= ((hash
<< 3) + (hash
<< 15) + (hash
>> 28) + c
);
3232 * Generate a Case-Hacked VMS symbol name (limited to 31 chars)
3235 VMS_Case_Hack_Symbol (In
, Out
)
3236 register const char *In
;
3243 const char *old_name
;
3245 int destructor
= 0; /*hack to allow for case sens in a destructor*/
3247 int Case_Hack_Bits
= 0;
3249 static char Hex_Table
[16] =
3250 {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
3253 * Kill any leading "_"
3255 if ((In
[0] == '_') && ((In
[1] > '9') || (In
[1] < '0')))
3258 new_name
= Out
; /* save this for later*/
3260 #if barfoo /* Dead code */
3261 if ((In
[0] == '_') && (In
[1] == '$') && (In
[2] == '_'))
3265 /* We may need to truncate the symbol, save the hash for later*/
3266 result
= (strlen (In
) > 23) ? hash_string (In
) : 0;
3268 * Is there a Psect Attribute to skip??
3270 if (HAS_PSECT_ATTRIBUTES (In
))
3275 In
+= PSECT_ATTRIBUTES_STRING_LENGTH
;
3278 if ((In
[0] == '$') && (In
[1] == '$'))
3288 /* if (strlen (In) > 31 && flag_hash_long_names)
3289 as_tsktsk ("Symbol name truncated: %s\n", In); */
3291 * Do the case conversion
3293 i
= 23; /* Maximum of 23 chars */
3294 while (*In
&& (--i
>= 0))
3296 Case_Hack_Bits
<<= 1;
3299 if ((destructor
== 1) && (i
== 21))
3301 switch (vms_name_mapping
)
3304 if (isupper (*In
)) {
3306 Case_Hack_Bits
|= 1;
3308 *Out
++ = islower (*In
) ? toupper (*In
++) : *In
++;
3311 case 3: *Out
++ = *In
++;
3314 if (islower (*In
)) {
3317 *Out
++ = isupper (*In
) ? tolower (*In
++) : *In
++;
3323 * If we saw a dollar sign, we don't do case hacking
3325 if (flag_no_hash_mixed_case
|| Saw_Dollar
)
3329 * If we have more than 23 characters and everything is lowercase
3330 * we can insert the full 31 characters
3335 * We have more than 23 characters
3336 * If we must add the case hack, then we have truncated the str
3340 if (Case_Hack_Bits
== 0)
3343 * And so far they are all lower case:
3344 * Check up to 8 more characters
3345 * and ensure that they are lowercase
3347 for (i
= 0; (In
[i
] != 0) && (i
< 8); i
++)
3348 if (isupper (In
[i
]) && !Saw_Dollar
&& !flag_no_hash_mixed_case
)
3354 if ((i
== 8) || (In
[i
] == 0))
3357 * They are: Copy up to 31 characters
3358 * to the output string
3361 while ((--i
>= 0) && (*In
))
3362 switch (vms_name_mapping
){
3363 case 0: *Out
++ = islower (*In
) ? toupper (*In
++) : *In
++;
3365 case 3: *Out
++ = *In
++;
3367 case 2: *Out
++ = isupper (*In
) ? tolower (*In
++) : *In
++;
3374 * If there were any uppercase characters in the name we
3375 * take on the case hacking string
3378 /* Old behavior for regular GNU-C compiler */
3379 if (!flag_hash_long_names
)
3381 if ((Case_Hack_Bits
!= 0) || (truncate
== 1))
3386 for (i
= 0; i
< 6; i
++)
3388 *Out
++ = Hex_Table
[Case_Hack_Bits
& 0xf];
3389 Case_Hack_Bits
>>= 4;
3395 Out
= pnt
; /*Cut back to 23 characters maximum */
3397 for (i
= 0; i
< 7; i
++)
3399 init
= result
& 0x01f;
3400 *Out
++ = (init
< 10) ? ('0' + init
) : ('A' + init
- 10);
3401 result
= result
>> 5;
3409 if (truncate
== 1 && flag_hash_long_names
&& flag_show_after_trunc
)
3410 as_tsktsk ("Symbol %s replaced by %s\n", old_name
, new_name
);
3415 * Scan a symbol name for a psect attribute specification
3417 #define GLOBALSYMBOL_BIT 0x10000
3418 #define GLOBALVALUE_BIT 0x20000
3422 VMS_Modify_Psect_Attributes (Name
, Attribute_Pointer
)
3424 int *Attribute_Pointer
;
3427 register const char *cp
;
3435 {"PIC", GPS_S_M_PIC
},
3436 {"LIB", GPS_S_M_LIB
},
3437 {"OVR", GPS_S_M_OVR
},
3438 {"REL", GPS_S_M_REL
},
3439 {"GBL", GPS_S_M_GBL
},
3440 {"SHR", GPS_S_M_SHR
},
3441 {"EXE", GPS_S_M_EXE
},
3443 {"WRT", GPS_S_M_WRT
},
3444 {"VEC", GPS_S_M_VEC
},
3445 {"GLOBALSYMBOL", GLOBALSYMBOL_BIT
},
3446 {"GLOBALVALUE", GLOBALVALUE_BIT
},
3456 * Check for a PSECT attribute list
3458 if (!HAS_PSECT_ATTRIBUTES (Name
))
3459 return; /* If not, return */
3461 * Skip the attribute list indicator
3463 Name
+= PSECT_ATTRIBUTES_STRING_LENGTH
;
3465 * Process the attributes ("_" separated, "$" terminated)
3467 while (*Name
!= '$')
3470 * Assume not negating
3476 if ((Name
[0] == 'N') && (Name
[1] == 'O'))
3479 * We are negating (and skip the NO)
3485 * Find the token delimiter
3488 while (*cp
&& (*cp
!= '_') && (*cp
!= '$'))
3491 * Look for the token in the attribute list
3493 for (i
= 0; Attributes
[i
].Name
; i
++)
3496 * If the strings match, set/clear the attr.
3498 if (strncmp (Name
, Attributes
[i
].Name
, cp
- Name
) == 0)
3504 *Attribute_Pointer
&=
3505 ~Attributes
[i
].Value
;
3507 *Attribute_Pointer
|=
3508 Attributes
[i
].Value
;
3516 * Now skip the attribute
3525 #define GBLSYM_REF 0
3526 #define GBLSYM_DEF 1
3527 #define GBLSYM_VAL 2
3528 #define GBLSYM_LCL 4 /* not GBL after all... */
3531 * Define a global symbol (or possibly a local one).
3534 VMS_Global_Symbol_Spec (Name
, Psect_Number
, Psect_Offset
, Flags
)
3543 * We are writing a GSD record
3545 Set_VMS_Object_File_Record (OBJ_S_C_GSD
);
3547 * If the buffer is empty we must insert the GSD record type
3549 if (Object_Record_Offset
== 0)
3550 PUT_CHAR (OBJ_S_C_GSD
);
3552 * We are writing a Global (or local) symbol definition subrecord.
3554 PUT_CHAR ((Flags
& GBLSYM_LCL
) != 0 ? GSD_S_C_LSY
:
3555 ((unsigned) Psect_Number
<= 255) ? GSD_S_C_SYM
: GSD_S_C_SYMW
);
3557 * Data type is undefined
3561 * Switch on Definition/Reference
3563 if ((Flags
& GBLSYM_DEF
) == 0)
3568 PUT_SHORT (((Flags
& GBLSYM_VAL
) == 0) ? GSY_S_M_REL
: 0);
3569 if ((Flags
& GBLSYM_LCL
) != 0) /* local symbols have extra field */
3570 PUT_SHORT (Current_Environment
);
3576 *[ assert (LSY_S_M_DEF == GSY_S_M_DEF && LSY_S_M_REL == GSY_S_M_REL); ]
3578 PUT_SHORT (((Flags
& GBLSYM_VAL
) == 0) ?
3579 GSY_S_M_DEF
| GSY_S_M_REL
: GSY_S_M_DEF
);
3580 if ((Flags
& GBLSYM_LCL
) != 0) /* local symbols have extra field */
3581 PUT_SHORT (Current_Environment
);
3585 if ((Flags
& GBLSYM_LCL
) == 0 && (unsigned) Psect_Number
<= 255)
3586 PUT_CHAR (Psect_Number
);
3588 PUT_SHORT (Psect_Number
);
3592 PUT_LONG (Psect_Offset
);
3595 * Finally, the global symbol name
3597 VMS_Case_Hack_Symbol (Name
, Local
);
3598 PUT_COUNTED_STRING (Local
);
3600 * Flush the buffer if it is more than 75% full
3602 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
3603 Flush_VMS_Object_Record_Buffer ();
3607 * Define an environment to support local symbol references.
3608 * This is just to mollify the linker; we don't actually do
3609 * anything useful with it.
3612 VMS_Local_Environment_Setup (Env_Name
)
3613 const char *Env_Name
;
3615 /* We are writing a GSD record. */
3616 Set_VMS_Object_File_Record (OBJ_S_C_GSD
);
3617 /* If the buffer is empty we must insert the GSD record type. */
3618 if (Object_Record_Offset
== 0)
3619 PUT_CHAR (OBJ_S_C_GSD
);
3620 /* We are writing an ENV subrecord. */
3621 PUT_CHAR (GSD_S_C_ENV
);
3623 ++Current_Environment
; /* index of environment being defined */
3625 /* ENV$W_FLAGS: we are defining the next environment. It's not nested. */
3626 PUT_SHORT (ENV_S_M_DEF
);
3627 /* ENV$W_ENVINDX: index is always 0 for non-nested definitions. */
3630 /* ENV$B_NAMLNG + ENV$T_NAME: environment name in ASCIC format. */
3631 if (!Env_Name
) Env_Name
= "";
3632 PUT_COUNTED_STRING ((char *)Env_Name
);
3634 /* Flush the buffer if it is more than 75% full. */
3635 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
3636 Flush_VMS_Object_Record_Buffer ();
3644 VMS_Psect_Spec (Name
, Size
, Type
, vsp
)
3648 struct VMS_Symbol
*vsp
;
3651 int Psect_Attributes
;
3654 * Generate the appropriate PSECT flags given the PSECT type
3659 /* Text psects are PIC,noOVR,REL,noGBL,SHR,EXE,RD,noWRT. */
3660 Psect_Attributes
= (GPS_S_M_PIC
|GPS_S_M_REL
|GPS_S_M_SHR
|GPS_S_M_EXE
3664 /* Data psects are PIC,noOVR,REL,noGBL,noSHR,noEXE,RD,WRT. */
3665 Psect_Attributes
= (GPS_S_M_PIC
|GPS_S_M_REL
|GPS_S_M_RD
|GPS_S_M_WRT
);
3668 /* Common block psects are: PIC,OVR,REL,GBL,SHR,noEXE,RD,WRT. */
3669 Psect_Attributes
= (GPS_S_M_PIC
|GPS_S_M_OVR
|GPS_S_M_REL
|GPS_S_M_GBL
3670 |GPS_S_M_SHR
|GPS_S_M_RD
|GPS_S_M_WRT
);
3673 /* Const data psects are: PIC,OVR,REL,GBL,SHR,noEXE,RD,noWRT. */
3674 Psect_Attributes
= (GPS_S_M_PIC
|GPS_S_M_OVR
|GPS_S_M_REL
|GPS_S_M_GBL
3675 |GPS_S_M_SHR
|GPS_S_M_RD
);
3679 error ("Unknown VMS psect type (%ld)", (long) Type
);
3683 * Modify the psect attributes according to any attribute string
3685 if (vsp
&& S_GET_TYPE (vsp
->Symbol
) == N_ABS
)
3686 Psect_Attributes
|= GLOBALVALUE_BIT
;
3687 else if (HAS_PSECT_ATTRIBUTES (Name
))
3688 VMS_Modify_Psect_Attributes (Name
, &Psect_Attributes
);
3690 * Check for globalref/def/val.
3692 if ((Psect_Attributes
& GLOBALVALUE_BIT
) != 0)
3695 * globalvalue symbols were generated before. This code
3696 * prevents unsightly psect buildup, and makes sure that
3697 * fixup references are emitted correctly.
3699 vsp
->Psect_Index
= -1; /* to catch errors */
3700 S_SET_TYPE (vsp
->Symbol
, N_UNDF
); /* make refs work */
3701 return 1; /* decrement psect counter */
3704 if ((Psect_Attributes
& GLOBALSYMBOL_BIT
) != 0)
3706 switch (S_GET_RAW_TYPE (vsp
->Symbol
))
3708 case N_UNDF
| N_EXT
:
3709 VMS_Global_Symbol_Spec (Name
, vsp
->Psect_Index
,
3710 vsp
->Psect_Offset
, GBLSYM_REF
);
3711 vsp
->Psect_Index
= -1;
3712 S_SET_TYPE (vsp
->Symbol
, N_UNDF
);
3713 return 1; /* return and indicate no psect */
3714 case N_DATA
| N_EXT
:
3715 VMS_Global_Symbol_Spec (Name
, vsp
->Psect_Index
,
3716 vsp
->Psect_Offset
, GBLSYM_DEF
);
3717 /* In this case we still generate the psect */
3720 as_fatal ("Globalsymbol attribute for symbol %s was unexpected.",
3726 Psect_Attributes
&= 0xffff; /* clear out the globalref/def stuff */
3728 * We are writing a GSD record
3730 Set_VMS_Object_File_Record (OBJ_S_C_GSD
);
3732 * If the buffer is empty we must insert the GSD record type
3734 if (Object_Record_Offset
== 0)
3735 PUT_CHAR (OBJ_S_C_GSD
);
3737 * We are writing a PSECT definition subrecord
3739 PUT_CHAR (GSD_S_C_PSC
);
3741 * Psects are always LONGWORD aligned
3745 * Specify the psect attributes
3747 PUT_SHORT (Psect_Attributes
);
3749 * Specify the allocation
3753 * Finally, the psect name
3755 VMS_Case_Hack_Symbol (Name
, Local
);
3756 PUT_COUNTED_STRING (Local
);
3758 * Flush the buffer if it is more than 75% full
3760 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
3761 Flush_VMS_Object_Record_Buffer ();
3766 /* Given the pointer to a symbol we calculate how big the data at the
3767 symbol is. We do this by looking for the next symbol (local or global)
3768 which will indicate the start of another datum. */
3771 VMS_Initialized_Data_Size (s0P
, End_Of_Data
)
3772 register symbolS
*s0P
;
3773 unsigned End_Of_Data
;
3776 valueT s0P_val
= S_GET_VALUE (s0P
), s1P_val
,
3777 nearest_val
= (valueT
) End_Of_Data
;
3779 /* Find the nearest symbol what follows this one. */
3780 for (s1P
= symbol_rootP
; s1P
; s1P
= symbol_next (s1P
))
3782 /* The data type must match. */
3783 if (S_GET_TYPE (s1P
) != N_DATA
)
3785 s1P_val
= S_GET_VALUE (s1P
);
3786 if (s1P_val
> s0P_val
&& s1P_val
< nearest_val
)
3787 nearest_val
= s1P_val
;
3789 /* Calculate its size. */
3790 return (offsetT
) (nearest_val
- s0P_val
);
3794 /* Check symbol names for the Psect hack with a globalvalue, and then
3795 generate globalvalues for those that have it. */
3798 VMS_Emit_Globalvalues (text_siz
, data_siz
, Data_Segment
)
3803 register symbolS
*sp
;
3804 char *stripped_name
, *Name
;
3806 int Psect_Attributes
;
3811 * Scan the symbol table for globalvalues, and emit def/ref when
3812 * required. These will be caught again later and converted to
3815 for (sp
= symbol_rootP
; sp
; sp
= sp
->sy_next
)
3817 typ
= S_GET_RAW_TYPE (sp
);
3818 abstyp
= ((typ
& ~N_EXT
) == N_ABS
);
3820 * See if this is something we want to look at.
3823 typ
!= (N_DATA
| N_EXT
) &&
3824 typ
!= (N_UNDF
| N_EXT
))
3827 * See if this has globalvalue specification.
3829 Name
= S_GET_NAME (sp
);
3834 Psect_Attributes
= GLOBALVALUE_BIT
;
3836 else if (HAS_PSECT_ATTRIBUTES (Name
))
3838 stripped_name
= (char *) xmalloc (strlen (Name
) + 1);
3839 strcpy (stripped_name
, Name
);
3840 Psect_Attributes
= 0;
3841 VMS_Modify_Psect_Attributes (stripped_name
, &Psect_Attributes
);
3846 if ((Psect_Attributes
& GLOBALVALUE_BIT
) != 0)
3851 /* Local symbol references will want
3852 to have an environment defined. */
3853 if (Current_Environment
< 0)
3854 VMS_Local_Environment_Setup (".N_ABS");
3855 VMS_Global_Symbol_Spec (Name
, 0,
3857 GBLSYM_DEF
|GBLSYM_VAL
|GBLSYM_LCL
);
3860 VMS_Global_Symbol_Spec (Name
, 0,
3862 GBLSYM_DEF
|GBLSYM_VAL
);
3864 case N_UNDF
| N_EXT
:
3865 VMS_Global_Symbol_Spec (stripped_name
, 0, 0, GBLSYM_VAL
);
3867 case N_DATA
| N_EXT
:
3868 Size
= VMS_Initialized_Data_Size (sp
, text_siz
+ data_siz
);
3870 error ("Invalid data type for globalvalue");
3871 globalvalue
= md_chars_to_number (Data_Segment
+
3872 S_GET_VALUE (sp
) - text_siz
, Size
);
3873 /* Three times for good luck. The linker seems to get confused
3874 if there are fewer than three */
3875 VMS_Global_Symbol_Spec (stripped_name
, 0, 0, GBLSYM_VAL
);
3876 VMS_Global_Symbol_Spec (stripped_name
, 0, globalvalue
,
3877 GBLSYM_DEF
|GBLSYM_VAL
);
3878 VMS_Global_Symbol_Spec (stripped_name
, 0, globalvalue
,
3879 GBLSYM_DEF
|GBLSYM_VAL
);
3882 as_warn ("Invalid globalvalue of %s", stripped_name
);
3886 if (stripped_name
) free (stripped_name
); /* clean up */
3893 * Define a procedure entry pt/mask
3896 VMS_Procedure_Entry_Pt (Name
, Psect_Number
, Psect_Offset
, Entry_Mask
)
3905 * We are writing a GSD record
3907 Set_VMS_Object_File_Record (OBJ_S_C_GSD
);
3909 * If the buffer is empty we must insert the GSD record type
3911 if (Object_Record_Offset
== 0)
3912 PUT_CHAR (OBJ_S_C_GSD
);
3914 * We are writing a Procedure Entry Pt/Mask subrecord
3916 PUT_CHAR (((unsigned) Psect_Number
<= 255) ? GSD_S_C_EPM
: GSD_S_C_EPMW
);
3918 * Data type is undefined
3922 * Flags = "RELOCATABLE" and "DEFINED"
3924 PUT_SHORT (GSY_S_M_DEF
| GSY_S_M_REL
);
3928 if ((unsigned) Psect_Number
<= 255)
3929 PUT_CHAR (Psect_Number
);
3931 PUT_SHORT (Psect_Number
);
3935 PUT_LONG (Psect_Offset
);
3939 PUT_SHORT (Entry_Mask
);
3941 * Finally, the global symbol name
3943 VMS_Case_Hack_Symbol (Name
, Local
);
3944 PUT_COUNTED_STRING (Local
);
3946 * Flush the buffer if it is more than 75% full
3948 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
3949 Flush_VMS_Object_Record_Buffer ();
3954 * Set the current location counter to a particular Psect and Offset
3957 VMS_Set_Psect (Psect_Index
, Offset
, Record_Type
)
3963 * We are writing a "Record_Type" record
3965 Set_VMS_Object_File_Record (Record_Type
);
3967 * If the buffer is empty we must insert the record type
3969 if (Object_Record_Offset
== 0)
3970 PUT_CHAR (Record_Type
);
3972 * Stack the Psect base + Offset
3974 vms_tir_stack_psect (Psect_Index
, Offset
, 0);
3976 * Set relocation base
3978 PUT_CHAR (TIR_S_C_CTL_SETRB
);
3980 * Flush the buffer if it is more than 75% full
3982 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
3983 Flush_VMS_Object_Record_Buffer ();
3988 * Store repeated immediate data in current Psect
3991 VMS_Store_Repeated_Data (Repeat_Count
, Pointer
, Size
, Record_Type
)
3993 register char *Pointer
;
3999 * Ignore zero bytes/words/longwords
4004 if (Pointer
[3] != 0 || Pointer
[2] != 0) break;
4007 if (Pointer
[1] != 0) break;
4010 if (Pointer
[0] != 0) break;
4017 * If the data is too big for a TIR_S_C_STO_RIVB sub-record
4018 * then we do it manually
4022 while (--Repeat_Count
>= 0)
4023 VMS_Store_Immediate_Data (Pointer
, Size
, Record_Type
);
4027 * We are writing a "Record_Type" record
4029 Set_VMS_Object_File_Record (Record_Type
);
4031 * If the buffer is empty we must insert record type
4033 if (Object_Record_Offset
== 0)
4034 PUT_CHAR (Record_Type
);
4036 * Stack the repeat count
4038 PUT_CHAR (TIR_S_C_STA_LW
);
4039 PUT_LONG (Repeat_Count
);
4041 * And now the command and its data
4043 PUT_CHAR (TIR_S_C_STO_RIVB
);
4046 PUT_CHAR (*Pointer
++);
4048 * Flush the buffer if it is more than 75% full
4050 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
4051 Flush_VMS_Object_Record_Buffer ();
4056 * Store a Position Independent Reference
4059 VMS_Store_PIC_Symbol_Reference (Symbol
, Offset
, PC_Relative
,
4060 Psect
, Psect_Offset
, Record_Type
)
4068 register struct VMS_Symbol
*vsp
= Symbol
->sy_obj
;
4073 * We are writing a "Record_Type" record
4075 Set_VMS_Object_File_Record (Record_Type
);
4077 * If the buffer is empty we must insert record type
4079 if (Object_Record_Offset
== 0)
4080 PUT_CHAR (Record_Type
);
4082 * Set to the appropriate offset in the Psect.
4083 * For a Code reference we need to fix the operand
4084 * specifier as well, so back up 1 byte;
4085 * for a Data reference we just store HERE.
4087 VMS_Set_Psect (Psect
,
4088 PC_Relative
? Psect_Offset
- 1 : Psect_Offset
,
4091 * Make sure we are still generating a "Record Type" record
4093 if (Object_Record_Offset
== 0)
4094 PUT_CHAR (Record_Type
);
4096 * Dispatch on symbol type (so we can stack its value)
4098 switch (S_GET_RAW_TYPE (Symbol
))
4107 #ifdef NOT_VAX_11_C_COMPATIBLE
4108 case N_UNDF
| N_EXT
:
4109 case N_DATA
| N_EXT
:
4110 #endif /* NOT_VAX_11_C_COMPATIBLE */
4112 case N_TEXT
| N_EXT
:
4114 * Get the symbol name (case hacked)
4116 VMS_Case_Hack_Symbol (S_GET_NAME (Symbol
), Local
);
4118 * Stack the global symbol value
4122 PUT_CHAR (TIR_S_C_STA_GBL
);
4126 /* Local symbols have an extra field. */
4127 PUT_CHAR (TIR_S_C_STA_LSY
);
4128 PUT_SHORT (Current_Environment
);
4130 PUT_COUNTED_STRING (Local
);
4134 * Stack the longword offset
4136 PUT_CHAR (TIR_S_C_STA_LW
);
4139 * Add the two, leaving the result on the stack
4141 PUT_CHAR (TIR_S_C_OPR_ADD
);
4145 * Uninitialized local data
4149 * Stack the Psect (+offset)
4151 vms_tir_stack_psect (vsp
->Psect_Index
,
4152 vsp
->Psect_Offset
+ Offset
,
4160 * Stack the Psect (+offset)
4162 vms_tir_stack_psect (vsp
->Psect_Index
,
4163 S_GET_VALUE (Symbol
) + Offset
,
4167 * Initialized local or global data
4170 #ifndef NOT_VAX_11_C_COMPATIBLE
4171 case N_UNDF
| N_EXT
:
4172 case N_DATA
| N_EXT
:
4173 #endif /* NOT_VAX_11_C_COMPATIBLE */
4175 * Stack the Psect (+offset)
4177 vms_tir_stack_psect (vsp
->Psect_Index
,
4178 vsp
->Psect_Offset
+ Offset
,
4183 * Store either a code or data reference
4185 PUT_CHAR (PC_Relative
? TIR_S_C_STO_PICR
: TIR_S_C_STO_PIDR
);
4187 * Flush the buffer if it is more than 75% full
4189 if (Object_Record_Offset
> (sizeof (Object_Record_Buffer
) * 3 / 4))
4190 Flush_VMS_Object_Record_Buffer ();
4195 * Check in the text area for an indirect pc-relative reference
4196 * and fix it up with addressing mode 0xff [PC indirect]
4198 * THIS SHOULD BE REPLACED BY THE USE OF TIR_S_C_STO_PIRR IN THE
4199 * PIC CODE GENERATING FIXUP ROUTINE.
4202 VMS_Fix_Indirect_Reference (Text_Psect
, Offset
, fragP
, text_frag_root
)
4205 register fragS
*fragP
;
4206 fragS
*text_frag_root
;
4209 * The addressing mode byte is 1 byte before the address
4213 * Is it in THIS frag??
4215 if ((Offset
< fragP
->fr_address
) ||
4216 (Offset
>= (fragP
->fr_address
+ fragP
->fr_fix
)))
4219 * We need to search for the fragment containing this
4222 for (fragP
= text_frag_root
; fragP
; fragP
= fragP
->fr_next
)
4224 if ((Offset
>= fragP
->fr_address
) &&
4225 (Offset
< (fragP
->fr_address
+ fragP
->fr_fix
)))
4229 * If we couldn't find the frag, things are BAD!!
4232 error ("Couldn't find fixup fragment when checking for indirect reference");
4235 * Check for indirect PC relative addressing mode
4237 if (fragP
->fr_literal
[Offset
- fragP
->fr_address
] == (char) 0xff)
4239 static char Address_Mode
= (char) 0xff;
4242 * Yes: Store the indirect mode back into the image
4243 * to fix up the damage done by STO_PICR
4245 VMS_Set_Psect (Text_Psect
, Offset
, OBJ_S_C_TIR
);
4246 VMS_Store_Immediate_Data (&Address_Mode
, 1, OBJ_S_C_TIR
);
4252 * If the procedure "main()" exists we have to add the instruction
4253 * "jsb c$main_args" at the beginning to be compatible with VAX-11 "C".
4255 * FIXME: the macro name `HACK_DEC_C_STARTUP' should be renamed
4256 * to `HACK_VAXCRTL_STARTUP' because Digital's compiler
4257 * named "DEC C" uses run-time library "DECC$SHR", but this
4258 * startup code is for "VAXCRTL", the library for Digital's
4259 * older "VAX C". Also, this extra code isn't needed for
4260 * supporting gcc because it already generates the VAXCRTL
4261 * startup call when compiling main(). The reference to
4262 * `flag_hash_long_names' looks very suspicious too;
4263 * probably an old-style command line option was inadvertently
4264 * overloaded here, then blindly converted into the new one.
4267 vms_check_for_main ()
4269 register symbolS
*symbolP
;
4270 #ifdef HACK_DEC_C_STARTUP /* JF */
4271 register struct frchain
*frchainP
;
4272 register fragS
*fragP
;
4273 register fragS
**prev_fragPP
;
4274 register struct fix
*fixP
;
4275 register fragS
*New_Frag
;
4277 #endif /* HACK_DEC_C_STARTUP */
4279 symbolP
= (symbolS
*) symbol_find ("_main");
4280 if (symbolP
&& !S_IS_DEBUG (symbolP
) &&
4281 S_IS_EXTERNAL (symbolP
) && (S_GET_TYPE (symbolP
) == N_TEXT
))
4283 #ifdef HACK_DEC_C_STARTUP
4284 if (!flag_hash_long_names
)
4288 * Remember the entry point symbol
4290 Entry_Point_Symbol
= symbolP
;
4291 #ifdef HACK_DEC_C_STARTUP
4296 * Scan all the fragment chains for the one with "_main"
4297 * (Actually we know the fragment from the symbol, but we need
4298 * the previous fragment so we can change its pointer)
4300 frchainP
= frchain_root
;
4304 * Scan all the fragments in this chain, remembering
4305 * the "previous fragment"
4307 prev_fragPP
= &frchainP
->frch_root
;
4308 fragP
= frchainP
->frch_root
;
4309 while (fragP
&& (fragP
!= frchainP
->frch_last
))
4312 * Is this the fragment?
4314 if (fragP
== symbolP
->sy_frag
)
4317 * Yes: Modify the fragment by replacing
4318 * it with a new fragment.
4320 New_Frag
= (fragS
*)
4321 xmalloc (sizeof (*New_Frag
) +
4326 * The fragments are the same except
4327 * that the "fixed" area is larger
4330 New_Frag
->fr_fix
+= 6;
4332 * Copy the literal data opening a hole
4333 * 2 bytes after "_main" (i.e. just after
4334 * the entry mask). Into which we place
4335 * the JSB instruction.
4337 New_Frag
->fr_literal
[0] = fragP
->fr_literal
[0];
4338 New_Frag
->fr_literal
[1] = fragP
->fr_literal
[1];
4339 New_Frag
->fr_literal
[2] = 0x16; /* Jsb */
4340 New_Frag
->fr_literal
[3] = 0xef;
4341 New_Frag
->fr_literal
[4] = 0;
4342 New_Frag
->fr_literal
[5] = 0;
4343 New_Frag
->fr_literal
[6] = 0;
4344 New_Frag
->fr_literal
[7] = 0;
4345 for (i
= 2; i
< fragP
->fr_fix
+ fragP
->fr_var
; i
++)
4346 New_Frag
->fr_literal
[i
+ 6] =
4347 fragP
->fr_literal
[i
];
4349 * Now replace the old fragment with the
4350 * newly generated one.
4352 *prev_fragPP
= New_Frag
;
4354 * Remember the entry point symbol
4356 Entry_Point_Symbol
= symbolP
;
4358 * Scan the text area fixup structures
4359 * as offsets in the fragment may have
4362 for (fixP
= text_fix_root
; fixP
; fixP
= fixP
->fx_next
)
4365 * Look for references to this
4368 if (fixP
->fx_frag
== fragP
)
4371 * Change the fragment
4374 fixP
->fx_frag
= New_Frag
;
4376 * If the offset is after
4377 * the entry mask we need
4378 * to account for the JSB
4379 * instruction we just
4382 if (fixP
->fx_where
>= 2)
4383 fixP
->fx_where
+= 6;
4387 * Scan the symbols as offsets in the
4388 * fragment may have changed
4390 for (symbolP
= symbol_rootP
;
4392 symbolP
= symbol_next (symbolP
))
4395 * Look for references to this
4398 if (symbolP
->sy_frag
== fragP
)
4401 * Change the fragment
4404 symbolP
->sy_frag
= New_Frag
;
4406 * If the offset is after
4407 * the entry mask we need
4408 * to account for the JSB
4409 * instruction we just
4412 if (S_GET_VALUE (symbolP
) >= 2)
4413 S_SET_VALUE (symbolP
,
4414 S_GET_VALUE (symbolP
) + 6);
4418 * Make a symbol reference to
4419 * "_c$main_args" so we can get
4420 * its address inserted into the
4423 symbolP
= (symbolS
*) xmalloc (sizeof (*symbolP
));
4424 S_SET_NAME (symbolP
, "_C$MAIN_ARGS");
4425 S_SET_TYPE (symbolP
, N_UNDF
);
4426 S_SET_OTHER (symbolP
, 0);
4427 S_SET_DESC (symbolP
, 0);
4428 S_SET_VALUE (symbolP
, 0);
4429 symbolP
->sy_name_offset
= 0;
4430 symbolP
->sy_number
= 0;
4431 symbolP
->sy_obj
= 0;
4432 symbolP
->sy_frag
= New_Frag
;
4433 symbolP
->sy_resolved
= 0;
4434 symbolP
->sy_resolving
= 0;
4435 /* this actually inserts at the beginning of the list */
4436 symbol_append (symbol_rootP
, symbolP
,
4437 &symbol_rootP
, &symbol_lastP
);
4439 symbol_rootP
= symbolP
;
4441 * Generate a text fixup structure
4442 * to get "_c$main_args" stored into the
4445 fixP
= (struct fix
*) xmalloc (sizeof (*fixP
));
4446 fixP
->fx_frag
= New_Frag
;
4448 fixP
->fx_addsy
= symbolP
;
4450 fixP
->fx_offset
= 0;
4453 fixP
->fx_next
= text_fix_root
;
4454 text_fix_root
= fixP
;
4456 * Now make sure we exit from the loop
4462 * Try the next fragment
4464 prev_fragPP
= &fragP
->fr_next
;
4465 fragP
= fragP
->fr_next
;
4468 * Try the next fragment chain
4471 frchainP
= frchainP
->frch_next
;
4474 #endif /* HACK_DEC_C_STARTUP */
4480 * Beginning of vms_write_object_file().
4484 struct vms_obj_state
{
4486 /* Next program section index to use. */
4489 /* Psect index for code. Always ends up #0. */
4492 /* Psect index for initialized static variables. */
4495 /* Psect index for uninitialized static variables. */
4498 /* Number of bytes used for local symbol data. */
4499 int local_initd_data_size
;
4501 /* Dynamic buffer for initialized data. */
4506 #define Psect_Number vms_obj_state.psect_number
4507 #define Text_Psect vms_obj_state.text_psect
4508 #define Data_Psect vms_obj_state.data_psect
4509 #define Bss_Psect vms_obj_state.bss_psect
4510 #define Local_Initd_Data_Size vms_obj_state.local_initd_data_size
4511 #define Data_Segment vms_obj_state.data_segment
4514 #define IS_GXX_VTABLE(symP) (strncmp (S_GET_NAME (symP), "__vt.", 5) == 0)
4517 /* Perform text segment fixups. */
4520 vms_fixup_text_section (text_siz
, text_frag_root
, data_frag_root
)
4522 struct frag
*text_frag_root
;
4523 struct frag
*data_frag_root
;
4525 register fragS
*fragP
;
4526 register struct fix
*fixP
;
4529 /* Scan the text fragments. */
4530 for (fragP
= text_frag_root
; fragP
; fragP
= fragP
->fr_next
)
4532 /* Stop if we get to the data fragments. */
4533 if (fragP
== data_frag_root
)
4535 /* Ignore fragments with no data. */
4536 if ((fragP
->fr_fix
== 0) && (fragP
->fr_var
== 0))
4538 /* Go the the appropriate offset in the Text Psect. */
4539 VMS_Set_Psect (Text_Psect
, fragP
->fr_address
, OBJ_S_C_TIR
);
4540 /* Store the "fixed" part. */
4542 VMS_Store_Immediate_Data (fragP
->fr_literal
,
4545 /* Store the "variable" part. */
4546 if (fragP
->fr_var
&& fragP
->fr_offset
)
4547 VMS_Store_Repeated_Data (fragP
->fr_offset
,
4548 fragP
->fr_literal
+ fragP
->fr_fix
,
4551 } /* text frag loop */
4554 * Now we go through the text segment fixups and generate
4555 * TIR records to fix up addresses within the Text Psect.
4557 for (fixP
= text_fix_root
; fixP
; fixP
= fixP
->fx_next
)
4559 /* We DO handle the case of "Symbol - Symbol" as
4560 long as it is in the same segment. */
4561 if (fixP
->fx_subsy
&& fixP
->fx_addsy
)
4563 /* They need to be in the same segment. */
4564 if (S_GET_RAW_TYPE (fixP
->fx_subsy
) !=
4565 S_GET_RAW_TYPE (fixP
->fx_addsy
))
4566 error ("Fixup data addsy and subsy don't have the same type");
4567 /* And they need to be in one that we can check the psect on. */
4568 if ((S_GET_TYPE (fixP
->fx_addsy
) != N_DATA
) &&
4569 (S_GET_TYPE (fixP
->fx_addsy
) != N_TEXT
))
4570 error ("Fixup data addsy and subsy don't have an appropriate type");
4571 /* This had better not be PC relative! */
4573 error ("Fixup data is erroneously \"pcrel\"");
4574 /* Subtract their values to get the difference. */
4575 dif
= S_GET_VALUE (fixP
->fx_addsy
) - S_GET_VALUE (fixP
->fx_subsy
);
4576 md_number_to_chars (Local
, (valueT
)dif
, fixP
->fx_size
);
4577 /* Now generate the fixup object records;
4578 set the psect and store the data. */
4579 VMS_Set_Psect (Text_Psect
,
4580 fixP
->fx_where
+ fixP
->fx_frag
->fr_address
,
4582 VMS_Store_Immediate_Data (Local
,
4585 continue; /* done with this fixup */
4586 } /* if fx_subsy && fx_addsy */
4587 /* Size will HAVE to be "long". */
4588 if (fixP
->fx_size
!= 4)
4589 error ("Fixup datum is not a longword");
4590 /* Symbol must be "added" (if it is ever
4591 subtracted we can fix this assumption). */
4592 if (fixP
->fx_addsy
== 0)
4593 error ("Fixup datum is not \"fixP->fx_addsy\"");
4594 /* Store the symbol value in a PIC fashion. */
4595 VMS_Store_PIC_Symbol_Reference (fixP
->fx_addsy
,
4599 fixP
->fx_where
+ fixP
->fx_frag
->fr_address
,
4602 * Check for indirect address reference, which has to be fixed up
4603 * (as the linker will screw it up with TIR_S_C_STO_PICR)...
4606 VMS_Fix_Indirect_Reference (Text_Psect
,
4607 fixP
->fx_where
+ fixP
->fx_frag
->fr_address
,
4610 } /* text fix loop */
4614 /* Create a buffer holding the data segment. */
4617 synthesize_data_segment (data_siz
, text_siz
, data_frag_root
)
4618 unsigned data_siz
, text_siz
;
4619 struct frag
*data_frag_root
;
4621 register fragS
*fragP
;
4623 long fill_size
, count
, i
;
4625 /* Allocate the data segment. */
4626 Data_Segment
= (char *) xmalloc (data_siz
);
4627 /* Run through the data fragments, filling in the segment. */
4628 for (fragP
= data_frag_root
; fragP
; fragP
= fragP
->fr_next
)
4630 i
= fragP
->fr_address
- text_siz
;
4632 memcpy (Data_Segment
+ i
, fragP
->fr_literal
, fragP
->fr_fix
);
4635 if ((fill_size
= fragP
->fr_var
) != 0)
4637 fill_literal
= fragP
->fr_literal
+ fragP
->fr_fix
;
4638 for (count
= fragP
->fr_offset
; count
; count
--)
4640 memcpy (Data_Segment
+ i
, fill_literal
, fill_size
);
4644 } /* data frag loop */
4650 /* Perform data segment fixups. */
4653 vms_fixup_data_section (data_siz
, text_siz
)
4654 unsigned data_siz
, text_siz
;
4656 register struct VMS_Symbol
*vsp
;
4657 register struct fix
*fixP
;
4658 register symbolS
*sp
;
4659 addressT fr_address
;
4663 /* Run through all the data symbols and store the data. */
4664 for (vsp
= VMS_Symbols
; vsp
; vsp
= vsp
->Next
)
4666 /* Ignore anything other than data symbols. */
4667 if (S_GET_TYPE (vsp
->Symbol
) != N_DATA
)
4669 /* Set the Psect + Offset. */
4670 VMS_Set_Psect (vsp
->Psect_Index
,
4673 /* Store the data. */
4674 val
= S_GET_VALUE (vsp
->Symbol
);
4675 VMS_Store_Immediate_Data (Data_Segment
+ val
- text_siz
,
4678 } /* N_DATA symbol loop */
4681 * Now we go through the data segment fixups and generate
4682 * TIR records to fix up addresses within the Data Psects.
4684 for (fixP
= data_fix_root
; fixP
; fixP
= fixP
->fx_next
)
4686 /* Find the symbol for the containing datum. */
4687 for (vsp
= VMS_Symbols
; vsp
; vsp
= vsp
->Next
)
4689 /* Only bother with Data symbols. */
4691 if (S_GET_TYPE (sp
) != N_DATA
)
4693 /* Ignore symbol if After fixup. */
4694 val
= S_GET_VALUE (sp
);
4695 fr_address
= fixP
->fx_frag
->fr_address
;
4696 if (val
> fixP
->fx_where
+ fr_address
)
4698 /* See if the datum is here. */
4699 if (val
+ vsp
->Size
<= fixP
->fx_where
+ fr_address
)
4701 /* We DO handle the case of "Symbol - Symbol" as
4702 long as it is in the same segment. */
4703 if (fixP
->fx_subsy
&& fixP
->fx_addsy
)
4705 /* They need to be in the same segment. */
4706 if (S_GET_RAW_TYPE (fixP
->fx_subsy
) !=
4707 S_GET_RAW_TYPE (fixP
->fx_addsy
))
4708 error ("Fixup data addsy and subsy don't have the same type");
4709 /* And they need to be in one that we can check the psect on. */
4710 if ((S_GET_TYPE (fixP
->fx_addsy
) != N_DATA
) &&
4711 (S_GET_TYPE (fixP
->fx_addsy
) != N_TEXT
))
4712 error ("Fixup data addsy and subsy don't have an appropriate type");
4713 /* This had better not be PC relative! */
4715 error ("Fixup data is erroneously \"pcrel\"");
4716 /* Subtract their values to get the difference. */
4717 dif
= S_GET_VALUE (fixP
->fx_addsy
) - S_GET_VALUE (fixP
->fx_subsy
);
4718 md_number_to_chars (Local
, (valueT
)dif
, fixP
->fx_size
);
4720 * Now generate the fixup object records;
4721 * set the psect and store the data.
4723 VMS_Set_Psect (vsp
->Psect_Index
,
4724 fr_address
+ fixP
->fx_where
4725 - val
+ vsp
->Psect_Offset
,
4727 VMS_Store_Immediate_Data (Local
,
4730 break; /* done with this fixup */
4732 /* Size will HAVE to be "long". */
4733 if (fixP
->fx_size
!= 4)
4734 error ("Fixup datum is not a longword");
4735 /* Symbol must be "added" (if it is ever
4736 subtracted we can fix this assumption). */
4737 if (fixP
->fx_addsy
== 0)
4738 error ("Fixup datum is not \"fixP->fx_addsy\"");
4739 /* Store the symbol value in a PIC fashion. */
4740 VMS_Store_PIC_Symbol_Reference (fixP
->fx_addsy
,
4744 fr_address
+ fixP
->fx_where
4745 - val
+ vsp
->Psect_Offset
,
4747 /* Done with this fixup. */
4749 } /* vms_symbol loop */
4751 } /* data fix loop */
4755 /* Define symbols for the linker. */
4758 global_symbol_directory (text_siz
, data_siz
)
4759 unsigned text_siz
, data_siz
;
4761 register fragS
*fragP
;
4762 register symbolS
*sp
;
4763 register struct VMS_Symbol
*vsp
;
4764 int Globalref
, define_as_global_symbol
;
4766 #ifndef gxx_bug_fixed
4768 * The g++ compiler does not write out external references to vtables
4769 * correctly. Check for this and holler if we see it happening.
4770 * If that compiler bug is ever fixed we can remove this.
4771 * (Jun'95: gcc 2.7.0's cc1plus still exhibits this behavior.)
4773 for (sp
= symbol_rootP
; sp
; sp
= symbol_next (sp
))
4774 if (S_GET_RAW_TYPE (sp
) == N_UNDF
&& IS_GXX_VTABLE (sp
))
4776 S_SET_TYPE (sp
, N_UNDF
| N_EXT
);
4777 S_SET_OTHER (sp
, 1);
4778 as_warn ("g++ wrote an extern reference to `%s' as a routine.\n%s",
4780 "I will fix it, but I hope that it was not really a routine.");
4782 #endif /* gxx_bug_fixed */
4785 * Now scan the symbols and emit the appropriate GSD records
4787 for (sp
= symbol_rootP
; sp
; sp
= symbol_next (sp
))
4789 define_as_global_symbol
= 0;
4791 /* Dispatch on symbol type. */
4792 switch (S_GET_RAW_TYPE (sp
))
4795 /* Global uninitialized data. */
4796 case N_UNDF
| N_EXT
:
4797 /* Make a VMS data symbol entry. */
4798 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4800 vsp
->Size
= S_GET_VALUE (sp
);
4801 vsp
->Psect_Index
= Psect_Number
++;
4802 vsp
->Psect_Offset
= 0;
4803 vsp
->Next
= VMS_Symbols
;
4806 /* Make the psect for this data. */
4807 Globalref
= VMS_Psect_Spec (S_GET_NAME (sp
),
4809 S_GET_OTHER (sp
) ? ps_CONST
: ps_COMMON
,
4813 #ifdef NOT_VAX_11_C_COMPATIBLE
4814 define_as_global_symbol
= 1;
4816 /* See if this is an external vtable. We want to help the
4817 linker find these things in libraries, so we make a symbol
4818 reference. This is not compatible with VAX-C usage for
4819 variables, but since vtables are only used internally by
4820 g++, we can get away with this hack. */
4821 define_as_global_symbol
= IS_GXX_VTABLE (sp
);
4825 /* Local uninitialized data. */
4827 /* Make a VMS data symbol entry. */
4828 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4831 vsp
->Psect_Index
= Bss_Psect
;
4832 vsp
->Psect_Offset
= S_GET_VALUE (sp
) - bss_address_frag
.fr_address
;
4833 vsp
->Next
= VMS_Symbols
;
4838 /* Global initialized data. */
4839 case N_DATA
| N_EXT
:
4840 /* Make a VMS data symbol entry. */
4841 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4843 vsp
->Size
= VMS_Initialized_Data_Size (sp
, text_siz
+ data_siz
);
4844 vsp
->Psect_Index
= Psect_Number
++;
4845 vsp
->Psect_Offset
= 0;
4846 vsp
->Next
= VMS_Symbols
;
4849 /* Make its psect. */
4850 Globalref
= VMS_Psect_Spec (S_GET_NAME (sp
),
4852 S_GET_OTHER (sp
) ? ps_CONST
: ps_COMMON
,
4856 #ifdef NOT_VAX_11_C_COMPATIBLE
4857 define_as_global_symbol
= 1;
4859 /* See N_UNDF|N_EXT above for explanation. */
4860 define_as_global_symbol
= IS_GXX_VTABLE (sp
);
4864 /* Local initialized data. */
4867 char *sym_name
= S_GET_NAME (sp
);
4869 /* Always suppress local numeric labels. */
4870 if (sym_name
&& strcmp (sym_name
, FAKE_LABEL_NAME
) == 0)
4873 /* Make a VMS data symbol entry. */
4874 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4876 vsp
->Size
= VMS_Initialized_Data_Size (sp
, text_siz
+ data_siz
);
4877 vsp
->Psect_Index
= Data_Psect
;
4878 vsp
->Psect_Offset
= Local_Initd_Data_Size
;
4879 Local_Initd_Data_Size
+= vsp
->Size
;
4880 vsp
->Next
= VMS_Symbols
;
4886 /* Global Text definition. */
4887 case N_TEXT
| N_EXT
:
4889 unsigned short Entry_Mask
;
4891 /* Get the entry mask. */
4892 fragP
= sp
->sy_frag
;
4893 /* First frag might be empty if we're generating listings.
4894 So skip empty rs_fill frags. */
4895 while (fragP
&& fragP
->fr_type
== rs_fill
&& fragP
->fr_fix
== 0)
4896 fragP
= fragP
->fr_next
;
4898 /* If first frag doesn't contain the data, what do we do?
4899 If it's possibly smaller than two bytes, that would
4900 imply that the entry mask is not stored where we're
4903 If you can find a test case that triggers this, report
4904 it (and tell me what the entry mask field ought to be),
4905 and I'll try to fix it. KR */
4906 if (fragP
->fr_fix
< 2)
4909 Entry_Mask
= (fragP
->fr_literal
[0] & 0x00ff) |
4910 ((fragP
->fr_literal
[1] & 0x00ff) << 8);
4911 /* Define the procedure entry point. */
4912 VMS_Procedure_Entry_Pt (S_GET_NAME (sp
),
4919 /* Local Text definition. */
4921 /* Make a VMS data symbol entry. */
4922 if (Text_Psect
!= -1)
4924 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4927 vsp
->Psect_Index
= Text_Psect
;
4928 vsp
->Psect_Offset
= S_GET_VALUE (sp
);
4929 vsp
->Next
= VMS_Symbols
;
4935 /* Global Reference. */
4937 /* Make a GSD global symbol reference record. */
4938 VMS_Global_Symbol_Spec (S_GET_NAME (sp
),
4944 /* Absolute symbol. */
4947 /* gcc doesn't generate these;
4948 VMS_Emit_Globalvalue handles them though. */
4949 vsp
= (struct VMS_Symbol
*) xmalloc (sizeof *vsp
);
4951 vsp
->Size
= 4; /* always assume 32 bits */
4952 vsp
->Psect_Index
= 0;
4953 vsp
->Psect_Offset
= S_GET_VALUE (sp
);
4954 vsp
->Next
= VMS_Symbols
;
4959 /* Anything else. */
4961 /* Ignore STAB symbols, including .stabs emitted by g++. */
4962 if (S_IS_DEBUG (sp
) || (S_GET_TYPE (sp
) == 22))
4967 as_tsktsk ("unhandled stab type %d", S_GET_TYPE (sp
));
4971 /* Global symbols have different linkage than external variables. */
4972 if (define_as_global_symbol
)
4973 VMS_Global_Symbol_Spec (S_GET_NAME (sp
),
4983 /* Output debugger symbol table information for symbols which
4984 are local to a specific routine. */
4987 local_symbols_DST (s0P
, Current_Routine
)
4988 symbolS
*s0P
, *Current_Routine
;
4991 char *s0P_name
, *pnt0
, *pnt1
;
4993 s0P_name
= S_GET_NAME (s0P
);
4994 if (*s0P_name
++ != '_')
4997 for (s1P
= Current_Routine
; s1P
; s1P
= symbol_next (s1P
))
4999 #if 0 /* redundant; RAW_TYPE != N_FUN suffices */
5000 if (!S_IS_DEBUG (s1P
))
5003 if (S_GET_RAW_TYPE (s1P
) != N_FUN
)
5006 pnt1
= S_GET_NAME (s1P
);
5007 /* We assume the two strings are never exactly equal... */
5008 while (*pnt0
++ == *pnt1
++)
5011 /* Found it if s0P name is exhausted and s1P name has ":F" or ":f" next.
5012 Note: both pointers have advanced one past the non-matching char. */
5013 if ((*pnt1
== 'F' || *pnt1
== 'f') && *--pnt1
== ':' && *--pnt0
== '\0')
5015 Define_Routine (s1P
, 0, Current_Routine
, Text_Psect
);
5022 /* Construct and output the debug symbol table. */
5025 vms_build_DST (text_siz
)
5028 register symbolS
*symbolP
;
5029 symbolS
*Current_Routine
= 0;
5030 struct input_file
*Cur_File
= 0;
5031 offsetT Cur_Offset
= -1;
5032 int Cur_Line_Number
= 0;
5033 int File_Number
= 0;
5034 int Debugger_Offset
= 0;
5039 /* Write the Traceback Begin Module record. */
5040 VMS_TBT_Module_Begin ();
5043 * Output debugging info for global variables and static variables
5044 * that are not specific to one routine. We also need to examine
5045 * all stabs directives, to find the definitions to all of the
5046 * advanced data types, and this is done by VMS_LSYM_Parse. This
5047 * needs to be done before any definitions are output to the object
5048 * file, since there can be forward references in the stabs
5049 * directives. When through with parsing, the text of the stabs
5050 * directive is altered, with the definitions removed, so that later
5051 * passes will see directives as they would be written if the type
5052 * were already defined.
5054 * We also look for files and include files, and make a list of
5055 * them. We examine the source file numbers to establish the actual
5056 * lines that code was generated from, and then generate offsets.
5059 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
5061 /* Only deal with STAB symbols here. */
5062 if (!S_IS_DEBUG (symbolP
))
5065 * Dispatch on STAB type.
5067 switch (S_GET_RAW_TYPE (symbolP
))
5070 dsc
= S_GET_DESC (symbolP
);
5071 if (dsc
> Cur_File
->max_line
)
5072 Cur_File
->max_line
= dsc
;
5073 if (dsc
< Cur_File
->min_line
)
5074 Cur_File
->min_line
= dsc
;
5077 Cur_File
= find_file (symbolP
);
5079 Cur_File
->min_line
= 1;
5082 Cur_File
= find_file (symbolP
);
5085 VMS_GSYM_Parse (symbolP
, Text_Psect
);
5088 VMS_LCSYM_Parse (symbolP
, Text_Psect
);
5090 case N_FUN
: /* For static constant symbols */
5092 VMS_STSYM_Parse (symbolP
, Text_Psect
);
5100 * Now we take a quick sweep through the files and assign offsets
5101 * to each one. This will essentially be the starting line number to
5102 * the debugger for each file. Output the info for the debugger to
5103 * specify the files, and then tell it how many lines to use.
5105 for (Cur_File
= file_root
; Cur_File
; Cur_File
= Cur_File
->next
)
5107 if (Cur_File
->max_line
== 0)
5109 if ((strncmp (Cur_File
->name
, "GNU_GXX_INCLUDE:", 16) == 0) &&
5112 if ((strncmp (Cur_File
->name
, "GNU_CC_INCLUDE:", 15) == 0) &&
5115 /* show a few extra lines at the start of the region selected */
5116 if (Cur_File
->min_line
> 2)
5117 Cur_File
->min_line
-= 2;
5118 Cur_File
->offset
= Debugger_Offset
- Cur_File
->min_line
+ 1;
5119 Debugger_Offset
+= Cur_File
->max_line
- Cur_File
->min_line
+ 1;
5120 if (Cur_File
->same_file_fpnt
)
5122 Cur_File
->file_number
= Cur_File
->same_file_fpnt
->file_number
;
5126 Cur_File
->file_number
= ++File_Number
;
5127 file_available
= VMS_TBT_Source_File (Cur_File
->name
,
5128 Cur_File
->file_number
);
5129 if (!file_available
)
5131 Cur_File
->file_number
= 0;
5136 VMS_TBT_Source_Lines (Cur_File
->file_number
,
5138 Cur_File
->max_line
- Cur_File
->min_line
+ 1);
5140 Cur_File
= (struct input_file
*) NULL
;
5143 * Scan the symbols and write out the routines
5144 * (this makes the assumption that symbols are in
5145 * order of ascending text segment offset)
5147 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
5150 * Deal with text symbols.
5152 if (!S_IS_DEBUG (symbolP
) && S_GET_TYPE (symbolP
) == N_TEXT
)
5155 * Ignore symbols starting with "L", as they are local symbols.
5157 if (*S_GET_NAME (symbolP
) == 'L')
5160 * If there is a routine start defined, terminate it.
5162 if (Current_Routine
)
5163 VMS_TBT_Routine_End (text_siz
, Current_Routine
);
5166 * Check for & skip dummy labels like "gcc_compiled.".
5167 * They're identified by the IN_DEFAULT_SECTION flag.
5169 if ((S_GET_OTHER (symbolP
) & IN_DEFAULT_SECTION
) != 0 &&
5170 S_GET_VALUE (symbolP
) == 0)
5173 * Store the routine begin traceback info.
5175 VMS_TBT_Routine_Begin (symbolP
, Text_Psect
);
5176 Current_Routine
= symbolP
;
5178 * Define symbols local to this routine.
5180 local_symbols_DST (symbolP
, Current_Routine
);
5188 * Deal with STAB symbols.
5190 else if (S_IS_DEBUG (symbolP
))
5193 * Dispatch on STAB type.
5195 switch (S_GET_RAW_TYPE (symbolP
))
5201 /* Offset the line into the correct portion of the file. */
5202 if (Cur_File
->file_number
== 0)
5204 val
= S_GET_VALUE (symbolP
);
5205 /* Sometimes the same offset gets several source lines
5206 assigned to it. We should be selective about which
5207 lines we allow, we should prefer lines that are in
5208 the main source file when debugging inline functions. */
5209 if (val
== Cur_Offset
&& Cur_File
->file_number
!= 1)
5212 /* calculate actual debugger source line */
5213 dsc
= S_GET_DESC (symbolP
) + Cur_File
->offset
;
5214 S_SET_DESC (symbolP
, dsc
);
5216 * Define PC/Line correlation.
5218 if (Cur_Offset
== -1)
5221 * First N_SLINE; set up initial correlation.
5223 VMS_TBT_Line_PC_Correlation (dsc
,
5228 else if ((dsc
- Cur_Line_Number
) <= 0)
5231 * Line delta is not +ve, we need to close the line and
5232 * start a new PC/Line correlation.
5234 VMS_TBT_Line_PC_Correlation (0,
5238 VMS_TBT_Line_PC_Correlation (dsc
,
5246 * Line delta is +ve, all is well.
5248 VMS_TBT_Line_PC_Correlation (dsc
- Cur_Line_Number
,
5253 /* Update the current line/PC info. */
5254 Cur_Line_Number
= dsc
;
5262 /* Remember that we had a source file and emit
5263 the source file debugger record. */
5264 Cur_File
= find_file (symbolP
);
5268 /* We need to make sure that we are really in the actual
5269 source file when we compute the maximum line number.
5270 Otherwise the debugger gets really confused. */
5271 Cur_File
= find_file (symbolP
);
5277 } /* if (IS_DEBUG) */
5281 * If there is a routine start defined, terminate it
5282 * (and the line numbers).
5284 if (Current_Routine
)
5286 /* Terminate the line numbers. */
5287 VMS_TBT_Line_PC_Correlation (0,
5288 text_siz
- S_GET_VALUE (Current_Routine
),
5291 /* Terminate the routine. */
5292 VMS_TBT_Routine_End (text_siz
, Current_Routine
);
5295 /* Write the Traceback End Module TBT record. */
5296 VMS_TBT_Module_End ();
5300 /* Write a VAX/VMS object file (everything else has been done!). */
5303 vms_write_object_file (text_siz
, data_siz
, bss_siz
, text_frag_root
,
5308 fragS
*text_frag_root
;
5309 fragS
*data_frag_root
;
5311 register struct VMS_Symbol
*vsp
;
5314 * Initialize program section indices; values get updated later.
5316 Psect_Number
= 0; /* next Psect Index to use */
5317 Text_Psect
= -1; /* Text Psect Index */
5318 Data_Psect
= -2; /* Data Psect Index JF: Was -1 */
5319 Bss_Psect
= -3; /* Bss Psect Index JF: Was -1 */
5320 /* Initialize other state variables. */
5322 Local_Initd_Data_Size
= 0;
5325 * Create the actual output file and populate it with required
5326 * "module header" information.
5328 Create_VMS_Object_File ();
5329 Write_VMS_MHD_Records ();
5332 * Create the Data segment:
5334 * Since this is REALLY hard to do any other way,
5335 * we actually manufacture the data segment and
5336 * then store the appropriate values out of it.
5337 * We need to generate this early, so that globalvalues
5338 * can be properly emitted.
5341 synthesize_data_segment (data_siz
, text_siz
, data_frag_root
);
5344 /******* Global Symbol Directory *******/
5347 * Emit globalvalues now. We must do this before the text psect is
5348 * defined, or we will get linker warnings about multiply defined
5349 * symbols. All of the globalvalues "reference" psect 0, although
5350 * it really does not have anything to do with it.
5352 VMS_Emit_Globalvalues (text_siz
, data_siz
, Data_Segment
);
5354 * Define the Text Psect
5356 Text_Psect
= Psect_Number
++;
5357 VMS_Psect_Spec ("$code", text_siz
, ps_TEXT
, 0);
5359 * Define the BSS Psect
5363 Bss_Psect
= Psect_Number
++;
5364 VMS_Psect_Spec ("$uninitialized_data", bss_siz
, ps_DATA
, 0);
5367 * Define symbols to the linker.
5369 global_symbol_directory (text_siz
, data_siz
);
5371 * Define the Data Psect
5373 if (data_siz
> 0 && Local_Initd_Data_Size
> 0)
5375 Data_Psect
= Psect_Number
++;
5376 VMS_Psect_Spec ("$data", Local_Initd_Data_Size
, ps_DATA
, 0);
5378 * Local initialized data (N_DATA) symbols need to be updated to the
5379 * proper value of Data_Psect now that it's actually been defined.
5380 * (A dummy value was used in global_symbol_directory() above.)
5382 for (vsp
= VMS_Symbols
; vsp
; vsp
= vsp
->Next
)
5383 if (vsp
->Psect_Index
< 0 && S_GET_RAW_TYPE (vsp
->Symbol
) == N_DATA
)
5384 vsp
->Psect_Index
= Data_Psect
;
5388 /******* Text Information and Relocation Records *******/
5391 * Write the text segment data
5394 vms_fixup_text_section (text_siz
, text_frag_root
, data_frag_root
);
5396 * Write the data segment data, then discard it.
5400 vms_fixup_data_section (data_siz
, text_siz
);
5401 free (Data_Segment
), Data_Segment
= 0;
5405 /******* Debugger Symbol Table Records *******/
5407 vms_build_DST (text_siz
);
5410 /******* Wrap things up *******/
5413 * Write the End Of Module record
5415 if (Entry_Point_Symbol
)
5416 Write_VMS_EOM_Record (Text_Psect
, S_GET_VALUE (Entry_Point_Symbol
));
5418 Write_VMS_EOM_Record (-1, (valueT
) 0);
5421 * All done, close the object file
5423 Close_VMS_Object_File ();
5426 /* end of obj-vms.c */