1 /* Target definitions for GCC for Intel 80386 running Interix 2 Parts Copyright (C) 1991-2016 Free Software Foundation, Inc. 3 4 Parts: 5 by Douglas B. Rupp (drupp@cs.washington.edu). 6 by Ron Guilmette (rfg@netcom.com). 7 by Donn Terry (donn@softway.com). 8 by Mumit Khan (khan@xraylith.wisc.edu). 9 10 This file is part of GCC. 11 12 GCC is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 3, or (at your option) 15 any later version. 16 17 GCC is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with GCC; see the file COPYING3. If not see 24 <http://www.gnu.org/licenses/>. */ 25 26 /* Note: Interix doesn't support user-written DLLs (use conventional 27 shared libs (.so) instead). Thus a lot of the stuff that might apply 28 about dllimport/dllexport and the like does not apply here. */ 29 30 #include <stdio.h> 31 32 /* Names to predefine in the preprocessor for this target machine. */ 33 34 #define DBX_DEBUGGING_INFO 1 35 #define SDB_DEBUGGING_INFO 1 36 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG 37 38 /* Our strategy for finding global constructors is a bit different, although 39 not a lot. */ 40 #define DO_GLOBAL_CTORS_BODY \ 41 do { \ 42 int i; \ 43 unsigned long nptrs; \ 44 func_ptr *p; \ 45 asm( \ 46 " .section .ctor_head, \"rw\"\n" \ 47 "1:\n" \ 48 " .text \n" \ 49 ASM_LOAD_ADDR(1b,%0) \ 50 : "=r" (p) : : "cc"); \ 51 for (nptrs = 0; p[nptrs] != 0; nptrs++); \ 52 for (i = nptrs-1; i >= 0; i--) \ 53 p[i] (); \ 54 } while (0) 55 56 #define DO_GLOBAL_DTORS_BODY \ 57 do { \ 58 func_ptr *p; \ 59 asm( \ 60 " .section .dtor_head, \"rw\"\n" \ 61 "1:\n" \ 62 " .text \n" \ 63 ASM_LOAD_ADDR(1b,%0) \ 64 : "=r" (p) : : "cc"); \ 65 while (*p) \ 66 { \ 67 p++; \ 68 (*(p-1)) (); \ 69 } \ 70 } while (0) 71 72 /* We don't use the "usual" push-an-address solution. */ 73 #undef TARGET_ASM_CONSTRUCTOR 74 75 #undef SUBTARGET_SWITCHES 76 #define SUBTARGET_SWITCHES \ 77 { "ms-bitfields", MASK_MS_BITFIELD_LAYOUT, N_("Use native (MS) bitfield layout") }, \ 78 { "no-ms-bitfields", -MASK_MS_BITFIELD_LAYOUT, N_("Use gcc default bitfield layout") }, 79 80 #undef LIB_SPEC 81 #define LIB_SPEC "\ 82 %{!shared:%{!dynamic:-lc -lpsxdll \ 83 }} \ 84 %{!G:%{!dynamic:-lc -lpsxdll \ 85 }} \ 86 %{dynamic:-lc -lpsxdll \ 87 } \ 88 %{v}" 89 90 #undef LINK_SPEC 91 #define LINK_SPEC "%{!shared:-stack 0x4000000,0x10000} \ 92 %{g} \ 93 %{dynamic:-Bdynamic} \ 94 %{static:-Bstatic} \ 95 %{shared:--shared -Bdynamic} \ 96 %{G:--shared -Bdynamic} \ 97 %{symbolic:--shared -Bsymbolic -Bdynamic} \ 98 %{rpath*:--rpath %*} \ 99 " 100 101 #undef STARTFILE_SPEC 102 #define STARTFILE_SPEC \ 103 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}} %{shared:crti%O%s}" 104 105 #define TARGET_DECLSPEC 1 106 107 /* cpp handles __STDC__ */ 108 #define TARGET_OS_CPP_BUILTINS() \ 109 do \ 110 { \ 111 builtin_define ("__INTERIX"); \ 112 builtin_define ("_M_IX86=300"); \ 113 builtin_define ("_X86_=1"); \ 114 builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ 115 builtin_define ("__cdecl=__attribute__((__cdecl__))"); \ 116 builtin_define ("__declspec(x)=__attribute__((x))"); \ 117 builtin_assert ("system=unix"); \ 118 builtin_assert ("system=interix"); \ 119 if (preprocessing_asm_p ()) \ 120 builtin_define_std ("LANGUAGE_ASSEMBLY"); \ 121 else \ 122 { \ 123 builtin_define_std ("LANGUAGE_C"); \ 124 if (c_dialect_cxx ()) \ 125 builtin_define_std ("LANGUAGE_C_PLUS_PLUS"); \ 126 if (c_dialect_objc ()) \ 127 builtin_define_std ("LANGUAGE_OBJECTIVE_C"); \ 128 } \ 129 } \ 130 while (0) 131 132 #undef CPP_SPEC 133 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE}" 134 135 #define SIZE_TYPE "unsigned int" 136 #define PTRDIFF_TYPE "int" 137 #define WCHAR_TYPE "short unsigned int" 138 #define WCHAR_TYPE_SIZE 16 139 140 /* Turn off long double being 96 bits. */ 141 #undef LONG_DOUBLE_TYPE_SIZE 142 #define LONG_DOUBLE_TYPE_SIZE 64 143 144 #define IX86_NO_LIBGCC_TFMODE 145 146 #undef TARGET_LIBC_HAS_FUNCTION 147 #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function 148 149 /* The following are needed for us to be able to use winnt.c, but are not 150 otherwise meaningful to Interix. (The functions that use these are 151 never called because we don't do DLLs.) */ 152 #define TARGET_NOP_FUN_DLLIMPORT 1 153 #define drectve_section() /* nothing */ 154 155 156 #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rdata,\"r\"" 157 158 /* Define this macro if references to a symbol must be treated 159 differently depending on something about the variale or 160 function named by the symbol (such as what section it is in). */ 161 162 #undef TARGET_ENCODE_SECTION_INFO 163 #define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info 164 #undef TARGET_STRIP_NAME_ENCODING 165 #define TARGET_STRIP_NAME_ENCODING i386_pe_strip_name_encoding_full 166 167 /* Emit code to check the stack when allocating more that 4000 168 bytes in one go. */ 169 170 #define CHECK_STACK_LIMIT 4000 171 172 /* By default, target has a 80387, uses IEEE compatible arithmetic, 173 and returns float values in the 387 and needs stack probes 174 We also align doubles to 64-bits forMSVC default compatibility 175 Ditto for bitfields. */ 176 #undef TARGET_SUBTARGET_DEFAULT 177 #define TARGET_SUBTARGET_DEFAULT \ 178 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE | \ 179 MASK_ALIGN_DOUBLE | MASK_MS_BITFIELD_LAYOUT) 180 181 /* The MS compilers take alignment as a number of bytes, so we do as well */ 182 #undef ASM_OUTPUT_ALIGN 183 #define ASM_OUTPUT_ALIGN(FILE,LOG) \ 184 if ((LOG)!=0) fprintf ((FILE), "\t.balign %d\n", 1<<(LOG)) 185 186 187 /* Define this macro if in some cases global symbols from one translation 188 unit may not be bound to undefined symbols in another translation unit 189 without user intervention. For instance, under Microsoft Windows 190 symbols must be explicitly imported from shared libraries (DLLs). */ 191 /* 192 * Old gcc(3.3) did not have 1 here 193 */ 194 #define MULTIPLE_SYMBOL_SPACES 1 195 196 extern void i386_pe_unique_section (tree, int); 197 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section 198 199 /* Switch into a generic section. */ 200 #define TARGET_ASM_NAMED_SECTION default_pe_asm_named_section 201 202 /* Select attributes for named sections. */ 203 #define TARGET_SECTION_TYPE_FLAGS i386_pe_section_type_flags 204 205 /* Write the extra assembler code needed to declare a function 206 properly. If we are generating SDB debugging information, this 207 will happen automatically, so we only need to handle other cases. */ 208 #undef ASM_DECLARE_FUNCTION_NAME 209 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ 210 do \ 211 { \ 212 if (write_symbols != SDB_DEBUG) \ 213 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \ 214 ASM_OUTPUT_LABEL (FILE, NAME); \ 215 } \ 216 while (0) 217 218 /* Add an external function to the list of functions to be declared at 219 the end of the file. */ 220 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \ 221 do \ 222 { \ 223 if (TREE_CODE (DECL) == FUNCTION_DECL) \ 224 i386_pe_record_external_function (DECL, NAME); \ 225 } \ 226 while (0) 227 228 /* Declare the type properly for any external libcall. */ 229 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \ 230 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1) 231 232 /* This says out to put a global symbol in the BSS section. */ 233 #undef ASM_OUTPUT_ALIGNED_BSS 234 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \ 235 asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN)) 236 237 /* Don't assume anything about the header files. */ 238 #define NO_IMPLICIT_EXTERN_C 239 240 /* External function declarations. */ 241 extern void i386_pe_record_external_function (tree, const char *); 242 extern void i386_pe_declare_function_type (FILE *, const char *, int); 243 extern void i386_pe_record_exported_symbol (const char *, int); 244 extern void i386_pe_asm_file_end (FILE *); 245 246 /* For Win32 ABI compatibility */ 247 #undef DEFAULT_PCC_STRUCT_RETURN 248 #define DEFAULT_PCC_STRUCT_RETURN 0 249 250 /* A bitfield declared as `int' forces `int' alignment for the struct. */ 251 #undef PCC_BITFIELD_TYPE_MATTERS 252 #define PCC_BITFIELD_TYPE_MATTERS 1 253 254 /* Enable alias attribute support. */ 255 #ifndef SET_ASM_OP 256 #define SET_ASM_OP "\t.set\t" 257 #endif 258 259 /* Note that there appears to be two different ways to support const 260 sections at the moment. You can either #define the symbol 261 READONLY_DATA_SECTION (giving it some code which switches to the 262 readonly data section) or else you can #define the symbols 263 EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and 264 SELECT_RTX_SECTION. We do both here just to be on the safe side. */ 265 266 #define USE_CONST_SECTION 1 267 268 /* The linker will take care of this, and having them causes problems with 269 ld -r (specifically -rU). */ 270 #define CTOR_LISTS_DEFINED_EXTERNALLY 1 271 272 /* Output a definition (implements alias) */ 273 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ 274 do \ 275 { \ 276 fputs (SET_ASM_OP, (FILE)); \ 277 assemble_name (FILE, LABEL1); \ 278 fputc (',', (FILE)); \ 279 assemble_name (FILE, LABEL2); \ 280 fputc ('\n', (FILE)); \ 281 } \ 282 while (0) 283 284 #define HOST_PTR_AS_INT unsigned long 285 286 /* The following two flags are usually "off" for i386, because some non-gnu 287 tools (for the i386) don't handle them. However, we don't have that 288 problem, so.... */ 289 290 /* Forward references to tags are allowed. */ 291 #define SDB_ALLOW_FORWARD_REFERENCES 292 /* Unknown tags are also allowed. */ 293 #define SDB_ALLOW_UNKNOWN_REFERENCES 294 /* DWARF2 Unwinding doesn't work with exception handling yet. */ 295 #define DWARF2_UNWIND_INFO 0 296 /* MSVC returns structs of up to 8 bytes via registers. */ 297 298 #undef SUBTARGET_RETURN_IN_MEMORY 299 #define SUBTARGET_RETURN_IN_MEMORY(TYPE, FNTYPE) \ 300 (TYPE_MODE (TYPE) == BLKmode || \ 301 (AGGREGATE_TYPE_P (TYPE) && int_size_in_bytes(TYPE) > 8 )) 302 303 #define ASM_LOAD_ADDR(loc, reg) " leal " #loc "," #reg "\n" 304 305 /* The integer half of this list needs to be constant. However, there's 306 a lot of disagreement about what the floating point adjustments should 307 be. We pick one that works with gdb. (The underlying problem is 308 what to do about the segment registers. Since we have access to them 309 from /proc, we'll allow them to be accessed in gdb, even tho the 310 gcc compiler can't generate them. (There's some evidence that 311 MSVC does, but possibly only for certain special "canned" sequences.) */ 312 313 #undef DBX_REGISTER_NUMBER 314 #define DBX_REGISTER_NUMBER(n) \ 315 (TARGET_64BIT ? dbx64_register_map[n] \ 316 : (n) == 0 ? (int) 0 \ 317 : (n) == 1 ? (int) 2 \ 318 : (n) == 2 ? (int) 1 \ 319 : (n) == 3 ? (int) 3 \ 320 : (n) == 4 ? (int) 6 \ 321 : (n) == 5 ? (int) 7 \ 322 : (n) == 6 ? (int) 5 \ 323 : (n) == 7 ? (int) 4 \ 324 : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (int) (n)+8 \ 325 : (int) (-1)) 326 327 #define EH_FRAME_THROUGH_COLLECT2 328 #define EH_TABLES_CAN_BE_READ_ONLY 0 329 330 /* the following are OSF linker (not gld) specific... we don't want them */ 331 #undef HAS_INIT_SECTION 332 #undef LD_INIT_SWITCH 333 #undef LD_FINI_SWITCH 334 335 /* The following are needed for us to be able to use winnt.c, but are not 336 otherwise meaningful to Interix. (The functions that use these are 337 never called because we don't do DLLs.) */ 338 #define TARGET_NOP_FUN_DLLIMPORT 1 339 #define I386_PE_STRIP_ENCODING(SYM_NAME) \ 340 ((SYM_NAME) + ((SYM_NAME)[0] == '@' \ 341 ? ((SYM_NAME)[3] == '*' ? 4 : 3) : 0) \ 342 + ((SYM_NAME)[0] == '*' ? 1 : 0)) 343 344 #define drectve_section() /* nothing */ 345 346