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