Bug 35921 - Con/de-structor definition fails to override dllimport declaration
Summary: Con/de-structor definition fails to override dllimport declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 major
Target Milestone: 4.3.2
Assignee: Danny Smith
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-12 22:10 UTC by John E. / TDM
Modified: 2008-06-28 07:53 UTC (History)
3 users (show)

See Also:
Host: mingw32
Target: mingw32
Build: mingw32
Known to work:
Known to fail:
Last reconfirmed: 2008-04-13 09:39:48


Attachments
Minimal testcase (101 bytes, text/plain)
2008-04-12 22:45 UTC, John E. / TDM
Details
Minimal testcase for vtable issue (91 bytes, text/plain)
2008-05-29 17:31 UTC, John E. / TDM
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John E. / TDM 2008-04-12 22:10:14 UTC
When the attached file is compiled with a mingw32 build of GCC 4.3.0, the constructor definition for "foo" does not fully override the declaration in the struct which inherits the dllimport attribute, and a dllimport reference is incorrectly emitted. The member function "bar()" is provided as an example of correctly overriding the dllimport declaration; this issue only occurs with constructors and destructors.

Compilation command line and output:
> g++ -c impoverride.cpp
impoverride.cpp:8: warning: 'foo::foo()' redeclared without dllimport attribute:
 previous dllimport ignored
impoverride.cpp:12: warning: 'void foo::bar()' redeclared without dllimport attr
ibute: previous dllimport ignored

> nm impoverride.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000011 T __Z3depv
0000000c T __ZN3foo3barEv
00000006 T __ZN3fooC1Ev
00000000 T __ZN3fooC2Ev
         U __imp___ZN3fooC1Ev << Shouldn't be there!

> g++ -v
Using built-in specs.
Target: mingw32
Configured with: ../../gcc-4.3.0-ehstatic/configure --prefix=/mingw --build=ming
w32 --enable-languages=c,c++ --disable-nls --disable-win32-registry --enable-sjl
j-exceptions --enable-libgomp --with-gmp=/d/cygdev/gccbuild/libsfor43/debug/gmp-
install --with-mpfr=/d/cygdev/gccbuild/libsfor43/debug/mpfr-install --with-libic
onv-prefix=/d/cygdev/gccbuild/libsfor43/debug/iconv-install --disable-werror --e
nable-threads --enable-libstdcxx-debug --enable-cxx-flags='-fno-function-section
s -fno-data-sections' --disable-symvers
Thread model: win32
gcc version 4.3.0 (GCC)
Comment 1 John E. / TDM 2008-04-12 22:45:45 UTC
Created attachment 15469 [details]
Minimal testcase
Comment 2 Aaron W. LaFramboise 2008-04-13 01:46:15 UTC
Note at present, implicit inline within the class definition will work; it's only out-of-line that fails.

Also, if we fix this bug in the suggested way, we need to change the documentation to state that the 'inline' is not ignored, and state that this has probably has different behavior from MSVC's dllimport.
Comment 3 Danny Smith 2008-04-13 09:39:47 UTC
Patch at:
http://gcc.gnu.org/ml/gcc-patches/2008-04/msg01048.html
Comment 4 dannysmith@gcc.gnu.org 2008-04-14 23:54:37 UTC
Subject: Bug 35921

Author: dannysmith
Date: Mon Apr 14 23:53:54 2008
New Revision: 134298

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134298
Log:
       PR target/35921
       * optimize.c (maybe_clone_body): Copy DECL_DLLIMPORT_P flag
       to clone.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/optimize.c

Comment 5 John E. / TDM 2008-04-16 00:50:28 UTC
The issue is fixed for me when applying the mentioned patch to 4.3.0, so as far as I'm concerned we can close this bug as soon as someone applies the fix to 4.3 SVN.
Comment 6 Danny Smith 2008-04-16 01:54:30 UTC
(In reply to comment #5)
> The issue is fixed for me when applying the mentioned patch to 4.3.0, so as far
> as I'm concerned we can close this bug as soon as someone applies the fix to
> 4.3 SVN.
> 

I'll wait a week to see if it causes any problems on trunk, then apply to 4.3 branch.

Danny
Comment 7 John E. / TDM 2008-05-29 17:31:03 UTC
Created attachment 15702 [details]
Minimal testcase for vtable issue

I'm not sure whether this is related, but the effect is similar so I'm adding it to this same bug.

Basically, we get an undefined reference to the vtable for a dllimport-ed struct with a single inner-defined virtual function. Again, it's something that worked in mingw32 in previous GCC releases and fails in 4.3.0.

Command line compilation and output:
> g++ -c impoverride2.cpp

> nm impoverride2.o
00000000 b .bss
00000000 d .data
00000000 r .rdata$_ZTI3foo
00000000 r .rdata$_ZTS3foo
00000000 r .rdata$_ZTV3foo
00000000 t .text
00000000 t .text$_ZN3foo3barEv
00000000 t .text$_ZN3fooC1Ev
00000000 T __Z3depv
00000000 T __ZN3foo3barEv
00000000 T __ZN3fooC1Ev
00000000 R __ZTI3foo
00000000 R __ZTS3foo
00000000 R __ZTV3foo
         U __ZTVN10__cxxabiv117__class_type_infoE
         U __imp___ZTV3foo << Shouldn't be there!

> g++ -v
Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.3.0/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,obj-c++ --with-bugurl=http://www.tdragon.net/recentgcc/bugs.php --disable-nls --disable-win32-registry --enable-libgomp --disable-werror --enable-threads --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections' --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --program-suffix=-dw2 --with-pkgversion='GCC TDM-3/DW2 for MinGW'
Thread model: win32
gcc version 4.3.0-dw2 (GCC TDM-3/DW2 for MinGW)
Comment 8 Danny Smith 2008-05-29 21:00:03 UTC
(In reply to comment #7)
> Created an attachment (id=15702) [edit]
> Minimal testcase for vtable issue
> 
> I'm not sure whether this is related, but the effect is similar so I'm adding
> it to this same bug.
> 
> Basically, we get an undefined reference to the vtable for a dllimport-ed
> struct with a single inner-defined virtual function.



Uhh, if you declare a struct as dllimport, then you are declaring that it's vtable is defined in a dll. So why is this a bug?

Of course if you allow compiler to actually inline the virtual function in your example, the vtable should not be needed. 

Anyway, thanks for reminding me of this bug.  I'll backport 4.4 patch to 4.3.2 once branch reopens.

Danny
Comment 9 John E. / TDM 2008-05-29 22:13:55 UTC
(In reply to comment #8)
> Uhh, if you declare a struct as dllimport, then you are declaring that it's
> vtable is defined in a dll. So why is this a bug?

Well, it's a change from mingw32/3.4.5's behavior. At any rate, after thinking about it I agree that it isn't a bug.

Thanks,
John E.
Comment 10 dannysmith@gcc.gnu.org 2008-06-07 00:40:27 UTC
Subject: Bug 35921

Author: dannysmith
Date: Sat Jun  7 00:39:43 2008
New Revision: 136515

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136515
Log:
       PR target/35921
       * optimize.c (maybe_clone_body): Copy DECL_DLLIMPORT_P flag
       to clone.

Modified:
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/optimize.c

Comment 11 Danny Smith 2008-06-07 00:46:09 UTC
Fix backported to branch.
Comment 12 Danny Smith 2008-06-28 07:53:06 UTC
*** Bug 36654 has been marked as a duplicate of this bug. ***