|
|
1.1 root 1: /* Output variables, constants and external declarations, for GNU compiler.
2: Copyright (C) 1988 Free Software Foundation, Inc.
3:
4: This file is part of GNU CC.
5:
6: GNU CC 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)
9: any later version.
10:
11: GNU CC 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.
15:
16: You should have received a copy of the GNU General Public License
17: along with GNU CC; see the file COPYING. If not, write to
18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19:
20: /* This enables certain macros in vax.h, which will make an indirect
21: reference to an external symbol an invalid address. This needs to be
22: defined before we include vax.h, since it determines which macros
23: are used for GO_IF_*. */
24:
25: #define NO_EXTERNAL_INDIRECT_ADDRESS
26:
27: #include "vax.h"
28:
29: #undef LIB_SPEC
30: #undef CPP_PREDEFINES
31: #undef TARGET_VERSION
32: #undef TARGET_DEFAULT
33: #undef CALL_USED_REGISTERS
34: #undef MAYBE_VMS_FUNCTION_PROLOGUE
35:
36: /* Predefine this in CPP because VMS limits the size of command options
37: and GNU CPP is not used on VMS except with GNU C. */
1.1.1.2 ! root 38: #define CPP_PREDEFINES "-Dvax -Dvms -DVMS -D__GNUC__=2"
! 39:
! 40: /* These match the definitions used in VAXCRTL, the VMS C run-time library */
! 41:
! 42: #define SIZE_TYPE "unsigned int"
! 43: #define PTRDIFF_TYPE "int"
! 44: #define WCHAR_TYPE "unsigned int"
! 45:
! 46: /* Use memcpy for structure copying, and so forth. */
! 47: #define TARGET_MEM_FUNCTIONS
1.1 root 48:
49: /* Strictly speaking, VMS does not use DBX at all, but the interpreter built
50: into gas only speaks straight DBX. */
51:
52: #define DEFAULT_GDB_EXTENSIONS 0
53:
54: /* By default, allow $ to be part of an identifier. */
55: #define DOLLARS_IN_IDENTIFIERS 2
56:
57: #define TARGET_DEFAULT 1
58: #define TARGET_VERSION fprintf (stderr, " (vax vms)");
59:
60: #define CALL_USED_REGISTERS {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}
61:
62: #define __MAIN_NAME " main ("
63: /*
64: * The MAYBE_VMS_FUNCTION_PROLOGUE macro works for both gcc and g++. It
65: * first checks to see if the current routine is "main", which will only
66: * happen for GCC, and add the jsb if it is. If is not the case then try and
67: * see if __MAIN_NAME is part of current_function_name, which will only happen
68: * if we are running g++, and add the jsb if it is. In gcc there should never
69: * be a space in the function name, and in g++ there is always a "(" in the
70: * function name, thus there should never be any confusion.
71: */
72: #define MAYBE_VMS_FUNCTION_PROLOGUE(FILE) \
73: { extern char *current_function_name; \
74: if (!strcmp ("main", current_function_name)) \
75: fprintf(FILE, "\tjsb _c$main_args\n"); \
76: else { \
77: char *p = current_function_name; \
78: while (*p != '\0') \
79: if (*p == *__MAIN_NAME) \
80: if (strncmp(p, __MAIN_NAME, (sizeof __MAIN_NAME)-1) == 0) {\
81: fprintf(FILE, "\tjsb _c$main_args\n");\
82: break; \
83: } else \
84: p++; \
85: else \
86: p++; \
87: }; \
88: }
89:
90: /* This macro definition sets up a default value for `main' to return. */
91: #define DEFAULT_MAIN_RETURN c_expand_return (integer_one_node)
92:
93: /* This makes use of a hook in varasm.c to mark all external variables
94: for us. We use this to make sure that external variables are correctly
95: addressed. Under VMS there is some brain damage in the linker that requires
96: us to do this. */
97:
98: #define ENCODE_SECTION_INFO(decl) \
99: if (TREE_EXTERNAL (decl) && TREE_PUBLIC (decl)) \
100: SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
101:
102: /* Under VMS we write the actual size of the storage to be allocated even
103: though the symbol is external. Although it is possible to give external
104: symbols a size of 0 (as unix does), the VMS linker does not make the
105: distinction between a variable definition and an external reference of a
106: variable, and thus the linker will not complain about a missing definition.
107: If we followed the unix example of giving external symbols a size of
108: zero, you tried to link a program where a given variable was externally
109: defined but none of the object modules contained a non-extern definition,
110: the linker would allocate 0 bytes for the variable, and any attempt to
111: use that variable would use the storage allocated to some other variable.
112:
113: We must also select either const_section or data_section: this will indicate
114: whether or not the variable will get the readonly bit set. Since the
115: VMS linker does not distinguish between a variable's definition and an
116: external reference, all usages of a given variable must have the readonly
117: bit set the same way, or the linker will get confused and give warning
118: messages. */
119:
120: /* We used to round the size up to a multiple of 4,
121: but that causes linker errors sometimes when the variable was initialized
122: since the size of its definition was not likewise rounded up. */
123:
124: #define ASM_OUTPUT_EXTERNAL(FILE,DECL,NAME) \
125: { if (DECL_INITIAL (DECL) == 0 && TREE_CODE (DECL) != FUNCTION_DECL) \
126: { \
127: if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl)) \
128: const_section (); \
129: else \
130: data_section (); \
131: fputs (".comm ", (FILE)); \
132: assemble_name ((FILE), (NAME)); \
133: if (DECL_SIZE (DECL) == 0) \
134: fprintf ((FILE), ",0\n"); \
135: else \
136: { \
137: tree size_tree; \
138: size_tree = size_binop (CEIL_DIV_EXPR, \
139: DECL_SIZE (DECL), size_int (BITS_PER_UNIT)); \
140: fprintf ((FILE), ",%d\n", TREE_INT_CST_LOW (size_tree)); \
141: } \
142: } \
143: }
144:
145: /* Here we redefine ASM_OUTPUT_COMMON to select the data_section or the
146: const_section before writing the ".const" assembler directive.
147: If we were specifying a size of zero for external variables, we would
148: not have to select a section, since the assembler can assume that
149: when the size > 0, the storage is for a non-external, uninitialized
150: variable (for which a "const" declaration would be senseless),
151: and the assembler can make the storage read/write.
152:
153: Since the ".const" directive specifies the actual size of the storage used
154: for both external and non-external variables, the assembler cannot
155: make this assumption, and thus it has no way of deciding if storage should
156: be read/write or read-only. To resolve this, we give the assembler some
157: assistance, in the form of a ".const" or a ".data" directive.
158:
159: Under GCC 1.40, external variables were declared with a size of zero.
160: The GNU assembler, GAS, will recognize the "-2" switch when built for VMS;
161: when compiling programs with GCC 2.n this switch should be used or the
162: assembler will not give the read-only attribute to external constants.
163: Failure to use this switch will result in linker warning messages about
164: mismatched psect attributes. */
165:
166: #undef ASM_OUTPUT_COMMON
167:
168: #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
169: ( ((TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl)) \
170: ? (const_section (), 0) : (data_section (), 0)), \
171: fputs (".comm ", (FILE)), \
172: assemble_name ((FILE), (NAME)), \
1.1.1.2 ! root 173: fprintf ((FILE), ",%u\n", (SIZE)))
1.1 root 174:
175: /* We define this to prevent the name mangler from putting dollar signs into
176: function names. This isn't really needed, but it has been here for
177: some time and removing it would cause the object files generated by the
178: compiler to be incompatible with the object files from a compiler that
179: had this defined. Since it does no harm, we leave it in. */
180:
181: #define NO_DOLLAR_IN_LABEL
182:
1.1.1.2 ! root 183: /* Add a "const" section. This is viewed by the assembler as being nearly
1.1 root 184: the same as the "data" section, with the only difference being that a
185: flag is set for variables declared while in the const section. This
186: flag is used to determine whether or not the read/write bit should be
187: set in the Psect definition. */
188:
189: #define EXTRA_SECTIONS in_const
190:
191: #define EXTRA_SECTION_FUNCTIONS \
192: void \
193: const_section () \
194: { \
195: if (in_section != in_const) { \
196: fprintf(asm_out_file,".const\n"); \
197: in_section = in_const; \
198: } \
199: }
200:
201: /* This macro contains the logic to decide which section a variable
202: should be stored in. Static constant variables go in the text_section,
203: non-const variables go in the data_section, and non-static const
204: variables go in the const_section.
205:
206: Since this macro is used in a number of places, we must also be able
207: to decide where to place string constants. */
208:
209: #define SELECT_SECTION(T,RELOC) \
210: { \
211: if (TREE_CODE (T) == VAR_DECL) \
212: { \
213: if (TREE_READONLY (T) && ! TREE_THIS_VOLATILE (T)) \
214: { \
215: if (TREE_PUBLIC (T)) \
216: const_section (); \
217: else \
218: text_section (); \
219: } \
220: else \
221: data_section (); \
222: } \
223: if (*tree_code_type[(int) TREE_CODE (T)] == 'c') \
224: { \
225: if ((TREE_CODE (T) == STRING_CST && flag_writable_strings)) \
226: data_section (); \
227: else \
228: text_section (); \
229: } \
230: }
231:
232: /* This is used by a hook in varasm.c to write the assembler directives
233: that are needed to tell the startup code which constructors need to
234: be run. */
235:
236: #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
237: { \
238: fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_init_1\n"); \
239: data_section(); \
240: fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_init_1:\n\t.long\t"); \
241: assemble_name ((FILE), (NAME)); \
242: fputc ('\n', (FILE)); \
243: }
244:
245: /* This is used by a hook in varasm.c to write the assembler directives
246: that are needed to tell the startup code which destructors need to
247: be run. */
248:
249: #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
250: { \
251: fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_clean_1\n"); \
252: data_section(); \
253: fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_clean_1:\n\t.long\t");\
254: assemble_name ((FILE), (NAME)); \
255: fputc ('\n', (FILE)); \
256: }
257:
258: /* The following definitions are used in libgcc2.c with the __main
259: function. The _SHR symbol is used when the sharable image library
260: for libg++ is used - this is picked up automatically by the linker
261: and this symbol points to the start of the __CTOR_LIST__ from libg++.
262: If libg++ is not being used, then __CTOR_LIST_SHR__ occurs just after
263: __CTOR_LIST__, and essentially points to the same list as __CTOR_LIST. */
264:
265: #ifdef L__main
266:
267: #define __CTOR_LIST__ __gxx_init_0
268: #define __CTOR_LIST_END__ __gxx_init_2
269:
270: #define __CTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_init_0_shr
271: #define __CTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_init_2_shr
272:
273: #define DO_GLOBAL_CTORS_BODY \
274: do { \
275: func_ptr *p; \
276: extern func_ptr __CTOR_LIST__[1]; \
277: extern func_ptr __CTOR_LIST_END__[1]; \
278: extern func_ptr __CTOR_LIST_SHR__[1]; \
279: extern func_ptr __CTOR_LIST_SHR_END__[1]; \
280: if( &__CTOR_LIST_SHR__[0] != &__CTOR_LIST__[1]) \
281: for (p = __CTOR_LIST_SHR__ + 1; p < __CTOR_LIST_SHR_END__ ; p++ ) \
282: if (*p) (*p) (); \
283: for (p = __CTOR_LIST__ + 1; p < __CTOR_LIST_END__ ; p++ ) \
284: if (*p) (*p) (); \
285: atexit (__do_global_dtors); \
286: { \
287: __label__ foo; \
288: int *callers_caller_fp = (int *) __builtin_frame_address (3); \
289: register int retval asm ("r0"); \
290: callers_caller_fp[4] = (int) && foo; \
291: return; \
292: foo: \
293: exit (retval); \
294: } \
295: } while (0)
296:
297: #define __DTOR_LIST__ __gxx_clean_0
298: #define __DTOR_LIST_END__ __gxx_clean_2
299:
300: #define __DTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_clean_0_shr
301: #define __DTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_clean_2_shr
302:
303: #define DO_GLOBAL_DTORS_BODY \
304: do { \
305: func_ptr *p; \
306: extern func_ptr __DTOR_LIST__[1]; \
307: extern func_ptr __DTOR_LIST_END__[1]; \
308: extern func_ptr __DTOR_LIST_SHR__[1]; \
309: extern func_ptr __DTOR_LIST_SHR_END__[1]; \
310: for (p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__ ; p++ ) \
311: if (*p) (*p) (); \
312: if( &__DTOR_LIST_SHR__[0] != &__DTOR_LIST__[1]) \
313: for (p = __DTOR_LIST_SHR__ + 1; p < __DTOR_LIST_SHR_END__ ; p++ ) \
314: if (*p) (*p) (); \
315: } while (0)
316:
317: #endif /* L__main */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.