1 /* Output variables, constants and external declarations, for GNU compiler. 2 Copyright (C) 1988, 1994, 1995, 1996, 1997, 1999, 2001, 2002 3 Free Software Foundation, Inc. 4 5 This file is part of GNU CC. 6 7 GNU CC is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2, or (at your option) 10 any later version. 11 12 GNU CC is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GNU CC; see the file COPYING. If not, write to 19 the Free Software Foundation, 59 Temple Place - Suite 330, 20 Boston, MA 02111-1307, USA. */ 21 22 #define TARGET_EXECUTABLE_SUFFIX ".exe" 23 #define TARGET_OBJECT_SUFFIX ".obj" 24 25 /* This enables certain macros in vax.h, which will make an indirect 26 reference to an external symbol an invalid address. This needs to be 27 defined before we include vax.h, since it determines which macros 28 are used for GO_IF_*. */ 29 30 #define NO_EXTERNAL_INDIRECT_ADDRESS 31 32 #include "vax/vax.h" 33 34 #undef VMS_TARGET 35 #define VMS_TARGET 1 36 37 #undef LIB_SPEC 38 #undef TARGET_NAME 39 #undef TARGET_DEFAULT 40 #undef CALL_USED_REGISTERS 41 #undef STARTING_FRAME_OFFSET 42 43 #define TARGET_OS_CPP_BUILTINS() \ 44 do \ 45 { \ 46 builtin_define_std ("vms"); \ 47 builtin_define_std ("VMS"); \ 48 builtin_assert ("system=vms"); \ 49 \ 50 builtin_define_std ("vax"); \ 51 if (TARGET_G_FLOAT) \ 52 builtin_define_std ("GFLOAT"); \ 53 } \ 54 while (0) 55 56 /* These match the definitions used in VAXCRTL, the VMS C run-time library */ 57 58 #define SIZE_TYPE "unsigned int" 59 #define PTRDIFF_TYPE "int" 60 #define WCHAR_TYPE "unsigned int" 61 #define WCHAR_TYPE_SIZE 32 /* in bits */ 62 63 /* Use memcpy for structure copying, and so forth. */ 64 #define TARGET_MEM_FUNCTIONS 65 66 /* Strictly speaking, VMS does not use DBX at all, but the interpreter built 67 into gas only speaks straight DBX. */ 68 69 #define DEFAULT_GDB_EXTENSIONS 0 70 71 #define TARGET_DEFAULT 1 72 #define TARGET_NAME "vax/vms" 73 74 /* The structure return address arrives as an "argument" on VMS. */ 75 #undef STRUCT_VALUE_REGNUM 76 #define STRUCT_VALUE 0 77 #undef PCC_STATIC_STRUCT_RETURN 78 79 #define CALL_USED_REGISTERS {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1} 80 81 /* The run-time library routine VAXC$ESTABLISH (necessary when mixing 82 VMS exception handling and setjmp/longjmp in the same program) requires 83 that a hidden automatic variable at the top of the stack be reserved 84 for its use. We accomplish this by simply adding 4 bytes to the local 85 stack for all functions, and making sure that normal local variables 86 are 4 bytes lower on the stack then they would otherwise have been. */ 87 88 #define STARTING_FRAME_OFFSET -4 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 /* Globalizing directive for a label. */ 94 #define GLOBAL_ASM_OP ".globl " 95 96 /* Under VMS we write the actual size of the storage to be allocated even 97 though the symbol is external. Although it is possible to give external 98 symbols a size of 0 (as unix does), the VMS linker does not make the 99 distinction between a variable definition and an external reference of a 100 variable, and thus the linker will not complain about a missing definition. 101 If we followed the unix example of giving external symbols a size of 102 zero, you tried to link a program where a given variable was externally 103 defined but none of the object modules contained a non-extern definition, 104 the linker would allocate 0 bytes for the variable, and any attempt to 105 use that variable would use the storage allocated to some other variable. 106 107 We must also select either const_section or data_section: this will indicate 108 whether or not the variable will get the readonly bit set. Since the 109 VMS linker does not distinguish between a variable's definition and an 110 external reference, all usages of a given variable must have the readonly 111 bit set the same way, or the linker will get confused and give warning 112 messages. */ 113 114 /* We used to round the size up to a multiple of 4, 115 but that causes linker errors sometimes when the variable was initialized 116 since the size of its definition was not likewise rounded up. */ 117 118 /* Note: the original ASM_OUTPUT_EXTERNAL code has been moved into 119 vms_check_external and vms_flush_pending_externals. */ 120 121 #define ASM_OUTPUT_EXTERNAL(FILE,DECL,NAME) \ 122 { if (DECL_INITIAL (DECL) == 0 && TREE_CODE (DECL) != FUNCTION_DECL) \ 123 vms_check_external ((DECL), (NAME), 1); \ 124 } 125 126 /* ASM_OUTPUT_EXTERNAL will have wait until after an initializer is 127 completed in order to switch sections for an external object, so 128 use the DECLARE_OBJECT hooks to manage deferred declarations. */ 129 130 /* This is the default action for ASM_DECLARE_OBJECT_NAME, but if it 131 is explicitly defined, then ASM_FINISH_DECLARE_OBJECT will be used. */ 132 133 #define ASM_DECLARE_OBJECT_NAME(ASM_OUT_FILE,NAME,DECL) \ 134 ASM_OUTPUT_LABEL ((ASM_OUT_FILE), (NAME)) 135 136 /* We don't need to do anything special to finish the current object, but it 137 should now be safe to output any deferred external global declarations. */ 138 139 #define ASM_FINISH_DECLARE_OBJECT(FILE,DECL,TOPLVL,ATEND) \ 140 vms_flush_pending_externals(FILE) 141 142 /* Anything still pending must be flushed at the very end. */ 143 144 #define ASM_FILE_END(STREAM) \ 145 vms_flush_pending_externals(STREAM) 146 147 /* Here we redefine ASM_OUTPUT_COMMON to select the data_section or the 148 const_section before writing the ".const" assembler directive. 149 If we were specifying a size of zero for external variables, we would 150 not have to select a section, since the assembler can assume that 151 when the size > 0, the storage is for a non-external, uninitialized 152 variable (for which a "const" declaration would be senseless), 153 and the assembler can make the storage read/write. 154 155 Since the ".const" directive specifies the actual size of the storage used 156 for both external and non-external variables, the assembler cannot 157 make this assumption, and thus it has no way of deciding if storage should 158 be read/write or read-only. To resolve this, we give the assembler some 159 assistance, in the form of a ".const" or a ".data" directive. 160 161 Under GCC 1.40, external variables were declared with a size of zero. 162 The GNU assembler, GAS, will recognize the "-2" switch when built for VMS; 163 when compiling programs with GCC 2.n this switch should be used or the 164 assembler will not give the read-only attribute to external constants. 165 Failure to use this switch will result in linker warning messages about 166 mismatched psect attributes. */ 167 168 #undef ASM_OUTPUT_COMMON 169 170 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \ 171 ( ((TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl)) \ 172 ? (const_section (), 0) : (data_section (), 0)), \ 173 fputs (".comm ", (FILE)), \ 174 assemble_name ((FILE), (NAME)), \ 175 fprintf ((FILE), ",%u\n", (SIZE))) 176 177 /* We define this to prevent the name mangler from putting dollar signs into 178 function names. This isn't really needed, but it has been here for 179 some time and removing it would cause the object files generated by the 180 compiler to be incompatible with the object files from a compiler that 181 had this defined. Since it does no harm, we leave it in. */ 182 183 #define NO_DOLLAR_IN_LABEL 184 185 /* Add a "const" section. This is viewed by the assembler as being nearly 186 the same as the "data" section, with the only difference being that a 187 flag is set for variables declared while in the const section. This 188 flag is used to determine whether or not the read/write bit should be 189 set in the Psect definition. */ 190 191 #define EXTRA_SECTIONS in_const 192 193 #define EXTRA_SECTION_FUNCTIONS \ 194 void \ 195 const_section () \ 196 { \ 197 if (in_section != in_const) { \ 198 fprintf(asm_out_file,".const\n"); \ 199 in_section = in_const; \ 200 } \ 201 } 202 203 /* This is used by a hook in varasm.c to write the assembler directives 204 that are needed to tell the startup code which constructors need to 205 be run. */ 206 207 #define TARGET_ASM_CONSTRUCTOR vms_asm_out_constructor 208 #define TARGET_ASM_DESTRUCTOR vms_asm_out_destructor 209 210 /* The following definitions are used in libgcc2.c with the __main 211 function. The _SHR symbol is used when the sharable image library 212 for the C++ library is used - this is picked up automatically by the linker 213 and this symbol points to the start of __CTOR_LIST__ from the C++ library. 214 If the C++ library is not used, then __CTOR_LIST_SHR__ occurs just after 215 __CTOR_LIST__, and essentially points to the same list as __CTOR_LIST. */ 216 217 #ifdef L__main 218 219 #define __CTOR_LIST__ __gxx_init_0 220 #define __CTOR_LIST_END__ __gxx_init_2 221 222 #define __CTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_init_0_shr 223 #define __CTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_init_2_shr 224 225 #define DO_GLOBAL_CTORS_BODY \ 226 do { \ 227 func_ptr *p; \ 228 extern func_ptr __CTOR_LIST__[1], __CTOR_LIST_END__[1]; \ 229 extern func_ptr __CTOR_LIST_SHR__[1], __CTOR_LIST_SHR_END__[1]; \ 230 if (&__CTOR_LIST_SHR__[0] != &__CTOR_LIST__[1]) \ 231 for (p = __CTOR_LIST_SHR__ + 1; p < __CTOR_LIST_SHR_END__ ; p++ ) \ 232 if (*p) (*p) (); \ 233 for (p = __CTOR_LIST__ + 1; p < __CTOR_LIST_END__ ; p++ ) \ 234 if (*p) (*p) (); \ 235 do { /* arrange for `return' from main() to pass through exit() */ \ 236 __label__ foo; \ 237 int *callers_caller_fp = (int *) __builtin_frame_address (3); \ 238 register int retval asm ("r0"); \ 239 callers_caller_fp[4] = (int) && foo; \ 240 break; /* out of do-while block */ \ 241 foo: \ 242 exit (retval); \ 243 } while (0); \ 244 } while (0) 245 246 #define __DTOR_LIST__ __gxx_clean_0 247 #define __DTOR_LIST_END__ __gxx_clean_2 248 249 #define __DTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_clean_0_shr 250 #define __DTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_clean_2_shr 251 252 #define DO_GLOBAL_DTORS_BODY \ 253 do { \ 254 func_ptr *p; \ 255 extern func_ptr __DTOR_LIST__[1], __DTOR_LIST_END__[1]; \ 256 extern func_ptr __DTOR_LIST_SHR__[1], __DTOR_LIST_SHR_END__[1]; \ 257 for (p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__ ; p++ ) \ 258 if (*p) (*p) (); \ 259 if (&__DTOR_LIST_SHR__[0] != &__DTOR_LIST__[1]) \ 260 for (p = __DTOR_LIST_SHR__ + 1; p < __DTOR_LIST_SHR_END__ ; p++ ) \ 261 if (*p) (*p) (); \ 262 } while (0) 263 264 #endif /* L__main */ 265 266 /* Specify the list of include file directories. */ 267 #define INCLUDE_DEFAULTS \ 268 { \ 269 { "GNU_GXX_INCLUDE:", "G++", 1, 1 }, \ 270 { "GNU_CC_INCLUDE:", "GCC", 0, 0 }, /* GNU includes */ \ 271 { "SYS$SYSROOT:[SYSLIB.]", 0, 0, 0 }, /* VAX-11 "C" includes */ \ 272 { ".", 0, 0, 1 }, /* Make normal VMS filespecs work. */ \ 273 { 0, 0, 0, 0 } \ 274 } 275