public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "geoff at telesiscomputing dot com.au" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/56892] New: dllexport prevents inline inside dll
Date: Tue, 09 Apr 2013 12:26:00 -0000	[thread overview]
Message-ID: <bug-56892-4@http.gcc.gnu.org/bugzilla/> (raw)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56892

             Bug #: 56892
           Summary: dllexport prevents inline inside dll
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: geoff@telesiscomputing.com.au


Created attachment 29840
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29840
Preprocessed result of: mingw32-g++.exe -v -save-temps -std=c++11 -O2 -Winline
testlib.cpp

When the dllexport attribute is used at the class level (which is most common),
any inline methods for that class will NOT be inlined inside the shared library
binary itself.  This prevents the shared library from being fully optimised,
sometimes with significant impact on performance.

Produced on mingw / gcc v4.7.2, and on mingw64 / gcc v4.8.0.

Given these three classes (testlib.hpp):

class __declspec(dllexport) A {
public:
    int fa() { return m; }
    int ga();
private:
    int m{0};
};

class __declspec(dllexport) B {
public:
    int fb();
    int gb();
private:
    int m{0};
};
inline int B::fb() { return m; }

class C {
public:
    int fc() { return m; }
    __declspec(dllexport) int gc();
private:
    int m{0};
};


Implemented as (testlib.cpp):

#include "testlib.hpp"

int A::ga() { return (fa() + 1); }

int B::gb() { return (fb() + 1); }

int C::gc() { return (fc() + 1); }


And then compiled with: -std::c++11 -O2 -Winline testlib.cpp

(The -std::c++11 is just for the in-class initializer.)

A::fa() is not inlined, and no warning is given.
B::fb() is not inlined, the compiler warns that it won't inline.
C::fc() is inlined as expected.

Almost no-one writes their classes like class C, they use class A or (less
commonly) class B.  If they use class A style code they won't even know that
their inlines are being ignored when building the library itself.

I do understand the potential issues (the theory being that exported functions
are supposed to replaceable), but if __declspec(dllexport) - a synonym for
__attrribute__((dllexport)) - is supposed to emulate the behaviour seen by the
same declaration under msvc (why else create the synonym?) then it is failing
to do so.  See this link for details:
http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx

It is apparent that dllexport and dllimport are introducing additional
semantics above that of "export symbol" and "import symbol".  So the other
work-around is to stop using dllexport and dllimport and use manual .def files,
or --export-all-symbols when calling the linker.  Obviously neither options is
ideal.

It's possible that there could be overlap with this bug report:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50779


             reply	other threads:[~2013-04-09 12:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 12:26 geoff at telesiscomputing dot com.au [this message]
2013-04-09 12:35 ` [Bug c++/56892] " geoff at telesiscomputing dot com.au
2013-07-10 23:32 ` paolo.carlini at oracle dot com
2013-09-09 13:25 ` ktietz at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-56892-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).