1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1988, 1994, 1995, 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #define TARGET_EXECUTABLE_SUFFIX ".exe"
22 #define TARGET_OBJECT_SUFFIX ".obj"
24 /* This enables certain macros in vax.h, which will make an indirect
25 reference to an external symbol an invalid address. This needs to be
26 defined before we include vax.h, since it determines which macros
27 are used for GO_IF_*. */
29 #define NO_EXTERNAL_INDIRECT_ADDRESS
40 #undef CALL_USED_REGISTERS
41 #undef STARTING_FRAME_OFFSET
43 /* Predefine this in CPP because VMS limits the size of command options
44 and GNU CPP is not used on VMS except with GNU C. */
45 #define CPP_PREDEFINES \
46 "-Dvax -Dvms -DVMS -D__vax__ -D__vms__ -D__VMS__\
47 -D__GNUC__=2 -D__GNUC_MINOR__=7 -Asystem=vms -Acpu=vax -Amachine=vax"
49 /* These match the definitions used in VAXCRTL, the VMS C run-time library */
51 #define SIZE_TYPE "unsigned int"
52 #define PTRDIFF_TYPE "int"
53 #define WCHAR_TYPE "unsigned int"
54 #define WCHAR_TYPE_SIZE 32 /* in bits */
56 /* Use memcpy for structure copying, and so forth. */
57 #define TARGET_MEM_FUNCTIONS
59 /* Strictly speaking, VMS does not use DBX at all, but the interpreter built
60 into gas only speaks straight DBX. */
62 #define DEFAULT_GDB_EXTENSIONS 0
64 #define TARGET_DEFAULT 1
65 #define TARGET_NAME "vax/vms"
67 /* The structure return address arrives as an "argument" on VMS. */
68 #undef STRUCT_VALUE_REGNUM
69 #define STRUCT_VALUE 0
70 #undef PCC_STATIC_STRUCT_RETURN
72 #define CALL_USED_REGISTERS {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}
74 /* The run-time library routine VAXC$ESTABLISH (necessary when mixing
75 VMS exception handling and setjmp/longjmp in the same program) requires
76 that a hidden automatic variable at the top of the stack be reserved
77 for its use. We accomplish this by simply adding 4 bytes to the local
78 stack for all functions, and making sure that normal local variables
79 are 4 bytes lower on the stack then they would otherwise have been. */
81 #define STARTING_FRAME_OFFSET -4
83 /* This macro definition sets up a default value for `main' to return. */
84 #define DEFAULT_MAIN_RETURN c_expand_return (integer_one_node)
86 /* This makes use of a hook in varasm.c to mark all external variables
87 for us. We use this to make sure that external variables are correctly
88 addressed. Under VMS there is some brain damage in the linker that requires
91 #define ENCODE_SECTION_INFO(decl, FIRST) \
92 if (DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) \
93 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
95 /* This is how to output a command to make the user-level label named NAME
96 defined for reference from other files. */
98 #undef ASM_GLOBALIZE_LABEL
99 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
100 do { fputs (".globl ", FILE); \
101 assemble_name (FILE, NAME); \
102 fputs ("\n", FILE); \
103 vms_check_external (NULL_TREE, NAME, 0); \
106 /* Under VMS we write the actual size of the storage to be allocated even
107 though the symbol is external. Although it is possible to give external
108 symbols a size of 0 (as unix does), the VMS linker does not make the
109 distinction between a variable definition and an external reference of a
110 variable, and thus the linker will not complain about a missing definition.
111 If we followed the unix example of giving external symbols a size of
112 zero, you tried to link a program where a given variable was externally
113 defined but none of the object modules contained a non-extern definition,
114 the linker would allocate 0 bytes for the variable, and any attempt to
115 use that variable would use the storage allocated to some other variable.
117 We must also select either const_section or data_section: this will indicate
118 whether or not the variable will get the readonly bit set. Since the
119 VMS linker does not distinguish between a variable's definition and an
120 external reference, all usages of a given variable must have the readonly
121 bit set the same way, or the linker will get confused and give warning
124 /* We used to round the size up to a multiple of 4,
125 but that causes linker errors sometimes when the variable was initialized
126 since the size of its definition was not likewise rounded up. */
128 /* Note: the original ASM_OUTPUT_EXTERNAL code has been moved into
129 vms_check_external and vms_flush_pending_externals. */
131 #define ASM_OUTPUT_EXTERNAL(FILE,DECL,NAME) \
132 { if (DECL_INITIAL (DECL) == 0 && TREE_CODE (DECL) != FUNCTION_DECL) \
133 vms_check_external ((DECL), (NAME), 1); \
136 /* ASM_OUTPUT_EXTERNAL will have wait until after an initializer is
137 completed in order to switch sections for an external object, so
138 use the DECLARE_OBJECT hooks to manage deferred declarations. */
140 /* This is the default action for ASM_DECLARE_OBJECT_NAME, but if it
141 is explicitly defined, then ASM_FINISH_DECLARE_OBJECT will be used. */
143 #define ASM_DECLARE_OBJECT_NAME(ASM_OUT_FILE,NAME,DECL) \
144 ASM_OUTPUT_LABEL ((ASM_OUT_FILE), (NAME))
146 /* We don't need to do anything special to finish the current object, but it
147 should now be safe to output any deferred external global declarations. */
149 #define ASM_FINISH_DECLARE_OBJECT(FILE,DECL,TOPLVL,ATEND) \
150 vms_flush_pending_externals(FILE)
152 /* Anything still pending must be flushed at the very end. */
154 #define ASM_FILE_END(STREAM) \
155 vms_flush_pending_externals(STREAM)
157 /* Here we redefine ASM_OUTPUT_COMMON to select the data_section or the
158 const_section before writing the ".const" assembler directive.
159 If we were specifying a size of zero for external variables, we would
160 not have to select a section, since the assembler can assume that
161 when the size > 0, the storage is for a non-external, uninitialized
162 variable (for which a "const" declaration would be senseless),
163 and the assembler can make the storage read/write.
165 Since the ".const" directive specifies the actual size of the storage used
166 for both external and non-external variables, the assembler cannot
167 make this assumption, and thus it has no way of deciding if storage should
168 be read/write or read-only. To resolve this, we give the assembler some
169 assistance, in the form of a ".const" or a ".data" directive.
171 Under GCC 1.40, external variables were declared with a size of zero.
172 The GNU assembler, GAS, will recognize the "-2" switch when built for VMS;
173 when compiling programs with GCC 2.n this switch should be used or the
174 assembler will not give the read-only attribute to external constants.
175 Failure to use this switch will result in linker warning messages about
176 mismatched psect attributes. */
178 #undef ASM_OUTPUT_COMMON
180 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
181 ( ((TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl)) \
182 ? (const_section (), 0) : (data_section (), 0)), \
183 fputs (".comm ", (FILE)), \
184 assemble_name ((FILE), (NAME)), \
185 fprintf ((FILE), ",%u\n", (SIZE)))
187 /* We define this to prevent the name mangler from putting dollar signs into
188 function names. This isn't really needed, but it has been here for
189 some time and removing it would cause the object files generated by the
190 compiler to be incompatible with the object files from a compiler that
191 had this defined. Since it does no harm, we leave it in. */
193 #define NO_DOLLAR_IN_LABEL
195 /* Add a "const" section. This is viewed by the assembler as being nearly
196 the same as the "data" section, with the only difference being that a
197 flag is set for variables declared while in the const section. This
198 flag is used to determine whether or not the read/write bit should be
199 set in the Psect definition. */
201 #define EXTRA_SECTIONS in_const
203 #define EXTRA_SECTION_FUNCTIONS \
207 if (in_section != in_const) { \
208 fprintf(asm_out_file,".const\n"); \
209 in_section = in_const; \
213 /* This macro contains the logic to decide which section a variable
214 should be stored in. Static constant variables go in the text_section,
215 non-const variables go in the data_section, and non-static const
216 variables go in the const_section.
218 Since this macro is used in a number of places, we must also be able
219 to decide where to place string constants. */
221 #define SELECT_SECTION(T,RELOC,ALIGN) \
223 if (TREE_CODE (T) == VAR_DECL) \
225 if (TREE_READONLY (T) && ! TREE_THIS_VOLATILE (T) \
226 && DECL_INITIAL (T) \
227 && (DECL_INITIAL (T) == error_mark_node \
228 || TREE_CONSTANT (DECL_INITIAL (T)))) \
230 if (TREE_PUBLIC (T)) \
238 if (TREE_CODE_CLASS (TREE_CODE (T)) == 'c') \
240 if ((TREE_CODE (T) == STRING_CST && flag_writable_strings)) \
247 /* This is used by a hook in varasm.c to write the assembler directives
248 that are needed to tell the startup code which constructors need to
251 #define TARGET_ASM_CONSTRUCTOR vms_asm_out_constructor
252 #define TARGET_ASM_DESTRUCTOR vms_asm_out_destructor
254 /* The following definitions are used in libgcc2.c with the __main
255 function. The _SHR symbol is used when the sharable image library
256 for the C++ library is used - this is picked up automatically by the linker
257 and this symbol points to the start of __CTOR_LIST__ from the C++ library.
258 If the C++ library is not used, then __CTOR_LIST_SHR__ occurs just after
259 __CTOR_LIST__, and essentially points to the same list as __CTOR_LIST. */
263 #define __CTOR_LIST__ __gxx_init_0
264 #define __CTOR_LIST_END__ __gxx_init_2
266 #define __CTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_init_0_shr
267 #define __CTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_init_2_shr
269 #define DO_GLOBAL_CTORS_BODY \
272 extern func_ptr __CTOR_LIST__[1], __CTOR_LIST_END__[1]; \
273 extern func_ptr __CTOR_LIST_SHR__[1], __CTOR_LIST_SHR_END__[1]; \
274 if (&__CTOR_LIST_SHR__[0] != &__CTOR_LIST__[1]) \
275 for (p = __CTOR_LIST_SHR__ + 1; p < __CTOR_LIST_SHR_END__ ; p++ ) \
277 for (p = __CTOR_LIST__ + 1; p < __CTOR_LIST_END__ ; p++ ) \
279 do { /* arrange for `return' from main() to pass through exit() */ \
281 int *callers_caller_fp = (int *) __builtin_frame_address (3); \
282 register int retval asm ("r0"); \
283 callers_caller_fp[4] = (int) && foo; \
284 break; /* out of do-while block */ \
290 #define __DTOR_LIST__ __gxx_clean_0
291 #define __DTOR_LIST_END__ __gxx_clean_2
293 #define __DTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_clean_0_shr
294 #define __DTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_clean_2_shr
296 #define DO_GLOBAL_DTORS_BODY \
299 extern func_ptr __DTOR_LIST__[1], __DTOR_LIST_END__[1]; \
300 extern func_ptr __DTOR_LIST_SHR__[1], __DTOR_LIST_SHR_END__[1]; \
301 for (p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__ ; p++ ) \
303 if (&__DTOR_LIST_SHR__[0] != &__DTOR_LIST__[1]) \
304 for (p = __DTOR_LIST_SHR__ + 1; p < __DTOR_LIST_SHR_END__ ; p++ ) \
310 /* Specify the list of include file directories. */
311 #define INCLUDE_DEFAULTS \
313 { "GNU_GXX_INCLUDE:", "G++", 1, 1 }, \
314 { "GNU_CC_INCLUDE:", "GCC", 0, 0 }, /* GNU includes */ \
315 { "SYS$SYSROOT:[SYSLIB.]", 0, 0, 0 }, /* VAX-11 "C" includes */ \
316 { ".", 0, 0, 1 }, /* Make normal VMS filespecs work. */ \