cygwin.h revision 52284
1/* Operating system specific defines to be used when targeting GCC for 2 hosting on Windows NT 3.x, using a Unix style C library and tools, 3 as distinct from winnt.h, which is used to build GCC for use with a 4 windows style library and tool set and uses the Microsoft tools. 5 Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. 6 7This file is part of GNU CC. 8 9GNU CC is free software; you can redistribute it and/or modify 10it under the terms of the GNU General Public License as published by 11the Free Software Foundation; either version 2, or (at your option) 12any later version. 13 14GNU CC is distributed in the hope that it will be useful, 15but WITHOUT ANY WARRANTY; without even the implied warranty of 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17GNU General Public License for more details. 18 19You should have received a copy of the GNU General Public License 20along with GNU CC; see the file COPYING. If not, write to 21the Free Software Foundation, 59 Temple Place - Suite 330, 22Boston, MA 02111-1307, USA. */ 23 24#define YES_UNDERSCORES 25 26#define DBX_DEBUGGING_INFO 27#define SDB_DEBUGGING_INFO 28#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG 29 30#include "i386/gas.h" 31#include "dbxcoff.h" 32 33/* Augment TARGET_SWITCHES with the cygwin/no-cygwin options. */ 34#define MASK_WIN32 0x40000000 /* Use -lming32 interface */ 35#define MASK_CYGWIN 0x20000000 /* Use -lcygwin interface */ 36#define MASK_WINDOWS 0x10000000 /* Use windows interface */ 37#define MASK_DLL 0x08000000 /* Use dll interface */ 38#define MASK_NOP_FUN_DLLIMPORT 0x20000 /* Ignore dllimport for functions */ 39 40#define TARGET_WIN32 (target_flags & MASK_WIN32) 41#define TARGET_CYGWIN (target_flags & MASK_CYGWIN) 42#define TARGET_WINDOWS (target_flags & MASK_WINDOWS) 43#define TARGET_DLL (target_flags & MASK_DLL) 44#define TARGET_NOP_FUN_DLLIMPORT (target_flags & MASK_NOP_FUN_DLLIMPORT) 45 46#undef SUBTARGET_SWITCHES 47#define SUBTARGET_SWITCHES \ 48{ "cygwin", MASK_CYGWIN, "Use the Cygwin interface" }, \ 49{ "no-cygwin", MASK_WIN32, "Use the Mingw32 interface" }, \ 50{ "windows", MASK_WINDOWS, "Create GUI application" }, \ 51{ "console", -MASK_WINDOWS, "Create console application" }, \ 52{ "dll", MASK_DLL, "Generate code for a DLL" }, \ 53{ "nop-fun-dllimport", MASK_NOP_FUN_DLLIMPORT, "Ignore dllimport for functions" }, \ 54{ "no-nop-fun-dllimport", -MASK_NOP_FUN_DLLIMPORT, "" }, 55 56 57/* Support the __declspec keyword by turning them into attributes. 58 We currently only support: dllimport and dllexport. 59 Note that the current way we do this may result in a collision with 60 predefined attributes later on. This can be solved by using one attribute, 61 say __declspec__, and passing args to it. The problem with that approach 62 is that args are not accumulated: each new appearance would clobber any 63 existing args. */ 64 65#ifdef CPP_PREDEFINES 66#undef CPP_PREDEFINES 67#endif 68 69#define CPP_PREDEFINES "-Di386 -D_WIN32 \ 70 -DWINNT -D_X86_=1 -D__STDC__=1\ 71 -D__stdcall=__attribute__((__stdcall__)) \ 72 -D__cdecl=__attribute__((__cdecl__)) \ 73 -D__declspec(x)=__attribute__((x)) \ 74 -Asystem(winnt) -Acpu(i386) -Amachine(i386)" 75 76/* Normally, -lgcc is not needed since everything in it is in the DLL, but we 77 want to allow things to be added to it when installing new versions of 78 GCC without making a new CYGWIN.DLL, so we leave it. Profiling is handled 79 by calling the init function from the prologue. */ 80 81#undef STARTFILE_SPEC 82#define STARTFILE_SPEC "%{mdll: %{mno-cygwin:dllcrt1%O%s}} \ 83 %{!mdll: %{!mno-cygwin:crt0%O%s} \ 84 %{mno-cygwin:crt1%O%s} %{pg:gcrt0%O%s}}" 85 86#undef CPP_SPEC 87#define CPP_SPEC "-remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE} \ 88 %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__} \ 89 %{mno-cygwin:-iwithprefixbefore \ 90 ../../../../%(mingw_include_path)/include/mingw32 -D__MINGW32__=0.2}" 91 92/* This macro defines names of additional specifications to put in the specs 93 that can be used in various specifications like CC1_SPEC. Its definition 94 is an initializer with a subgrouping for each command option. 95 96 Each subgrouping contains a string constant, that defines the 97 specification name, and a string constant that used by the GNU CC driver 98 program. 99 100 Do not define this macro if it does not need to do anything. */ 101 102#undef SUBTARGET_EXTRA_SPECS 103#define SUBTARGET_EXTRA_SPECS \ 104 { "mingw_include_path", DEFAULT_TARGET_MACHINE } 105 106/* We have to dynamic link to get to the system DLLs. All of libc, libm and 107 the Unix stuff is in cygwin.dll. The import library is called 108 'libcygwin.a'. For Windows applications, include more libraries, but 109 always include kernel32. We'd like to specific subsystem windows to 110 ld, but that doesn't work just yet. */ 111 112#undef LIB_SPEC 113#define LIB_SPEC "%{pg:-lgmon} \ 114 %{!mno-cygwin:-lcygwin} \ 115 %{mno-cygwin:-lmingw32 -lmoldname -lcrtdll} \ 116 %{mwindows:-lgdi32 -lcomdlg32} \ 117 -luser32 -lkernel32 -ladvapi32 -lshell32" 118 119#define LINK_SPEC "%{mwindows:--subsystem windows} \ 120 %{mconsole:--subsystem console} \ 121 %{mdll:--dll -e _DllMainCRTStartup@12}" 122 123 124#define SIZE_TYPE "unsigned int" 125#define PTRDIFF_TYPE "int" 126#define WCHAR_UNSIGNED 1 127#define WCHAR_TYPE_SIZE 16 128#define WCHAR_TYPE "short unsigned int" 129 130#define HAVE_ATEXIT 1 131 132 133/* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop). */ 134#define HANDLE_PRAGMA_PACK_PUSH_POP 1 135 136/* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS 137 is a valid machine specific attribute for DECL. 138 The attributes in ATTRIBUTES have previously been assigned to DECL. */ 139extern int i386_pe_valid_decl_attribute_p (); 140 141#undef VALID_MACHINE_DECL_ATTRIBUTE 142#define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, IDENTIFIER, ARGS) \ 143 i386_pe_valid_decl_attribute_p (DECL, ATTRIBUTES, IDENTIFIER, ARGS) 144 145/* A C expression whose value is nonzero if IDENTIFIER with arguments ARGS 146 is a valid machine specific attribute for TYPE. 147 The attributes in ATTRIBUTES have previously been assigned to TYPE. */ 148 149#undef VALID_MACHINE_TYPE_ATTRIBUTE 150#define VALID_MACHINE_TYPE_ATTRIBUTE(TYPE, ATTRIBUTES, IDENTIFIER, ARGS) \ 151 i386_pe_valid_type_attribute_p (TYPE, ATTRIBUTES, IDENTIFIER, ARGS) 152extern int i386_pe_valid_type_attribute_p (); 153 154extern union tree_node *i386_pe_merge_decl_attributes (); 155#define MERGE_MACHINE_DECL_ATTRIBUTES(OLD, NEW) \ 156 i386_pe_merge_decl_attributes ((OLD), (NEW)) 157 158/* Used to implement dllexport overriding dllimport semantics. It's also used 159 to handle vtables - the first pass won't do anything because 160 DECL_CONTEXT (DECL) will be 0 so i386_pe_dll{ex,im}port_p will return 0. 161 It's also used to handle dllimport override semantics. */ 162#if 0 163#define REDO_SECTION_INFO_P(DECL) \ 164 ((DECL_MACHINE_ATTRIBUTES (DECL) != NULL_TREE) \ 165 || (TREE_CODE (DECL) == VAR_DECL && DECL_VIRTUAL_P (DECL))) 166#else 167#define REDO_SECTION_INFO_P(DECL) 1 168#endif 169 170 171#undef EXTRA_SECTIONS 172#define EXTRA_SECTIONS in_ctor, in_dtor, in_drectve 173 174#undef EXTRA_SECTION_FUNCTIONS 175#define EXTRA_SECTION_FUNCTIONS \ 176 CTOR_SECTION_FUNCTION \ 177 DTOR_SECTION_FUNCTION \ 178 DRECTVE_SECTION_FUNCTION \ 179 SWITCH_TO_SECTION_FUNCTION 180 181#define CTOR_SECTION_FUNCTION \ 182void \ 183ctor_section () \ 184{ \ 185 if (in_section != in_ctor) \ 186 { \ 187 fprintf (asm_out_file, "\t.section .ctor\n"); \ 188 in_section = in_ctor; \ 189 } \ 190} 191 192#define DTOR_SECTION_FUNCTION \ 193void \ 194dtor_section () \ 195{ \ 196 if (in_section != in_dtor) \ 197 { \ 198 fprintf (asm_out_file, "\t.section .dtor\n"); \ 199 in_section = in_dtor; \ 200 } \ 201} 202 203#define DRECTVE_SECTION_FUNCTION \ 204void \ 205drectve_section () \ 206{ \ 207 if (in_section != in_drectve) \ 208 { \ 209 fprintf (asm_out_file, "%s\n", "\t.section .drectve\n"); \ 210 in_section = in_drectve; \ 211 } \ 212} 213 214/* Switch to SECTION (an `enum in_section'). 215 216 ??? This facility should be provided by GCC proper. 217 The problem is that we want to temporarily switch sections in 218 ASM_DECLARE_OBJECT_NAME and then switch back to the original section 219 afterwards. */ 220#define SWITCH_TO_SECTION_FUNCTION \ 221void \ 222switch_to_section (section, decl) \ 223 enum in_section section; \ 224 tree decl; \ 225{ \ 226 switch (section) \ 227 { \ 228 case in_text: text_section (); break; \ 229 case in_data: data_section (); break; \ 230 case in_named: named_section (decl, NULL, 0); break; \ 231 case in_ctor: ctor_section (); break; \ 232 case in_dtor: dtor_section (); break; \ 233 case in_drectve: drectve_section (); break; \ 234 default: abort (); break; \ 235 } \ 236} 237 238#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ 239 do { \ 240 ctor_section (); \ 241 fprintf (FILE, "%s\t", ASM_LONG); \ 242 assemble_name (FILE, NAME); \ 243 fprintf (FILE, "\n"); \ 244 } while (0) 245 246#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ 247 do { \ 248 dtor_section (); \ 249 fprintf (FILE, "%s\t", ASM_LONG); \ 250 assemble_name (FILE, NAME); \ 251 fprintf (FILE, "\n"); \ 252 } while (0) 253 254/* Don't allow flag_pic to propagate since gas may produce invalid code 255 otherwise. */ 256 257#undef SUBTARGET_OVERRIDE_OPTIONS 258#define SUBTARGET_OVERRIDE_OPTIONS \ 259do { \ 260 if (flag_pic) \ 261 { \ 262 warning ("-f%s ignored for target (all code is position independent)",\ 263 (flag_pic > 1) ? "PIC" : "pic"); \ 264 flag_pic = 0; \ 265 } \ 266} while (0) \ 267 268/* Define this macro if references to a symbol must be treated 269 differently depending on something about the variable or 270 function named by the symbol (such as what section it is in). 271 272 On i386 running Windows NT, modify the assembler name with a suffix 273 consisting of an atsign (@) followed by string of digits that represents 274 the number of bytes of arguments passed to the function, if it has the 275 attribute STDCALL. 276 277 In addition, we must mark dll symbols specially. Definitions of 278 dllexport'd objects install some info in the .drectve section. 279 References to dllimport'd objects are fetched indirectly via 280 _imp__. If both are declared, dllexport overrides. This is also 281 needed to implement one-only vtables: they go into their own 282 section and we need to set DECL_SECTION_NAME so we do that here. 283 Note that we can be called twice on the same decl. */ 284 285extern void i386_pe_encode_section_info (); 286 287#ifdef ENCODE_SECTION_INFO 288#undef ENCODE_SECTION_INFO 289#endif 290#define ENCODE_SECTION_INFO(DECL) i386_pe_encode_section_info (DECL) 291 292/* Utility used only in this file. */ 293#define I386_PE_STRIP_ENCODING(SYM_NAME) \ 294 ((SYM_NAME) + ((SYM_NAME)[0] == '@' ? 3 : 0)) 295 296/* This macro gets just the user-specified name 297 out of the string in a SYMBOL_REF. Discard 298 trailing @[NUM] encoded by ENCODE_SECTION_INFO. */ 299#undef STRIP_NAME_ENCODING 300#define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \ 301do { \ 302 char *_p; \ 303 char *_name = I386_PE_STRIP_ENCODING (SYMBOL_NAME); \ 304 for (_p = _name; *_p && *_p != '@'; ++_p) \ 305 ; \ 306 if (*_p == '@') \ 307 { \ 308 int _len = _p - _name; \ 309 (VAR) = (char *) alloca (_len + 1); \ 310 strncpy ((VAR), _name, _len); \ 311 (VAR)[_len] = '\0'; \ 312 } \ 313 else \ 314 (VAR) = _name; \ 315} while (0) 316 317 318/* Output a reference to a label. */ 319#undef ASM_OUTPUT_LABELREF 320#define ASM_OUTPUT_LABELREF(STREAM, NAME) \ 321 fprintf (STREAM, "%s%s", USER_LABEL_PREFIX, \ 322 I386_PE_STRIP_ENCODING (NAME)) \ 323 324/* Output a common block. */ 325#undef ASM_OUTPUT_COMMON 326#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \ 327do { \ 328 if (i386_pe_dllexport_name_p (NAME)) \ 329 i386_pe_record_exported_symbol (NAME); \ 330 if (! i386_pe_dllimport_name_p (NAME)) \ 331 { \ 332 fprintf ((STREAM), "\t.comm\t"); \ 333 assemble_name ((STREAM), (NAME)); \ 334 fprintf ((STREAM), ", %d\t%s %d\n", \ 335 (ROUNDED), ASM_COMMENT_START, (SIZE)); \ 336 } \ 337} while (0) 338 339/* Output the label for an initialized variable. */ 340#undef ASM_DECLARE_OBJECT_NAME 341#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \ 342do { \ 343 if (i386_pe_dllexport_name_p (NAME)) \ 344 i386_pe_record_exported_symbol (NAME); \ 345 ASM_OUTPUT_LABEL ((STREAM), (NAME)); \ 346} while (0) 347 348 349/* Emit code to check the stack when allocating more that 4000 350 bytes in one go. */ 351 352#define CHECK_STACK_LIMIT 4000 353 354/* By default, target has a 80387, uses IEEE compatible arithmetic, 355 and returns float values in the 387 and needs stack probes */ 356#undef TARGET_DEFAULT 357 358#define TARGET_DEFAULT \ 359 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE) 360 361/* This is how to output an assembler line 362 that says to advance the location counter 363 to a multiple of 2**LOG bytes. */ 364 365#undef ASM_OUTPUT_ALIGN 366#define ASM_OUTPUT_ALIGN(FILE,LOG) \ 367 if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG)) 368 369/* Define this macro if in some cases global symbols from one translation 370 unit may not be bound to undefined symbols in another translation unit 371 without user intervention. For instance, under Microsoft Windows 372 symbols must be explicitly imported from shared libraries (DLLs). */ 373#define MULTIPLE_SYMBOL_SPACES 374 375#define UNIQUE_SECTION_P(DECL) DECL_ONE_ONLY (DECL) 376extern void i386_pe_unique_section (); 377#define UNIQUE_SECTION(DECL,RELOC) i386_pe_unique_section (DECL, RELOC) 378 379#define SUPPORTS_ONE_ONLY 1 380 381/* A C statement to output something to the assembler file to switch to section 382 NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or 383 NULL_TREE. Some target formats do not support arbitrary sections. Do not 384 define this macro in such cases. */ 385#undef ASM_OUTPUT_SECTION_NAME 386#define ASM_OUTPUT_SECTION_NAME(STREAM, DECL, NAME, RELOC) \ 387do { \ 388 static struct section_info \ 389 { \ 390 struct section_info *next; \ 391 char *name; \ 392 enum sect_enum {SECT_RW, SECT_RO, SECT_EXEC} type; \ 393 } *sections; \ 394 struct section_info *s; \ 395 char *mode; \ 396 enum sect_enum type; \ 397 \ 398 for (s = sections; s; s = s->next) \ 399 if (!strcmp (NAME, s->name)) \ 400 break; \ 401 \ 402 if (DECL && TREE_CODE (DECL) == FUNCTION_DECL) \ 403 type = SECT_EXEC, mode = "x"; \ 404 else if (DECL && DECL_READONLY_SECTION (DECL, RELOC)) \ 405 type = SECT_RO, mode = ""; \ 406 else \ 407 type = SECT_RW, mode = "w"; \ 408 \ 409 if (s == 0) \ 410 { \ 411 s = (struct section_info *) xmalloc (sizeof (struct section_info)); \ 412 s->name = xmalloc ((strlen (NAME) + 1) * sizeof (*NAME)); \ 413 strcpy (s->name, NAME); \ 414 s->type = type; \ 415 s->next = sections; \ 416 sections = s; \ 417 fprintf (STREAM, ".section\t%s,\"%s\"\n", NAME, mode); \ 418 /* Functions may have been compiled at various levels of \ 419 optimization so we can't use `same_size' here. Instead, \ 420 have the linker pick one. */ \ 421 if ((DECL) && DECL_ONE_ONLY (DECL)) \ 422 fprintf (STREAM, "\t.linkonce %s\n", \ 423 TREE_CODE (DECL) == FUNCTION_DECL \ 424 ? "discard" : "same_size"); \ 425 } \ 426 else \ 427 { \ 428 fprintf (STREAM, ".section\t%s,\"%s\"\n", NAME, mode); \ 429 } \ 430} while (0) 431 432/* Write the extra assembler code needed to declare a function 433 properly. If we are generating SDB debugging information, this 434 will happen automatically, so we only need to handle other cases. */ 435#undef ASM_DECLARE_FUNCTION_NAME 436#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ 437 do \ 438 { \ 439 if (i386_pe_dllexport_name_p (NAME)) \ 440 i386_pe_record_exported_symbol (NAME); \ 441 if (write_symbols != SDB_DEBUG) \ 442 i386_pe_declare_function_type (FILE, NAME, TREE_PUBLIC (DECL)); \ 443 ASM_OUTPUT_LABEL (FILE, NAME); \ 444 } \ 445 while (0) 446 447/* Add an external function to the list of functions to be declared at 448 the end of the file. */ 449#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \ 450 do \ 451 { \ 452 if (TREE_CODE (DECL) == FUNCTION_DECL) \ 453 i386_pe_record_external_function (NAME); \ 454 } \ 455 while (0) 456 457/* Declare the type properly for any external libcall. */ 458#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \ 459 i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1) 460 461/* Output function declarations at the end of the file. */ 462#define ASM_FILE_END(FILE) \ 463 i386_pe_asm_file_end (FILE) 464 465#undef ASM_COMMENT_START 466#define ASM_COMMENT_START " #" 467 468/* DWARF2 Unwinding doesn't work with exception handling yet. */ 469#define DWARF2_UNWIND_INFO 0 470 471/* Don't assume anything about the header files. */ 472#define NO_IMPLICIT_EXTERN_C 473 474#define SUBTARGET_PROLOGUE \ 475 if (profile_flag \ 476 && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),\ 477 "main") == 0) \ 478 { \ 479 rtx xops[1]; \ 480 xops[0] = gen_rtx_MEM (FUNCTION_MODE, \ 481 gen_rtx (SYMBOL_REF, Pmode, "_monstartup")); \ 482 if (do_rtl) \ 483 emit_call_insn (gen_rtx (CALL, VOIDmode, xops[0], const0_rtx)); \ 484 else \ 485 output_asm_insn (AS1 (call,%P1), xops); \ 486 } 487 488/* External function declarations. */ 489 490#ifndef PROTO 491#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) 492#define PROTO(ARGS) ARGS 493#else 494#define PROTO(ARGS) () 495#endif 496#endif 497 498#ifdef BUFSIZ /* stdio.h has been included, ok to use FILE * */ 499#define STDIO_PROTO(ARGS) PROTO(ARGS) 500#else 501#define STDIO_PROTO(ARGS) () 502#endif 503 504extern void i386_pe_record_external_function PROTO((char *)); 505extern void i386_pe_declare_function_type STDIO_PROTO((FILE *, char *, int)); 506extern void i386_pe_record_exported_symbol PROTO((char *)); 507extern void i386_pe_asm_file_end STDIO_PROTO((FILE *)); 508 509/* For Win32 ABI compatibility */ 510#undef DEFAULT_PCC_STRUCT_RETURN 511#define DEFAULT_PCC_STRUCT_RETURN 0 512 513/* No data type wants to be aligned rounder than this. */ 514#undef BIGGEST_ALIGNMENT 515#define BIGGEST_ALIGNMENT 128 516 517/* A bitfield declared as `int' forces `int' alignment for the struct. */ 518#undef PCC_BITFIELDS_TYPE_MATTERS 519#define PCC_BITFIELDS_TYPE_MATTERS 0 520 521/* Enable alias attribute support. */ 522#ifndef SET_ASM_OP 523#define SET_ASM_OP "\t.set" 524#endif 525 526