This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch/RFA] Fix mingw/cygwin dllimport PR's 7910 (et al) and 11021

The attached patch fixes dllimport PR's c++7910 (and duplicates) and
c++/11021. and expands the testsuite for handling of dllimport

PR  7910 and related problems all arise when we try to apply a the
dllimport attribute to a definition. The patch trys to  check for this
ambiguity as early as possible, throws errors when the syntax is
obviously inconsistent and discards the attribute (with warning) if a
redeclaration or definition is seen later.

It also throws error if the symbol is defined with only local scope,
 eg '__attribute__((dllimport)) static int foo'

Dllimport is also inconsistent with virtual methods in C++ classes.
The attribute says that we cannot treat the symbols address as a
constant. Thus we simply disregard the attribute for virtual methods,
avoiding the PR 11021 segfault.  The cost for disregarding the
attribute for functions is small:an additional thunk in the dll.

Multiple inheritance and dll's requires an additional dllexport
modification to get some virtual amd non-virtual thunks exported
from the dll. Once I develop the testcase[s] for that I'll submit.

The patch is based on earlier work by Mumit Khan, by I have moved
things around quite a bit and don't try to follow MSVC 'rules' as
strictly. particularly when they seemed to encourage sloppy code.
I would like to put Mumit's name on the ChangeLog as well,
but will await his review.

I would really appreciate comments on this because. although I've
happy with my empirical tests on real dll's,I'm in a bit over my

Booted and regtested i386-pc-mingw
gcc version 3.4 20030528 (experimental)



2002-05-30  Danny Smith  <>

        PR c++/7910
        * config/i386/winnt.c (ix86_handle_dll_attribute): Don't add
        dllimport attribute if function is defined at declaration, but
        throw error instead. Likewise for dllimport'd variable
        definitions.  Throw error if dllimport or dllexport symbol is
        not global.
        (i386_pe_dllimport_p): Ignore dllimport attribute of functions
        if defined after declaration or if inlined. Handle static data
        members of C++ classes. Emit warnings.
        (i386_pe_mark_dllexport): Warn about inconsistent dll
        (i386_pe_mark_dllimport): Remove unnecessary checks; already
        (i386_pe_encode_section_info): Warn if the dllimport attribute
        and symbol prefix have been instantiated and then overridden.
        * testsuite/g++.dg/ext/dllimport1.C: Add mingw32 as target. Add
        test for warnings.
        * testsuite/g++.dg/ext/dllimport2.C: Add test for warnings.
        * testsuite/g++.dg/ext/dllimport3.C: Likeswise..
        * testsuite/g++.dg/ext/dllimport4.C: New file. Test that errors
        are emitted if dllimport symbols defined at declaration.
        * testsuite/g++.dg/ext/dllimport5.C: New file. Test that errors
        are emitted if dll[im/ex]port attribute on local symbol.
        * testsuite/g++.dg/ext/dllimport6.C: New file. Test that static
        members of C++ classes are marked.
        * testsuite/g++.dg/ext/dllimport7.C: New file. Test that errors
        are emitted for definition of static data in classes marked as
        * testsuite/g++.dg/ext/dllimport8.C: New file. Test dllimport
        handling and warnings for static functions in C++ classes.
        * testsuite/g++.dg/ext/dllimport9.C: New file. More tests of
        inline function and dllimport.

        * testsuite/g++.dg/ext/dllexport1.C: New file. Test that inline
        functions are exported using -fkeep-inlines.

        PR c++/11021
        * config/i386/winnt.c (i386_pe_dllimport_p): Ignore dllimport
        attributes for virtual methods.
        * testsuite/g++.dg/ext/dllimport10.C: New file.

        * config/i386/winnt.c (i386_pe_output_labelref): Fix indents.

Attachment: winnt-dllimport.diff
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]