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