* tree.c (handle_dll_attribute): Move here from i383/winnt.c.
Replace use of DECL_INLINE with DECL_DECLARED_INLINE_P. Set
DECL_VISIBLITY. Test TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
* tree.h (handle_dll_attribute): Declare. Test
TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
* c-common.h (c_determine_visibility): Declare.
* c-common.c (c_determine_visibility): New function.
* c-decl.c (finish_decl): Use it.
(finish_function): Likewise.
* defaults.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define it to
zero, by default. Use #if, not #ifdef, to test it.
* config/arm/arm.c (arm_attribute_table): Use
handle_dll_attribute. Test TARGET_DLLIMPORT_DECL_ATTRIBUTES with
#if.
* config/arm/pe.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define to 1.
* config/i386/cygming.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
to 1.
* config/i386/i386-protos.h (ix86_handle_dll_attribute): Remove.
* config/i386/i386.c (ix86_attribute_table): Use
handle_dll_attribute for dllimport/dllexport. Test
TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
* config/i386/winnt.c (ix86_handle_dll_attribute): Remove.
* config/mcore/mcore.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
it to 1.
* config/mcore/mcore.c (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Test it
with #if.
* config/sh/symbian-pre.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
it to 1.
* doc/extend.texi (dllexport): Clarify and correct documentation.
(dllimport): Likewise.
* doc/tm.texi (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Mention
handle_dll_attribute.
* decl.c (start_preparsed_function): Move determine_visibility
call.
* decl2.c (determine_visibility): Incorporate dllexport testing.
* g++.dg/ext/visibility/assign1.C: Use scan-hidden and
dg-require-visiblity.
* g++.dg/ext/visibility/fvisibility-inlines-hidden.C: Likewise.
* g++.dg/ext/visibility/fvisibility.C: Likewise.
* g++.dg/ext/visibility/memfuncts.C: Likewise.
* g++.dg/ext/visibility/new1.C: Likewise.
* g++.dg/ext/visibility/pragma.C: Likewise.
* g++.dg/ext/visibility/staticmemfuncts.C: Likewise.
* g++.dg/ext/visibility/virtual.C: Likewise.
* g++/dg/ext/visibility/visibility-1.C: Likewise.
* g++/dg/ext/visibility/visibility-2.C: Likewise.
* g++/dg/ext/visibility/visibility-3.C: Likewise.
* g++/dg/ext/visibility/visibility-4.C: Likewise.
* g++/dg/ext/visibility/visibility-5.C: Likewise.
* g++/dg/ext/visibility/visibility-6.C: Likewise.
* g++/dg/ext/visibility/visibility-7.C: Likewise.
* g++/dg/ext/visibility/visibility-8.C: New test.
* gcc.c-torture/compile/dll.x: Remove.
* gcc.dg/dll-2.c: Use dg-require-dll
* gcc.dg/visibility-10.c: New test.
* lib/gcc-dg.exp (dg-require-dll): Add Symbian to list of targets
supporting DLLs.
* testsuite/lib/scanasm.exp (scan_hidden): New function.
(scan_not_hidden): Likewise.
From-SVN: r85621
+2004-08-05 Mark Mitchell <mark@codesourcery.com>
+
+ * tree.c (handle_dll_attribute): Move here from i383/winnt.c.
+ Replace use of DECL_INLINE with DECL_DECLARED_INLINE_P. Set
+ DECL_VISIBLITY. Test TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
+ * tree.h (handle_dll_attribute): Declare. Test
+ TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
+ * c-common.h (c_determine_visibility): Declare.
+ * c-common.c (c_determine_visibility): New function.
+ * c-decl.c (finish_decl): Use it.
+ (finish_function): Likewise.
+ * defaults.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define it to
+ zero, by default. Use #if, not #ifdef, to test it.
+ * config/arm/arm.c (arm_attribute_table): Use
+ handle_dll_attribute. Test TARGET_DLLIMPORT_DECL_ATTRIBUTES with
+ #if.
+ * config/arm/pe.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define to 1.
+ * config/i386/cygming.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
+ to 1.
+ * config/i386/i386-protos.h (ix86_handle_dll_attribute): Remove.
+ * config/i386/i386.c (ix86_attribute_table): Use
+ handle_dll_attribute for dllimport/dllexport. Test
+ TARGET_DLLIMPORT_DECL_ATTRIBUTES with #if.
+ * config/i386/winnt.c (ix86_handle_dll_attribute): Remove.
+ * config/mcore/mcore.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
+ it to 1.
+ * config/mcore/mcore.c (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Test it
+ with #if.
+ * config/sh/symbian-pre.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define
+ it to 1.
+ * doc/extend.texi (dllexport): Clarify and correct documentation.
+ (dllimport): Likewise.
+ * doc/tm.texi (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Mention
+ handle_dll_attribute.
+
2004-08-05 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
* tree-ssa-loop-manip.c: New file.
* defaults.h (TARGET_DECLSPEC): New macro.
* c-cppbuiltin.c (c_cpp_builtins): Handle TARGET_DECLSPEC.
* config/arm/pe.h (SUBTARGET_CPP_SPEC): Remove __declspec support.
- * config/arm/symbian. (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define.
+ * config/arm/symbian.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define.
* config/i386/beof-elf.h (TARGET_OS_CPP_BUILTINS): Remove
__declspec support.
(TARGET_DECLSPEC): Define.
return NULL_TREE;
}
+/* Determine the ELF symbol visibility for DECL, which is either a
+ variable or a function. It is an error to use this function if a
+ definition of DECL is not available in this translation unit.
+ Returns true if the final visibility has been determined by this
+ function; false if the caller is free to make additional
+ modifications. */
+
+bool
+c_determine_visibility (tree decl)
+{
+ my_friendly_assert (TREE_CODE (decl) == VAR_DECL
+ || TREE_CODE (decl) == FUNCTION_DECL,
+ 20040805);
+
+ /* If the user explicitly specified the visibility with an
+ attribute, honor that. DECL_VISIBILITY will have been set during
+ the processing of the attribute. We check for an explicit
+ attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
+ to distinguish the use of an attribute from the use of a "#pragma
+ GCC visibility push(...)"; in the latter case we still want other
+ considerations to be able to overrule the #pragma. */
+ if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)))
+ return true;
+
+ /* Anything that is exported must have default visibility. */
+ if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
+ {
+ DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
+ DECL_VISIBILITY_SPECIFIED (decl) = 1;
+ return true;
+ }
+
+ return false;
+}
+
/* Handle an "tls_model" attribute; arguments as in
struct attribute_spec.handler. */
extern tree convert_and_check (tree, tree);
extern void overflow_warning (tree);
extern void unsigned_conversion_warning (tree, tree);
+extern bool c_determine_visibility (tree);
#define c_sizeof(T) c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 1)
#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR, 1)
if (current_scope == file_scope)
maybe_apply_pragma_weak (decl);
+ /* If this is a variable definition, determine its ELF visibility. */
+ if (TREE_CODE (decl) == VAR_DECL
+ && TREE_STATIC (decl)
+ && !DECL_EXTERNAL (decl))
+ c_determine_visibility (decl);
+
/* Output the assembler code and/or RTL code for variables and functions,
unless the type is an undefined structure or union.
If not, it will get done when the type is completed. */
&& !targetm.have_ctors_dtors)
static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
+ /* Finalize the ELF visibility for the function. */
+ c_determine_visibility (fndecl);
+
/* Genericize before inlining. Delay genericizing nested functions
until their parent function is genericized. Since finalizing
requires GENERIC, delay that as well. */
\f
/* Initialize the GCC target structure. */
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
#undef TARGET_MERGE_DECL_ATTRIBUTES
#define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
#endif
{ "dllimport", 0, 0, true, false, false, NULL },
{ "dllexport", 0, 0, true, false, false, NULL },
{ "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
+#elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
+ { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
#endif
{ NULL, 0, 0, false, false, false, NULL }
};
/* Get tree.c to declare a target-specific specialization of
merge_decl_attributes. */
-#define TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
#undef SUBTARGET_CPP_SPEC
#define SUBTARGET_CPP_SPEC "-D__pe__"
/* Get tree.c to declare a target-specific specialization of
merge_decl_attributes. */
-#define TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
/* This macro defines names of additional specifications to put in the specs
that can be used in various specifications like CC1_SPEC. Its definition
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_dll_attribute (tree *, tree, tree, int, bool *);
extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
extern unsigned int i386_pe_section_type_flags (tree, const char *, int);
/* Initialize the GCC target structure. */
#undef TARGET_ATTRIBUTE_TABLE
#define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
# undef TARGET_MERGE_DECL_ATTRIBUTES
# define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
#endif
/* Regparm attribute specifies how many integer arguments are to be
passed in registers. */
{ "regparm", 1, 1, false, true, true, ix86_handle_regparm_attribute },
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
- { "dllimport", 0, 0, false, false, false, ix86_handle_dll_attribute },
- { "dllexport", 0, 0, false, false, false, ix86_handle_dll_attribute },
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
+ { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
{ "shared", 0, 0, true, false, false, ix86_handle_shared_attribute },
#endif
{ "ms_struct", 0, 0, false, false, false, ix86_handle_struct_attribute },
#define DLL_EXPORT_PREFIX "#e."
#endif
-/* Handle a "dllimport" or "dllexport" attribute;
- arguments as in struct attribute_spec.handler. */
-tree
-ix86_handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
- bool *no_add_attrs)
-{
- tree node = *pnode;
-
- /* These attributes may apply to structure and union types being created,
- but otherwise should pass to the declaration involved. */
- if (!DECL_P (node))
- {
- if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
- | (int) ATTR_FLAG_ARRAY_NEXT))
- {
- *no_add_attrs = true;
- return tree_cons (name, args, NULL_TREE);
- }
- if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
- {
- warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
- *no_add_attrs = true;
- }
-
- return NULL_TREE;
- }
-
- /* Report error on dllimport ambiguities seen now before they cause
- any damage. */
- else if (is_attribute_p ("dllimport", name))
- {
- /* Like MS, treat definition of dllimported variables and
- non-inlined functions on declaration as syntax errors.
- We allow the attribute for function definitions if declared
- inline, but just ignore it in i386_pe_dllimport_p. */
- if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
- && !DECL_INLINE (node))
- {
- error ("%Jfunction `%D' definition is marked dllimport.", node, node);
- *no_add_attrs = true;
- }
-
- else if (TREE_CODE (node) == VAR_DECL)
- {
- if (DECL_INITIAL (node))
- {
- error ("%Jvariable `%D' definition is marked dllimport.",
- node, node);
- *no_add_attrs = true;
- }
-
- /* `extern' needn't be specified with dllimport.
- Specify `extern' now and hope for the best. Sigh. */
- DECL_EXTERNAL (node) = 1;
- /* Also, implicitly give dllimport'd variables declared within
- a function global scope, unless declared static. */
- if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
- TREE_PUBLIC (node) = 1;
- }
- }
-
- /* Report error if symbol is not accessible at global scope. */
- if (!TREE_PUBLIC (node)
- && (TREE_CODE (node) == VAR_DECL
- || TREE_CODE (node) == FUNCTION_DECL))
- {
- error ("%Jexternal linkage required for symbol '%D' because of "
- "'%s' attribute.", node, node, IDENTIFIER_POINTER (name));
- *no_add_attrs = true;
- }
-
- return NULL_TREE;
-}
-
/* Handle a "shared" attribute;
arguments as in struct attribute_spec.handler. */
tree
#undef TARGET_ASM_EXTERNAL_LIBCALL
#define TARGET_ASM_EXTERNAL_LIBCALL mcore_external_libcall
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
#undef TARGET_MERGE_DECL_ATTRIBUTES
#define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
#endif
/* Get tree.c to declare a target-specific specialization of
merge_decl_attributes. */
-#define TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
#define TARGET_CPU_CPP_BUILTINS() \
do \
#define SUBTARGET_CPP_SPEC ""
/* Get tree.c to declare merge_dllimport_decl_attributes(). */
-#define TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
/* The Symbian OS currently does not support exception handling. */
#define SUBTARGET_CC1PLUS_SPEC "-fno-exceptions"
+2004-08-05 Mark Mitchell <mark@codesourcery.com>
+
+ * decl.c (start_preparsed_function): Move determine_visibility
+ call.
+ * decl2.c (determine_visibility): Incorporate dllexport testing.
+
2004-08-05 Geoffrey Keating <geoffk@apple.com>
* g++spec.c (lang_specific_driver): An -Xlinker or -Wl, option
&& lookup_attribute ("noinline", attrs))
warning ("%Jinline function '%D' given attribute noinline", decl1, decl1);
- /* Determine the ELF visibility attribute for the function. */
- determine_visibility (decl1);
-
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
/* This is a constructor, we must ensure that any default args
introduced by this definition are propagated to the clones
fntype = TREE_TYPE (decl1);
}
+ /* Determine the ELF visibility attribute for the function. We must
+ not do this before calling "pushdecl", as we must allow
+ "duplicate_decls" to merge any attributes appropriately. */
+ if (!DECL_CLONED_FUNCTION_P (decl1))
+ determine_visibility (decl1);
+
/* Reset these in case the call to pushdecl changed them. */
current_function_decl = decl1;
cfun->decl = decl1;
return true;
}
-/* Determine the ELF symbol visibility for DECL. */
+/* Like c_determine_visibility, but with additional C++-specific
+ behavior. */
void
determine_visibility (tree decl)
/* Cloned constructors and destructors get the same visibility as
the underlying function. That should be set up in
maybe_clone_body. */
- if (DECL_CLONED_FUNCTION_P (decl))
+ my_friendly_assert (!DECL_CLONED_FUNCTION_P (decl), 20040804);
+
+ /* Give the common code a chance to make a determination. */
+ if (c_determine_visibility (decl))
return;
+ /* If DECL is a member of a class, visibility specifiers on the
+ class can influence the visibility of the DECL. */
if (DECL_CLASS_SCOPE_P (decl))
class_type = DECL_CONTEXT (decl);
else if (TREE_CODE (decl) == VAR_DECL
/* By default, static data members and function members receive
the visibility of their containing class. */
- if (class_type
- && (TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == FUNCTION_DECL)
- && !lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)))
+ if (class_type)
{
+ if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type)))
+ {
+ DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
+ DECL_VISIBILITY_SPECIFIED (decl) = 1;
+ return;
+ }
+
if (TREE_CODE (decl) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl)
&& visibility_options.inlines_hidden)
#define PIC_OFFSET_TABLE_REGNUM INVALID_REGNUM
#endif
+#ifndef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#define TARGET_DLLIMPORT_DECL_ATTRIBUTES 0
+#endif
+
#ifndef TARGET_DECLSPEC
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
/* If the target supports the "dllimport" attribute, users are
probably used to the "__declspec" syntax. */
#define TARGET_DECLSPEC 1
@item dllexport
@cindex @code{__declspec(dllexport)}
-On Microsoft Windows targets and Symbian targets the @code{dllexport}
-attribute causes the compiler to provide a global pointer to a pointer
-in a dll, so that it can be referenced with the @code{dllimport}
-attribute. The pointer name is formed by combining @code{_imp__} and
-the function or variable name.
+On Microsoft Windows targets and Symbian OS targets the
+@code{dllexport} attribute causes the compiler to provide a global
+pointer to a pointer in a DLL, so that it can be referenced with the
+@code{dllimport} attribute. On Microsoft Windows targets, the pointer
+name is formed by combining @code{_imp__} and the function or variable
+name.
+
+You can use @code{__declspec(dllexport)} as a synonym for
+@code{__attribute__ ((dllexport))} for compatibility with other
+compilers.
+
+On systems that support the @code{visibility} attribute, this
+attribute also implies ``default'' visibility, unless a
+@code{visibility} attribute is explicitly specified. You should avoid
+the use of @code{dllexport} with ``hidden'' or ``internal''
+visibility; in the future GCC may issue an error for those cases.
-Currently, the @code{dllexport}attribute is ignored for inlined
-functions, but export can be forced by using the
-@option{-fkeep-inline-functions} flag. The attribute is also ignored for
-undefined symbols.
+Currently, the @code{dllexport} attribute is ignored for inlined
+functions, unless the @option{-fkeep-inline-functions} flag has been
+used. The attribute is also ignored for undefined symbols.
When applied to C++ classes. the attribute marks defined non-inlined
member functions and static data members as exports. Static consts
initialized in-class are not marked unless they are also defined
out-of-class.
-On cygwin, mingw, arm-pe and sh-symbianelf targets,
-@code{__declspec(dllexport)} is recognized as a synonym for
-@code{__attribute__ ((dllexport))} for compatibility with other
-Microsoft Windows and Symbian compilers.
-
For Microsoft Windows targets there are alternative methods for
-including the symbol in the dll's export table such as using a
+including the symbol in the DLL's export table such as using a
@file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
the @option{--export-all} linker flag.
@item dllimport
@cindex @code{__declspec(dllimport)}
-On Microsoft Windows and Symbian targets, the @code{dllimport}
+On Microsoft Windows and Symbian OS targets, the @code{dllimport}
attribute causes the compiler to reference a function or variable via
-a global pointer to a pointer that is set up by the Microsoft Windows
-dll library. The pointer name is formed by combining @code{_imp__} and
-the function or variable name. The attribute implies @code{extern}
-storage.
+a global pointer to a pointer that is set up by the DLL exporting the
+symbol. The attribute implies @code{extern} storage. On Microsoft
+Windows targets, the pointer name is formed by combining @code{_imp__}
+and the function or variable name.
+
+You can use @code{__declspec(dllimport)} as a synonym for
+@code{__attribute__ ((dllimport))} for compatibility with other
+compilers.
Currently, the attribute is ignored for inlined functions. If the
attribute is applied to a symbol @emph{definition}, an error is reported.
attribute is ignored for virtual methods to allow creation of vtables
using thunks.
-For Symbian targets the @code{dllimport} attribute also has another
-affect - it can cause the vtable and run-time type information for a
-class to be exported. This happens when the class has a dllimport'ed
-constructor or a non-inline, non-pure virtual function and, for either
-of those two conditions, the class also has a inline constructor or
-destructor and has a key function that is defined in the current
-translation unit.
-
-On cygwin, mingw, arm-pe sh-symbianelf targets,
-@code{__declspec(dllimport)} is recognized as a synonym for
-@code{__attribute__ ((dllimport))} for compatibility with other
-Microsoft Windows and Symbian compilers.
+On the SH Symbian OS target the @code{dllimport} attribute also has
+another affect - it can cause the vtable and run-time type information
+for a class to be exported. This happens when the class has a
+dllimport'ed constructor or a non-inline, non-pure virtual function
+and, for either of those two conditions, the class also has a inline
+constructor or destructor and has a key function that is defined in
+the current translation unit.
For Microsoft Windows based targets the use of the @code{dllimport}
attribute on functions is not necessary, but provides a small
-performance benefit by eliminating a thunk in the dll. The use of the
+performance benefit by eliminating a thunk in the DLL. The use of the
@code{dllimport} attribute on imported variables was required on older
-versions of GNU ld, but can now be avoided by passing the
-@option{--enable-auto-import} switch to ld. As with functions, using
-the attribute for a variable eliminates a thunk in the dll.
-
-One drawback to using this attribute is that a pointer to a function or
-variable marked as dllimport cannot be used as a constant address. The
-attribute can be disabled for functions by setting the
-@option{-mnop-fun-dllimport} flag.
+versions of the GNU linker, but can now be avoided by passing the
+@option{--enable-auto-import} switch to the GNU linker. As with
+functions, using the attribute for a variable eliminates a thunk in
+the DLL.
+
+One drawback to using this attribute is that a pointer to a function
+or variable marked as @code{dllimport} cannot be used as a constant
+address. On Microsoft Windows targets, the attribute can be disabled
+for functions by setting the @option{-mnop-fun-dllimport} flag.
@item eightbit_data
@cindex eight bit data on the H8/300, H8/300H, and H8S
call @code{merge_attributes} to handle machine-independent merging.
@findex TARGET_DLLIMPORT_DECL_ATTRIBUTES
-If the only target-specific handling you require is @samp{dllimport} for
-Microsoft Windows targets, you should define the macro
-@code{TARGET_DLLIMPORT_DECL_ATTRIBUTES}. This links in a function
-called @code{merge_dllimport_decl_attributes} which can then be defined
-as the expansion of @code{TARGET_MERGE_DECL_ATTRIBUTES}. This is done
-in @file{i386/cygwin.h} and @file{i386/i386.c}, for example.
+If the only target-specific handling you require is @samp{dllimport}
+for Microsoft Windows targets, you should define the macro
+@code{TARGET_DLLIMPORT_DECL_ATTRIBUTES} to @code{1}. The compiler
+will then define a function called
+@code{merge_dllimport_decl_attributes} which can then be defined as
+the expansion of @code{TARGET_MERGE_DECL_ATTRIBUTES}. You can also
+add @code{handle_dll_attribute} in the attribute table for your port
+to perform initial processing of the @samp{dllimport} and
+@samp{dllexport} attributes. This is done in @file{i386/cygwin.h} and
+@file{i386/i386.c}, for example.
@end deftypefn
@defmac TARGET_DECLSPEC
+2004-08-05 Mark Mitchell <mark@codesourcery.com>
+
+ * g++.dg/ext/visibility/assign1.C: Use scan-hidden and
+ dg-require-visiblity.
+ * g++.dg/ext/visibility/fvisibility-inlines-hidden.C: Likewise.
+ * g++.dg/ext/visibility/fvisibility.C: Likewise.
+ * g++.dg/ext/visibility/memfuncts.C: Likewise.
+ * g++.dg/ext/visibility/new1.C: Likewise.
+ * g++.dg/ext/visibility/pragma.C: Likewise.
+ * g++.dg/ext/visibility/staticmemfuncts.C: Likewise.
+ * g++.dg/ext/visibility/virtual.C: Likewise.
+ * g++/dg/ext/visibility/visibility-1.C: Likewise.
+ * g++/dg/ext/visibility/visibility-2.C: Likewise.
+ * g++/dg/ext/visibility/visibility-3.C: Likewise.
+ * g++/dg/ext/visibility/visibility-4.C: Likewise.
+ * g++/dg/ext/visibility/visibility-5.C: Likewise.
+ * g++/dg/ext/visibility/visibility-6.C: Likewise.
+ * g++/dg/ext/visibility/visibility-7.C: Likewise.
+ * g++/dg/ext/visibility/visibility-8.C: New test.
+ * gcc.c-torture/compile/dll.x: Remove.
+ * gcc.dg/dll-2.c: Use dg-require-dll
+ * gcc.dg/visibility-10.c: New test.
+ * lib/gcc-dg.exp (dg-require-dll): Add Symbian to list of targets
+ supporting DLLs.
+ * testsuite/lib/scanasm.exp (scan_hidden): New function.
+ (scan_not_hidden): Likewise.
+
2004-08-05 David Edelsohn <edelsohn@gnu.org>
* gcc.dg/sh4a-fprun.c: Fix dg-do typo.
/* { dg-do compile } */
/* { dg-require-visibility "" } */
-/* { dg-final { scan-assembler "\\.hidden.*_ZN1DaSERKS_" } } */
+/* { dg-final { scan-hidden "_ZN1DaSERKS_" } } */
struct B {
B& operator=(const B&);
/* { dg-do compile } */
/* { dg-require-visibility "" } */
/* { dg-options "-fvisibility-inlines-hidden" } */
-/* { dg-final { scan-assembler "\\.hidden.*Foo.methodEv" } } */
+/* { dg-final { scan-hidden "_ZN3Foo6methodEv" } } */
class Foo
{
/* { dg-do compile } */
/* { dg-require-visibility "" } */
/* { dg-options "-fvisibility=hidden" } */
-/* { dg-final { scan-assembler "\\.hidden.*Foo.methodEv" } } */
+/* { dg-final { scan-hidden "_ZN3Foo6methodEv" } } */
class Foo
{
/* Test that setting visibility for class member functions works. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
-/* { dg-final { scan-assembler "\\.hidden.*Foo.methodEv" } } */
+/* { dg-final { scan-hidden "_ZN3Foo6methodEv" } } */
class __attribute__ ((visibility ("hidden"))) Foo
{
-// { dg-require-visibility }
-// { dg-do compile }
+// { dg-require-visibility "" }
// { dg-options "-fvisibility=hidden" }
-// { dg-final { scan-assembler-not "\\.hidden\[^\n\]*_Znwj" } }
+// { dg-final { scan-not-hidden "_Znwj" } }
void f() {
new int;
/* Test that #pragma GCC visibility affects class members. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
-/* { dg-final { scan-assembler "\\.hidden.*Foo.methodEv" } } */
+/* { dg-final { scan-hidden "_ZN3Foo6methodEv" } } */
#pragma GCC visibility push(hidden)
class Foo
/* Test that setting visibility for static class member functions works. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
-/* { dg-final { scan-assembler "\\.hidden.*Foo.methodEv" } } */
+/* { dg-final { scan-hidden "_ZN3Foo6methodEv" } } */
class __attribute__ ((visibility ("hidden"))) Foo
{
/* Test that setting visibility for class affects virtual table. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
-/* { dg-final { scan-assembler "\\.hidden.*ZTV3Foo" } } */
+/* { dg-final { scan-hidden "ZTV3Foo" } } */
class __attribute__ ((visibility ("hidden"))) Foo
{
/* Test visibility attribute on function definition. */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "_Z3foov" } } */
void
__attribute__((visibility ("hidden")))
/* Test that visibility attribute on declaration extends to definition. */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "_Z3foov" } } */
void __attribute__((visibility ("hidden"))) foo();
/* Test visibility attribute on forward declaration of global variable */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "xyzzy" } } */
int
__attribute__((visibility ("hidden")))
/* Test visibility attribute on forward declaration of global variable */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "xyzzy" } } */
extern int __attribute__ ((visibility ("hidden")))
xyzzy;
/* Test visibility attribute on definition of a function that has
already had a forward declaration. */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "_Z3foov" } } */
void foo();
/* Test visibility attribute on definition of global variable that has
already had a forward declaration. */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */
+/* { dg-require-visibility "" }
+/* { dg-final { scan-hidden "xyzzy" } } */
extern int xyzzy;
/* Test warning from conflicting visibility specifications. */
-/* { dg-do compile { target *86-*-linux* } } */
-/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */
+/* { dg-require-visibility "" } */
+/* { dg-final { scan-hidden "xyzzy" } } */
extern int
__attribute__((visibility ("hidden")))
--- /dev/null
+// Test that a definition marked with dllexport has default
+// visibility.
+// { dg-require-visibility "" }
+// { dg-require-dll "" }
+// { dg-options "-fvisibility=hidden" }
+// { dg-final { scan-not-hidden "_ZN1A1fEv" } }
+// { dg-final { scan-not-hidden "_Z1gv" } }
+// { dg-final { scan-not-hidden "_Z1hv" } }
+// { dg-final { scan-not-hidden "_ZN1B1iEv" } }
+// { dg-final { scan-not-hidden "_ZN1B1jEv" } }
+// { dg-final { scan-not-hidden "_ZN1A1a" } }
+// { dg-final { scan-not-hidden "_ZN1B1b" } }
+// { dg-final { scan-not-hidden "k" } }
+// { dg-final { scan-not-hidden "l" } }
+
+struct __declspec(dllexport) A {
+ void f();
+ static int a;
+};
+
+void A::f() {}
+
+int A::a;
+
+__declspec(dllexport) void g() {}
+
+__declspec(dllexport) void h();
+void h() {}
+
+struct B {
+ void i();
+ __declspec(dllexport) void j();
+ __declspec(dllexport) static int b;
+};
+
+__declspec(dllexport) void B::i() {}
+
+void B::j() {}
+
+int B::b;
+
+__declspec(dllexport) int k;
+
+__declspec(dllexport) extern int l;
+int l;
+++ /dev/null
-# This test examines the attribute support for DLLs.
-# Only COFF/PE formats support DLLs, (plus, as a special case
-# the mcore-elf toolchain), so the code here tries to determine
-# the file format and decide whether the test should be marked
-# as unsupported.
-
-set torture_eval_before_compile {
-
- if ![istarget "mcore-*-elf"] {
-
- set objformat [gcc_target_object_format]
-
- if { $objformat != "pe" } {
- unsupported "dll.c"
- return 1
- }
- }
-}
-
-return 0
In C, it's ok to redeclare a variable so this works for variables
and functions. In C++, it only works for functions. */
-/* { dg-do compile { target arm*-*-pe* } } */
-/* { dg-do compile { target i?86-pc-cygwin } } */
-/* { dg-do compile { target i?86-pc-mingw* } } */
+/* { dg-require-dll } */
__declspec (dllimport) int foo1 ();
__declspec (dllexport) int foo1 ();
--- /dev/null
+/* Test that a definition marked with dllexport has default
+ visibility. */
+/* { dg-require-visibility "" } */
+/* { dg-require-dll "" } */
+/* { dg-options "-fvisibility=hidden" } */
+/* { dg-final { scan-not-hidden "g" } } */
+/* { dg-final { scan-not-hidden "h" } } */
+/* { dg-final { scan-not-hidden "k" } } */
+/* { dg-final { scan-not-hidden "l" } } */
+
+__declspec(dllexport) void g() {}
+
+__declspec(dllexport) void h();
+void h() {}
+
+__declspec(dllexport) int k;
+
+__declspec(dllexport) extern int l;
+int l;
proc dg-require-dll { args } {
global target_triplet
- # As a special case, the mcore-*-elf supports dllimport/dllexport.
- if { [string match "mcore-*-elf" $target_triplet] } {
+ # As a special case, the mcore-*-elf supports these attributes.
+ # All Symbian OS targets also support these attributes.
+ if { [string match "mcore-*-elf" $target_triplet]
+ || [string match "*-*-symbianelf" $target_triplet]} {
return
}
# PE/COFF targets support dllimport/dllexport.
dg-scan "scan-assembler-not" 0 $testcase $output_file $args
}
+# Check that a symbol is defined as a hidden symbol in the .s file
+# produced by the compiler.
+
+proc scan-hidden { args } {
+ upvar 2 name testcase
+ set output_file "[file rootname [file tail $testcase]].s"
+
+ set symbol [lindex $args 0]
+ set args [lreplace $args 0 0 "hidden\[ \t_\]*$symbol"]
+
+ dg-scan "scan-hidden" 1 $testcase $output_file $args
+}
+
+# Check that a symbol is not defined as a hidden symbol in the .s file
+# produced by the compiler.
+
+proc scan-not-hidden { args } {
+ upvar 2 name testcase
+ set output_file "[file rootname [file tail $testcase]].s"
+
+ set symbol [lindex $args 0]
+ set args [lreplace $args 0 0 "hidden\[ \t_\]*$symbol"]
+
+ dg-scan "scan-not-hidden" 0 $testcase $output_file $args
+}
+
# Look for a pattern in OUTPUT_FILE. See dg-scan for details.
proc scan-file { output_file args } {
DECL_ATTRIBUTES (newdecl));
}
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
/* Specialization of merge_decl_attributes for various Windows targets.
return a;
}
+/* Handle a "dllimport" or "dllexport" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+tree
+handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
+ bool *no_add_attrs)
+{
+ tree node = *pnode;
+
+ /* These attributes may apply to structure and union types being created,
+ but otherwise should pass to the declaration involved. */
+ if (!DECL_P (node))
+ {
+ if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
+ | (int) ATTR_FLAG_ARRAY_NEXT))
+ {
+ *no_add_attrs = true;
+ return tree_cons (name, args, NULL_TREE);
+ }
+ if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
+ {
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+ }
+
+ /* Report error on dllimport ambiguities seen now before they cause
+ any damage. */
+ if (is_attribute_p ("dllimport", name))
+ {
+ /* Like MS, treat definition of dllimported variables and
+ non-inlined functions on declaration as syntax errors. We
+ allow the attribute for function definitions if declared
+ inline. */
+ if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
+ && !DECL_DECLARED_INLINE_P (node))
+ {
+ error ("%Jfunction `%D' definition is marked dllimport.", node, node);
+ *no_add_attrs = true;
+ }
+
+ else if (TREE_CODE (node) == VAR_DECL)
+ {
+ if (DECL_INITIAL (node))
+ {
+ error ("%Jvariable `%D' definition is marked dllimport.",
+ node, node);
+ *no_add_attrs = true;
+ }
+
+ /* `extern' needn't be specified with dllimport.
+ Specify `extern' now and hope for the best. Sigh. */
+ DECL_EXTERNAL (node) = 1;
+ /* Also, implicitly give dllimport'd variables declared within
+ a function global scope, unless declared static. */
+ if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
+ TREE_PUBLIC (node) = 1;
+ }
+ }
+
+ /* Report error if symbol is not accessible at global scope. */
+ if (!TREE_PUBLIC (node)
+ && (TREE_CODE (node) == VAR_DECL
+ || TREE_CODE (node) == FUNCTION_DECL))
+ {
+ error ("%Jexternal linkage required for symbol '%D' because of "
+ "'%s' attribute.", node, node, IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
#endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
\f
/* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
extern tree merge_attributes (tree, tree);
-#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
/* Given two Windows decl attributes lists, possibly including
dllimport, return a list of their union . */
extern tree merge_dllimport_decl_attributes (tree, tree);
+
+/* Handle a "dllimport" or "dllexport" attribute. */
+extern tree handle_dll_attribute (tree *, tree, tree, int, bool *);
#endif
/* Check whether CAND is suitable to be returned from get_qualified_type