Hi, all
I built gcc with --enable-plugin on windows.
download link:
https://pcxprj.googlecode.com/files/MinGW_GCC4.6.1_enable_plugin_experimental.7z
There is an example in the package, and this is in the example directory.
Makefile.gcc is linked with cc1
Makefile.g++ is linked with cc1plus
So the gcc has some problems, when you use gcc to call plugin, you
should link plugin with libcc1.a, and if you use g++ to call plugin,
you should link plugin with libcc1plus.a. You can't mix linking, or
you will get segment fault.
Here is the patches and build process. (I only use C/C++/Fortran, so only
modify them)
Before building it, you should have dlopen/dlsym, here we can use
dlfcn-win32 temporarily.
1. Make binutils export exe's symbols.
Patch binutils using export-symbols.diff
And using the newer binutils to build gcc.
2. Modify gcc source code to support plugin
Patch gcc using gcc-plugin.patch
3. Build gcc using --enable-plugin
4. After installing, you should copy libcc1.a, libcc1plus.a and
libf951.a to your install directory's lib.
Then you can use gcc plugin.
Note: when you use gcc to call plugin, you should link plugin with
libcc1.a, and if you use g++ to call plugin, you should link plugin
with libcc1plus.a. You can't mix linking, or you will get segment
fault.
In the end, I use the built editon to run the gcc testsuite plugin section
successfully.
So, at some time, we can port llvm-dragonegg to windows?
Any ideas?
Thanks.
--
Best Regards,
xunxun
diff -ruNa gcc4.6.1/gcc/configure build/gcc/configure
--- gcc4.6.1/gcc/configure 2011-02-28 23:36:37.0 +0800
+++ build/gcc/configure 2011-10-16 20:57:13.0 +0800
@@ -26270,10 +26270,11 @@
${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest /dev/null
21
if $export_sym_check conftest | grep foobar /dev/null; then
plugin_rdynamic=yes
-pluginlibs=-rdynamic
+pluginlibs=-Wl,--export-all-symbols
else
-plugin_rdynamic=no
-enable_plugin=no
+plugin_rdynamic=yes
+enable_plugin=yes
+pluginlibs=-Wl,--export-all-symbols
fi
{ $as_echo $as_me:${as_lineno-$LINENO}: result: $plugin_rdynamic 5
$as_echo $plugin_rdynamic 6; }
@@ -26364,7 +26365,7 @@
$as_echo_n checking for -fPIC -shared... 6; }
cat confdefs.h - _ACEOF conftest.$ac_ext
/* end confdefs.h. */
-extern int X;
+int X;
int
main ()
{
diff -ruNa gcc4.6.1/gcc/cp/Make-lang.in build/gcc/cp/Make-lang.in
--- gcc4.6.1/gcc/cp/Make-lang.in2011-05-19 16:00:50.0 +0800
+++ build/gcc/cp/Make-lang.in 2011-10-18 13:42:58.0 +0800
@@ -102,7 +102,7 @@
cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
- $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
+ $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
-Wl,--output-def,cc1plus.def,--out-implib,libcc1plus.a
# Special build rules.
$(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf
diff -ruNa gcc4.6.1/gcc/fortran/Make-lang.in build/gcc/fortran/Make-lang.in
--- gcc4.6.1/gcc/fortran/Make-lang.in 2010-11-13 07:26:56.0 +0800
+++ build/gcc/fortran/Make-lang.in 2011-10-18 13:42:09.0 +0800
@@ -98,7 +98,7 @@
f951$(exeext): $(F95_OBJS) \
$(BACKEND) $(LIBDEPS) attribs.o
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
- $(F95_OBJS) $(BACKEND) $(LIBS) attribs.o $(BACKENDLIBS)
+ $(F95_OBJS) $(BACKEND) $(LIBS) attribs.o $(BACKENDLIBS)
-Wl,--output-def,f951.def,--out-implib,libf951.a
gt-fortran-trans.h: s-gtype; @true
#
diff -ruNa gcc4.6.1/gcc/Makefile.in build/gcc/Makefile.in
--- gcc4.6.1/gcc/Makefile.in2011-05-24 02:12:34.0 +0800
+++ build/gcc/Makefile.in 2011-10-18 13:35:17.0 +0800
@@ -1852,7 +1852,7 @@
cc1$(exeext): $(C_OBJS) cc1-checksum.o $(BACKEND) $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(C_OBJS) \
- cc1-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
+ cc1-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
-Wl,--output-def,cc1.def,--out-implib,libcc1.a
#
# Build libgcc.a.
diff -ruNa cvs/binutils/dlltool.c build/binutils/dlltool.c
--- cvs/binutils/dlltool.c 2011-10-14 21:02:59.722042474 +0800
+++ build/binutils/dlltool.c2011-10-15 08:39:30.244664033 +0800
@@ -412,7 +412,7 @@
/* TRUE if we should export all symbols. Otherwise, we only export
symbols listed in .drectve sections or in the def file. */
-static bfd_boolean export_all_symbols;
+static bfd_boolean export_all_symbols = TRUE;
/* TRUE if we should exclude the symbols in DEFAULT_EXCLUDES when
exporting all symbols. */
diff -ruNa cvs/ld/emultempl/pe.em build/ld/emultempl/pe.em
--- cvs/ld/emultempl/pe.em 2011-06-13 08:59:43.0 +0800
+++ build/ld/emultempl/pe.em2011-10-15 08:17:53.350233079 +0800
@@ -297,6 +297,9 @@