1 /* Subroutines for insn-output.c for Windows NT.
2 Contributed by Douglas Rupp (drupp@cs.washington.edu)
3 Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
38 /* i386/PE specific attribute support.
40 i386/PE has two new attributes:
41 dllexport - for exporting a function/variable that will live in a dll
42 dllimport - for importing a function/variable from a dll
44 Microsoft allows multiple declspecs in one __declspec, separating
45 them with spaces. We do NOT support this. Instead, use __declspec
49 static tree associated_type (tree);
50 const char * gen_stdcall_suffix (tree);
51 const char * gen_fastcall_suffix (tree);
52 int i386_pe_dllexport_p (tree);
53 int i386_pe_dllimport_p (tree);
54 void i386_pe_mark_dllexport (tree);
55 void i386_pe_mark_dllimport (tree);
57 /* This is we how mark internal identifiers with dllimport or dllexport
59 #ifndef DLL_IMPORT_PREFIX
60 #define DLL_IMPORT_PREFIX "#i."
62 #ifndef DLL_EXPORT_PREFIX
63 #define DLL_EXPORT_PREFIX "#e."
66 /* Handle a "dllimport" or "dllexport" attribute;
67 arguments as in struct attribute_spec.handler. */
69 ix86_handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
74 /* These attributes may apply to structure and union types being created,
75 but otherwise should pass to the declaration involved. */
78 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
79 | (int) ATTR_FLAG_ARRAY_NEXT))
82 return tree_cons (name, args, NULL_TREE);
84 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
86 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
93 /* Report error on dllimport ambiguities seen now before they cause
95 else if (is_attribute_p ("dllimport", name))
97 /* Like MS, treat definition of dllimported variables and
98 non-inlined functions on declaration as syntax errors.
99 We allow the attribute for function definitions if declared
100 inline, but just ignore it in i386_pe_dllimport_p. */
101 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
102 && !DECL_INLINE (node))
104 error ("%Hfunction `%D' definition is marked dllimport.",
105 &DECL_SOURCE_LOCATION (node), node);
106 *no_add_attrs = true;
109 else if (TREE_CODE (node) == VAR_DECL)
111 if (DECL_INITIAL (node))
113 error ("%Hvariable `%D' definition is marked dllimport.",
114 &DECL_SOURCE_LOCATION (node), node);
115 *no_add_attrs = true;
118 /* `extern' needn't be specified with dllimport.
119 Specify `extern' now and hope for the best. Sigh. */
120 DECL_EXTERNAL (node) = 1;
121 /* Also, implicitly give dllimport'd variables declared within
122 a function global scope, unless declared static. */
123 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
124 TREE_PUBLIC (node) = 1;
128 /* Report error if symbol is not accessible at global scope. */
129 if (!TREE_PUBLIC (node)
130 && (TREE_CODE (node) == VAR_DECL
131 || TREE_CODE (node) == FUNCTION_DECL))
133 error ("%Hexternal linkage required for symbol '%D' because of '%s' attribute.",
134 &DECL_SOURCE_LOCATION (node), node, IDENTIFIER_POINTER (name));
135 *no_add_attrs = true;
141 /* Handle a "shared" attribute;
142 arguments as in struct attribute_spec.handler. */
144 ix86_handle_shared_attribute (tree *node, tree name,
145 tree args ATTRIBUTE_UNUSED,
146 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
148 if (TREE_CODE (*node) != VAR_DECL)
150 warning ("`%s' attribute only applies to variables",
151 IDENTIFIER_POINTER (name));
152 *no_add_attrs = true;
158 /* Return the type that we should use to determine if DECL is
159 imported or exported. */
162 associated_type (tree decl)
166 /* In the C++ frontend, DECL_CONTEXT for a method doesn't actually refer
167 to the containing class. So we look at the 'this' arg. */
168 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
170 /* Artificial methods are not affected by the import/export status
171 of their class unless they are COMDAT. Implicit copy ctor's and
172 dtor's are not affected by class status but virtual and
173 non-virtual thunks are. */
174 if (!DECL_ARTIFICIAL (decl) || DECL_COMDAT (decl))
175 t = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))));
177 else if (DECL_CONTEXT (decl)
178 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
179 t = DECL_CONTEXT (decl);
184 /* Return nonzero if DECL is a dllexport'd object. */
187 i386_pe_dllexport_p (tree decl)
191 if (TREE_CODE (decl) != VAR_DECL
192 && TREE_CODE (decl) != FUNCTION_DECL)
194 exp = lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl));
198 /* Class members get the dllexport status of their class. */
199 if (associated_type (decl))
201 exp = lookup_attribute ("dllexport",
202 TYPE_ATTRIBUTES (associated_type (decl)));
210 /* Return nonzero if DECL is a dllimport'd object. */
213 i386_pe_dllimport_p (tree decl)
218 if (TREE_CODE (decl) == FUNCTION_DECL
219 && TARGET_NOP_FUN_DLLIMPORT)
222 if (TREE_CODE (decl) != VAR_DECL
223 && TREE_CODE (decl) != FUNCTION_DECL)
226 imp = lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl));
228 /* Class members get the dllimport status of their class. */
229 if (!imp && associated_type (decl))
231 imp = lookup_attribute ("dllimport",
232 TYPE_ATTRIBUTES (associated_type (decl)));
239 /* Don't mark defined functions as dllimport. If the definition
240 itself was marked with dllimport, than ix86_handle_dll_attribute
241 reports an error. This handles the case when the definition
242 overrides an earlier declaration. */
243 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)
244 && !DECL_INLINE (decl))
246 /* Don't warn about artificial methods. */
247 if (!DECL_ARTIFICIAL (decl))
248 warning ("%H function '%D' is defined after prior declaration as dllimport: attribute ignored",
249 &DECL_SOURCE_LOCATION (decl), decl);
253 /* We ignore the dllimport attribute for inline member functions.
254 This differs from MSVC behavior which treats it like GNUC
255 'extern inline' extension. */
256 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
259 warning ("%Hinline function '%D' is declared as dllimport: attribute ignored.",
260 &DECL_SOURCE_LOCATION (decl), decl);
264 /* Don't allow definitions of static data members in dllimport class,
265 Just ignore attribute for vtable data. */
266 else if (TREE_CODE (decl) == VAR_DECL
267 && TREE_STATIC (decl) && TREE_PUBLIC (decl)
268 && !DECL_EXTERNAL (decl) && context_imp)
270 if (!DECL_VIRTUAL_P (decl))
271 error ("%Hdefinition of static data member '%D' of dllimport'd class.",
272 &DECL_SOURCE_LOCATION (decl), decl); return 0;
275 /* Since we can't treat a pointer to a dllimport'd symbol as a
276 constant address, we turn off the attribute on C++ virtual
277 methods to allow creation of vtables using thunks. Don't mark
278 artificial methods either (in associated_type, only COMDAT
279 artificial method get import status from class context). */
280 else if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
281 && (DECL_VIRTUAL_P (decl) || DECL_ARTIFICIAL (decl)))
290 /* Return nonzero if SYMBOL is marked as being dllexport'd. */
293 i386_pe_dllexport_name_p (const char *symbol)
295 return (strncmp (DLL_EXPORT_PREFIX, symbol,
296 strlen (DLL_EXPORT_PREFIX)) == 0);
299 /* Return nonzero if SYMBOL is marked as being dllimport'd. */
302 i386_pe_dllimport_name_p (const char *symbol)
304 return (strncmp (DLL_IMPORT_PREFIX, symbol,
305 strlen (DLL_IMPORT_PREFIX)) == 0);
308 /* Mark a DECL as being dllexport'd.
309 Note that we override the previous setting (eg: dllimport). */
312 i386_pe_mark_dllexport (tree decl)
319 rtlname = XEXP (DECL_RTL (decl), 0);
320 if (GET_CODE (rtlname) == SYMBOL_REF)
321 oldname = XSTR (rtlname, 0);
322 else if (GET_CODE (rtlname) == MEM
323 && GET_CODE (XEXP (rtlname, 0)) == SYMBOL_REF)
324 oldname = XSTR (XEXP (rtlname, 0), 0);
327 if (i386_pe_dllimport_name_p (oldname))
329 warning ("%Hinconsistent dll linkage for '%D', dllexport assumed.",
330 &DECL_SOURCE_LOCATION (decl), decl);
331 /* Remove DLL_IMPORT_PREFIX. */
332 oldname += strlen (DLL_IMPORT_PREFIX);
333 DECL_NON_ADDR_CONST_P (decl) = 0;
335 else if (i386_pe_dllexport_name_p (oldname))
336 return; /* already done */
338 newname = alloca (strlen (DLL_EXPORT_PREFIX) + strlen (oldname) + 1);
339 sprintf (newname, "%s%s", DLL_EXPORT_PREFIX, oldname);
341 /* We pass newname through get_identifier to ensure it has a unique
342 address. RTL processing can sometimes peek inside the symbol ref
343 and compare the string's addresses to see if two symbols are
345 idp = get_identifier (newname);
347 XEXP (DECL_RTL (decl), 0) =
348 gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (idp));
351 /* Mark a DECL as being dllimport'd. */
354 i386_pe_mark_dllimport (tree decl)
361 rtlname = XEXP (DECL_RTL (decl), 0);
362 if (GET_CODE (rtlname) == SYMBOL_REF)
363 oldname = XSTR (rtlname, 0);
364 else if (GET_CODE (rtlname) == MEM
365 && GET_CODE (XEXP (rtlname, 0)) == SYMBOL_REF)
366 oldname = XSTR (XEXP (rtlname, 0), 0);
369 if (i386_pe_dllexport_name_p (oldname))
371 error ("`%s' declared as both exported to and imported from a DLL",
372 IDENTIFIER_POINTER (DECL_NAME (decl)));
375 else if (i386_pe_dllimport_name_p (oldname))
377 /* Already done, but do a sanity check to prevent assembler errors. */
378 if (!DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
380 error ("%Hfailure in redeclaration of '%D': dllimport'd symbol lacks external linkage.",
381 &DECL_SOURCE_LOCATION (decl), decl);
387 newname = alloca (strlen (DLL_IMPORT_PREFIX) + strlen (oldname) + 1);
388 sprintf (newname, "%s%s", DLL_IMPORT_PREFIX, oldname);
390 /* We pass newname through get_identifier to ensure it has a unique
391 address. RTL processing can sometimes peek inside the symbol ref
392 and compare the string's addresses to see if two symbols are
394 idp = get_identifier (newname);
396 newrtl = gen_rtx (MEM, Pmode,
397 gen_rtx (SYMBOL_REF, Pmode,
398 IDENTIFIER_POINTER (idp)));
399 XEXP (DECL_RTL (decl), 0) = newrtl;
401 /* Can't treat a pointer to this as a constant address */
402 DECL_NON_ADDR_CONST_P (decl) = 1;
405 /* Return string which is the former assembler name modified with a
406 prefix consisting of FASTCALL_PREFIX and a suffix consisting of an
407 atsign (@) followed by the number of bytes of arguments. */
410 gen_fastcall_suffix (tree decl)
414 const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
417 if (TYPE_ARG_TYPES (TREE_TYPE (decl)))
418 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (decl))))
421 tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
423 /* Quit if we hit an incomplete type. Error is reported
424 by convert_arguments in c-typeck.c or cp/typeck.c. */
425 while (TREE_VALUE (formal_type) != void_type_node
426 && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))
429 = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
430 /* Must round up to include padding. This is done the same
431 way as in store_one_arg. */
432 parm_size = ((parm_size + PARM_BOUNDARY - 1)
433 / PARM_BOUNDARY * PARM_BOUNDARY);
435 formal_type = TREE_CHAIN (formal_type);
439 /* Assume max of 8 base 10 digits in the suffix. */
440 newsym = xmalloc (1 + strlen (asmname) + 1 + 8 + 1);
441 sprintf (newsym, "%c%s@%d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
442 return IDENTIFIER_POINTER (get_identifier (newsym));
445 /* Return string which is the former assembler name modified with a
446 suffix consisting of an atsign (@) followed by the number of bytes of
450 gen_stdcall_suffix (tree decl)
453 /* ??? This probably should use XSTR (XEXP (DECL_RTL (decl), 0), 0) instead
454 of DECL_ASSEMBLER_NAME. */
455 const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
458 if (TYPE_ARG_TYPES (TREE_TYPE (decl)))
459 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (decl))))
462 tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
464 /* Quit if we hit an incomplete type. Error is reported
465 by convert_arguments in c-typeck.c or cp/typeck.c. */
466 while (TREE_VALUE (formal_type) != void_type_node
467 && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))
470 = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
471 /* Must round up to include padding. This is done the same
472 way as in store_one_arg. */
473 parm_size = ((parm_size + PARM_BOUNDARY - 1)
474 / PARM_BOUNDARY * PARM_BOUNDARY);
476 formal_type = TREE_CHAIN (formal_type);
480 /* Assume max of 8 base 10 digits in the suffix. */
481 newsym = xmalloc (strlen (asmname) + 1 + 8 + 1);
482 sprintf (newsym, "%s@%d", asmname, total/BITS_PER_UNIT);
483 return IDENTIFIER_POINTER (get_identifier (newsym));
487 i386_pe_encode_section_info (tree decl, rtx rtl, int first)
489 default_encode_section_info (decl, rtl, first);
491 if (TREE_CODE (decl) == FUNCTION_DECL)
493 if (lookup_attribute ("stdcall",
494 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
495 XEXP (DECL_RTL (decl), 0) =
496 gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (decl));
497 else if (lookup_attribute ("fastcall",
498 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
499 XEXP (DECL_RTL (decl), 0) =
500 gen_rtx (SYMBOL_REF, Pmode, gen_fastcall_suffix (decl));
503 /* Mark the decl so we can tell from the rtl whether the object is
504 dllexport'd or dllimport'd. This also handles dllexport/dllimport
505 override semantics. */
507 if (i386_pe_dllexport_p (decl))
508 i386_pe_mark_dllexport (decl);
509 else if (i386_pe_dllimport_p (decl))
510 i386_pe_mark_dllimport (decl);
511 /* It might be that DECL has already been marked as dllimport, but a
512 subsequent definition nullified that. The attribute is gone but
513 DECL_RTL still has (DLL_IMPORT_PREFIX) prefixed. We need to remove
514 that. Ditto for the DECL_NON_ADDR_CONST_P flag. */
515 else if ((TREE_CODE (decl) == FUNCTION_DECL
516 || TREE_CODE (decl) == VAR_DECL)
517 && DECL_RTL (decl) != NULL_RTX
518 && GET_CODE (DECL_RTL (decl)) == MEM
519 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
520 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == SYMBOL_REF
521 && i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0)))
523 const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
524 /* Remove DLL_IMPORT_PREFIX. */
525 tree idp = get_identifier (oldname + strlen (DLL_IMPORT_PREFIX));
526 rtx newrtl = gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (idp));
528 warning ("%H%s '%D' %s after being referenced with dllimport linkage.",
529 &DECL_SOURCE_LOCATION (decl),
530 TREE_CODE (decl) == VAR_DECL ? "variable" : "function",
531 decl, (DECL_INITIAL (decl) || !DECL_EXTERNAL (decl))
532 ? "defined locally" : "redeclared without dllimport attribute");
534 XEXP (DECL_RTL (decl), 0) = newrtl;
536 DECL_NON_ADDR_CONST_P (decl) = 0;
538 /* We previously set TREE_PUBLIC and DECL_EXTERNAL.
539 We leave these alone for now. */
543 /* Strip only the leading encoding, leaving the stdcall suffix and fastcall
544 prefix if it exists. */
547 i386_pe_strip_name_encoding (const char *str)
549 if (strncmp (str, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
551 str += strlen (DLL_IMPORT_PREFIX);
552 else if (strncmp (str, DLL_EXPORT_PREFIX, strlen (DLL_EXPORT_PREFIX))
554 str += strlen (DLL_EXPORT_PREFIX);
560 /* Also strip the stdcall suffix. */
563 i386_pe_strip_name_encoding_full (const char *str)
566 const char *name = i386_pe_strip_name_encoding (str);
568 p = strchr (name, '@');
570 return ggc_alloc_string (name, p - name);
575 /* Output a reference to a label. Fastcall symbols are prefixed with @,
576 whereas symbols for functions using other calling conventions don't
577 have a prefix (unless they are marked dllimport or dllexport). */
579 void i386_pe_output_labelref (stream, name)
583 if (strncmp (name, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
587 if (name[strlen (DLL_IMPORT_PREFIX)] == FASTCALL_PREFIX)
588 /* A dllimport fastcall symbol. */
590 fprintf (stream, "__imp_%s",
591 i386_pe_strip_name_encoding (name));
594 /* A dllimport non-fastcall symbol. */
596 fprintf (stream, "__imp__%s",
597 i386_pe_strip_name_encoding (name));
600 else if ((name[0] == FASTCALL_PREFIX)
601 || (strncmp (name, DLL_EXPORT_PREFIX, strlen (DLL_EXPORT_PREFIX)
603 && name[strlen (DLL_EXPORT_PREFIX)] == FASTCALL_PREFIX)))
604 /* A fastcall symbol. */
606 fprintf (stream, "%s",
607 i386_pe_strip_name_encoding (name));
610 /* Everything else. */
612 fprintf (stream, "%s%s", USER_LABEL_PREFIX,
613 i386_pe_strip_name_encoding (name));
618 i386_pe_unique_section (tree decl, int reloc)
621 const char *name, *prefix;
624 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
625 name = i386_pe_strip_name_encoding_full (name);
627 /* The object is put in, for example, section .text$foo.
628 The linker will then ultimately place them in .text
629 (everything from the $ on is stripped). Don't put
630 read-only data in .rdata section to avoid a PE linker
631 bug when .rdata$* grouped sections are used in code
632 without a .rdata section. */
633 if (TREE_CODE (decl) == FUNCTION_DECL)
635 else if (decl_readonly_section (decl, reloc))
639 len = strlen (name) + strlen (prefix);
640 string = alloca (len + 1);
641 sprintf (string, "%s%s", prefix, name);
643 DECL_SECTION_NAME (decl) = build_string (len, string);
646 /* Select a set of attributes for section NAME based on the properties
647 of DECL and whether or not RELOC indicates that DECL's initializer
648 might contain runtime relocations.
650 We make the section read-only and executable for a function decl,
651 read-only for a const data decl, and writable for a non-const data decl.
653 If the section has already been defined, to not allow it to have
654 different attributes, as (1) this is ambiguous since we're not seeing
655 all the declarations up front and (2) some assemblers (e.g. SVR4)
656 do not recognize section redefinitions. */
657 /* ??? This differs from the "standard" PE implementation in that we
658 handle the SHARED variable attribute. Should this be done for all
661 #define SECTION_PE_SHARED SECTION_MACH_DEP
664 i386_pe_section_type_flags (tree decl, const char *name, int reloc)
670 /* The names we put in the hashtable will always be the unique
671 versions gived to us by the stringtable, so we can just use
672 their addresses as the keys. */
674 htab = htab_create (31, htab_hash_pointer, htab_eq_pointer, NULL);
676 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
677 flags = SECTION_CODE;
678 else if (decl && decl_readonly_section (decl, reloc))
682 flags = SECTION_WRITE;
684 if (decl && TREE_CODE (decl) == VAR_DECL
685 && lookup_attribute ("shared", DECL_ATTRIBUTES (decl)))
686 flags |= SECTION_PE_SHARED;
689 if (decl && DECL_ONE_ONLY (decl))
690 flags |= SECTION_LINKONCE;
692 /* See if we already have an entry for this section. */
693 slot = (unsigned int **) htab_find_slot (htab, name, INSERT);
696 *slot = (unsigned int *) xmalloc (sizeof (unsigned int));
701 if (decl && **slot != flags)
702 error ("%H'%D' causes a section type conflict",
703 &DECL_SOURCE_LOCATION (decl), decl);
710 i386_pe_asm_named_section (const char *name, unsigned int flags)
712 char flagchars[8], *f = flagchars;
714 if (flags & SECTION_CODE)
716 if (flags & SECTION_WRITE)
718 if (flags & SECTION_PE_SHARED)
722 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
724 if (flags & SECTION_LINKONCE)
726 /* Functions may have been compiled at various levels of
727 optimization so we can't use `same_size' here.
728 Instead, have the linker pick one. */
729 fprintf (asm_out_file, "\t.linkonce %s\n",
730 (flags & SECTION_CODE ? "discard" : "same_size"));
734 /* The Microsoft linker requires that every function be marked as
735 DT_FCN. When using gas on cygwin, we must emit appropriate .type
740 /* Mark a function appropriately. This should only be called for
741 functions for which we are not emitting COFF debugging information.
742 FILE is the assembler output file, NAME is the name of the
743 function, and PUBLIC is nonzero if the function is globally
747 i386_pe_declare_function_type (FILE *file, const char *name, int public)
749 fprintf (file, "\t.def\t");
750 assemble_name (file, name);
751 fprintf (file, ";\t.scl\t%d;\t.type\t%d;\t.endef\n",
752 public ? (int) C_EXT : (int) C_STAT,
753 (int) DT_FCN << N_BTSHFT);
756 /* Keep a list of external functions. */
760 struct extern_list *next;
764 static struct extern_list *extern_head;
766 /* Assemble an external function reference. We need to keep a list of
767 these, so that we can output the function types at the end of the
768 assembly. We can't output the types now, because we might see a
769 definition of the function later on and emit debugging information
773 i386_pe_record_external_function (const char *name)
775 struct extern_list *p;
777 p = (struct extern_list *) xmalloc (sizeof *p);
778 p->next = extern_head;
783 /* Keep a list of exported symbols. */
787 struct export_list *next;
789 int is_data; /* used to type tag exported symbols. */
792 static struct export_list *export_head;
794 /* Assemble an export symbol entry. We need to keep a list of
795 these, so that we can output the export list at the end of the
796 assembly. We used to output these export symbols in each function,
797 but that causes problems with GNU ld when the sections are
801 i386_pe_record_exported_symbol (const char *name, int is_data)
803 struct export_list *p;
805 p = (struct export_list *) xmalloc (sizeof *p);
806 p->next = export_head;
808 p->is_data = is_data;
812 /* This is called at the end of assembly. For each external function
813 which has not been defined, we output a declaration now. We also
814 output the .drectve section. */
817 i386_pe_file_end (void)
819 struct extern_list *p;
823 for (p = extern_head; p != NULL; p = p->next)
827 decl = get_identifier (p->name);
829 /* Positively ensure only one declaration for any given symbol. */
830 if (! TREE_ASM_WRITTEN (decl) && TREE_SYMBOL_REFERENCED (decl))
832 TREE_ASM_WRITTEN (decl) = 1;
833 i386_pe_declare_function_type (asm_out_file, p->name,
840 struct export_list *q;
842 for (q = export_head; q != NULL; q = q->next)
844 fprintf (asm_out_file, "\t.ascii \" -export:%s%s\"\n",
845 i386_pe_strip_name_encoding (q->name),
846 (q->is_data) ? ",data" : "");