[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Win32 and Dynamic Compilation working



I have dynamic compilation (g2c-eval) working under Win32 using the
Visual C++ compiler. I had to make a number of changes to get it going
and I'm not sure it works for all cases. I'll outline the changes here
to get feedback on what the best approach might be to support this
(assuming you want to support it in the mainline Goo release).

I've taken the approach of building the Goo executable with most of
the functions 'exported'. This is a special tag to the C compiler that
makes that function or variable usable from another DLL.

The shared DLL that gets created by the g2c-eval 'imports' these
functions from the main executable via an import library. This allows
it to link since Win32 DLL's can't have unresolved references when
linking. And the references are linked back to the executables correct
function/variables.

I had to change the way I did the Win32 Thread Local Storage
support. When using DLL's you can't use the declspec(thread) variable
type, instead you have to fall back to the Win32 Tls functions.

Here are the main changes made:

1) Created an IMPORTEXPORT define that has the correct 'import' or
   'export' tag depending on whether building a DLL or the main Goo
   executable. I'm open to better suggestions for the name. It looks
   like this:

   #if defined(_MSC_VER)
     #if defined(BUILD_DLL)
       #define IMPORTEXPORT __declspec(dllimport)
     #else
       #define IMPORTEXPORT __declspec(dllexport)
     #endif
   #else
     #define IMPORTEXPORT
   #endif

2) Changed references to 'extern ...' to be 'IMPORTEXPORT extern...'
   so they get the correct linkage. eg:

   IMPORTEXPORT extern P YPsb(P);
   IMPORTEXPORT extern P YPlb(P);
   IMPORTEXPORT extern P YPlu(P);

3) Changed RTVDEF and others to include IMPORTEXPORT:

   #define RTVDEF(x, m, n)  IMPORTEXPORT extern P x; P x = PNUL;
   #define RTVEXT(x, m, n)  IMPORTEXPORT extern P x;

   #define DYNDEF(x, m, n)  IMPORTEXPORT extern P x; P x = PNUL;
   #define DYNEXT(x, m, n)  IMPORTEXPORT extern P x;

4) Implemented the compile and load functions in grt.c.

5) Rebuilt the world, set eval/top:$g2c-eval? to #t and it works.

I'll post the changed files on my website shortly. 

Is there a way of unloading the shared libraries that are loaded? Will
I run out of file handles and/or address space eventually?

Chris.