public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Davide Piombo <Davide.Piombo@phase.eu>,
	'Trevor Saunders' <tbsaunde@tbsaunde.org>
Cc: 'Joseph Myers' <joseph@codesourcery.com>,
	David Malcolm <dmalcolm@redhat.com>,
	"'gcc@gcc.gnu.org'" <gcc@gcc.gnu.org>
Subject: Re: R: R: R: Plugin development under windows
Date: Wed, 29 Mar 2017 10:37:00 -0000	[thread overview]
Message-ID: <3b8249ef-c80a-076c-0248-51795da33bc6@palves.net> (raw)
In-Reply-To: <C267FE4E4B042C4B8A26EECCCACE9D6A06A99D4D@nelson.pmc.phase.it>

On 03/29/2017 08:30 AM, Davide Piombo wrote:
> Hi Trevor, thanks for your hint.
> 
> Yesterday I made some other tests. I tried to use CygWin instead of
> MinGW and the POSIX missing references are now solved. Now the error
> have moved from the compiler to the linker and the build stops
> because of undefined references. The missing symbols are included in
> GCC executable and are declared as external symbols in GCC plugin
> header files.

Declared as external is not sufficient.  They also need to be
declared as exported in PE terms.

Usually, you do that by tagging exported symbols
with __declspec(dllexport) at the time the exe is built, and tagging
them as __declspec(dllimport) when the plugin is built.

I.e., you'd apply the guidelines described at:

  https://gcc.gnu.org/wiki/Visibility

to GCC itself.  E.g., add a macro like the DLL_PUBLIC described
there, something around:

#if defined _WIN32 || defined __CYGWIN__
# ifdef BUILDING_GCC
#   define GCC_PUBLIC __declspec(dllexport)
# else
#   define GCC_PUBLIC __declspec(dllimport)
# endif
#else
# define GCC_PUBLIC
#endif

And add GCC_PUBLIC to symbols that should be exported to plugins.

AFAIK, in plugin architectures on Windows, it's more common to
split the bulk of an exe to a dll that is then linked by both
a "shim" exe and the plugins, but exporting symbols from EXEs
should work fine too.  See e.g.,:

  http://stackoverflow.com/questions/3752634/dll-get-symbols-from-its-parent-loader/3756083#3756083
  http://stackoverflow.com/questions/15454968/dll-plugin-that-uses-functions-defined-in-the-main-executable

The key search terms are "plugins on windows export exe symbols".

My Windows knowledge has been steadily fading over the years, and I'm
not sure whether GCC export all symbols automatically using "-fvisibility"
on Windows (as workaround) of whether you really need to go
the __declspec or dllexport routes.

Also, see:

 https://gcc.gnu.org/onlinedocs/gcc/Microsoft-Windows-Function-Attributes.html

maybe you can also workaround it by using LD's --export-all.

This should give you some pointers to experiment.

> Anyway, before to change the compiler or library version I tried to
> dump symbols from libgcc.a in order to understand if missing symbols
> are really in this library and they are not there.

libgcc.a is not GCC itself.  See:

  https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

Thanks,
Pedro Alves

  reply	other threads:[~2017-03-29 10:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 11:19 Davide Piombo
2017-03-27 14:09 ` David Malcolm
2017-03-27 15:57   ` Joseph Myers
2017-03-27 16:16     ` R: " Davide Piombo
2017-03-27 16:56       ` Joseph Myers
2017-03-28  7:52         ` R: " Davide Piombo
2017-03-28 22:57           ` Trevor Saunders
2017-03-29  7:33             ` R: " Davide Piombo
2017-03-29 10:37               ` Pedro Alves [this message]
2017-03-30  7:27                 ` R: " Davide Piombo
2017-03-27 16:04   ` Davide Piombo

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=3b8249ef-c80a-076c-0248-51795da33bc6@palves.net \
    --to=pedro@palves.net \
    --cc=Davide.Piombo@phase.eu \
    --cc=dmalcolm@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=tbsaunde@tbsaunde.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).