From a20f6f00bf53a4debcbf361256ed098f8e930850 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Fri, 1 Apr 2005 08:13:50 +0000 Subject: cygming.h (SUBTARGET_ATTRIBUTE_TABLE): Define, with entry for selectany attribute. * config/i386/cygming.h (SUBTARGET_ATTRIBUTE_TABLE): Define, with entry for selectany attribute. * config/i386/i386-protos.h (ix86_handle_selectany_attribute): Declare. * config/i386/winnt.c (ix86_handle_selectany_attribute): Define. (i386_pe_asm_named_section): Handle sections generated by selectany attribute. * doc/extend.texi (selectany): Document attribute. From-SVN: r97377 --- gcc/config/i386/cygming.h | 4 ++++ gcc/config/i386/i386-protos.h | 1 + gcc/config/i386/winnt.c | 44 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 4 deletions(-) (limited to 'gcc/config') diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h index a354994..de731bb 100644 --- a/gcc/config/i386/cygming.h +++ b/gcc/config/i386/cygming.h @@ -418,6 +418,10 @@ extern int i386_pe_dllimport_name_p (const char *); #undef TARGET_USE_LOCAL_THUNK_ALIAS_P #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL)) +#define SUBTARGET_ATTRIBUTE_TABLE \ + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \ + { "selectany", 0, 0, true, false, false, ix86_handle_selectany_attribute } + #undef TREE #ifndef BUFSIZ diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index bf69386..1ecc3ae 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -216,6 +216,7 @@ extern int ix86_data_alignment (tree, int); extern int ix86_local_alignment (tree, int); extern int ix86_constant_alignment (tree, int); extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *); +extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *); extern unsigned int i386_pe_section_type_flags (tree, const char *, int); extern void i386_pe_asm_named_section (const char *, unsigned int, tree); diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c index c8a7544..ebd8db7 100644 --- a/gcc/config/i386/winnt.c +++ b/gcc/config/i386/winnt.c @@ -78,6 +78,36 @@ ix86_handle_shared_attribute (tree *node, tree name, return NULL_TREE; } + +/* Handle a "selectany" attribute; + arguments as in struct attribute_spec.handler. */ +tree +ix86_handle_selectany_attribute (tree *node, tree name, + tree args ATTRIBUTE_UNUSED, + int flags ATTRIBUTE_UNUSED, + bool *no_add_attrs) +{ + /* The attribute applies only to objects that are initialized and have + external linkage, */ + if (TREE_CODE (*node) == VAR_DECL && TREE_PUBLIC (*node) + && (DECL_INITIAL (*node) + /* If an object is initialized with a ctor, the static + initialization and destruction code for it is present in + each unit defining the object. The code that calls the + ctor is protected by a link-once guard variable, so that + the object still has link-once semantics, */ + || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (*node)))) + make_decl_one_only (*node); + else + { + error ("%qs attribute applies only to initialized variables" + " with external linkage", IDENTIFIER_POINTER (name)); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Return the type that we should use to determine if DECL is imported or exported. */ @@ -622,7 +652,7 @@ i386_pe_section_type_flags (tree decl, const char *name, int reloc) void i386_pe_asm_named_section (const char *name, unsigned int flags, - tree decl ATTRIBUTE_UNUSED) + tree decl) { char flagchars[8], *f = flagchars; @@ -649,10 +679,16 @@ i386_pe_asm_named_section (const char *name, unsigned int flags, if (flags & SECTION_LINKONCE) { /* Functions may have been compiled at various levels of - optimization so we can't use `same_size' here. - Instead, have the linker pick one. */ + optimization so we can't use `same_size' here. + Instead, have the linker pick one, without warning. + If 'selectany' attibute has been specified, MS compiler + sets 'discard' characteristic, rather than telling linker + to warn of size or content mismatch, so do the same. */ + bool discard = (flags & SECTION_CODE) + || lookup_attribute ("selectany", + DECL_ATTRIBUTES (decl)); fprintf (asm_out_file, "\t.linkonce %s\n", - (flags & SECTION_CODE ? "discard" : "same_size")); + (discard ? "discard" : "same_size")); } } -- cgit v1.1