Here is the patches and build process. 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. -- Best Regards, xunxun
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.c 2011-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.000000000 +0800 +++ build/ld/emultempl/pe.em 2011-10-15 08:17:53.350233079 +0800 @@ -297,6 +297,9 @@ OPTION_USE_NUL_PREFIXED_IMPORT_TABLES}, {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE}, {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE}, + {"output-def", required_argument, NULL, OPTION_OUT_DEF}, + {"output-def", required_argument, NULL, OPTION_OUT_DEF}, + {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL}, #ifdef DLL_SUPPORT /* getopt allows abbreviations, so we do this to stop it from treating -o as an abbreviation for this option. */ @@ -433,6 +436,7 @@ fprintf (file, _(" --support-old-code Support interworking with old code\n")); fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n")); fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n")); + fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -747,13 +751,13 @@ case OPTION_LEADING_UNDERSCORE: pe_leading_underscore = 1; break; -#ifdef DLL_SUPPORT case OPTION_OUT_DEF: pe_out_def_filename = xstrdup (optarg); break; case OPTION_EXPORT_ALL: pe_dll_export_everything = 1; break; +#ifdef DLL_SUPPORT case OPTION_EXCLUDE_SYMBOLS: pe_dll_add_excludes (optarg, EXCLUDESYMS); break; diff -ruNa cvs/ld/emultempl/pep.em build/ld/emultempl/pep.em --- cvs/ld/emultempl/pep.em 2011-06-13 08:59:43.000000000 +0800 +++ build/ld/emultempl/pep.em 2011-10-15 08:18:06.274297160 +0800 @@ -235,6 +235,9 @@ OPTION_USE_NUL_PREFIXED_IMPORT_TABLES}, {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE}, {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE}, + {"output-def", required_argument, NULL, OPTION_OUT_DEF}, + {"output-def", required_argument, NULL, OPTION_OUT_DEF}, + {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL}, #ifdef DLL_SUPPORT /* getopt allows abbreviations, so we do this to stop it from treating -o as an abbreviation for this option. */ @@ -362,6 +365,7 @@ fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n")); fprintf (file, _(" --support-old-code Support interworking with old code\n")); fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n")); + fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -667,13 +671,13 @@ case OPTION_LEADING_UNDERSCORE: pep_leading_underscore = 1; break; -#ifdef DLL_SUPPORT case OPTION_OUT_DEF: pep_out_def_filename = xstrdup (optarg); break; case OPTION_EXPORT_ALL: pep_dll_export_everything = 1; break; +#ifdef DLL_SUPPORT case OPTION_EXCLUDE_SYMBOLS: pep_dll_add_excludes (optarg, EXCLUDESYMS); break; diff -ruNa cvs/ld/pe-dll.c build/ld/pe-dll.c --- cvs/ld/pe-dll.c 2011-10-14 21:03:11.122099004 +0800 +++ build/ld/pe-dll.c 2011-10-15 08:10:10.827939549 +0800 @@ -149,7 +149,7 @@ /* For emultempl/pe.em. */ def_file * pe_def_file = 0; -int pe_dll_export_everything = 0; +int pe_dll_export_everything = 1; int pe_dll_exclude_all_symbols = 0; int pe_dll_do_default_excludes = 1; int pe_dll_kill_ats = 0;
diff -ruNa gcc4.6.1/gcc/configure build/gcc/configure --- gcc4.6.1/gcc/configure 2011-02-28 23:36:37.000000000 +0800 +++ build/gcc/configure 2011-10-16 20:57:13.000000000 +0800 @@ -26270,10 +26270,11 @@ ${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest > /dev/null 2>&1 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.in 2011-05-19 16:00:50.000000000 +0800 +++ build/gcc/cp/Make-lang.in 2011-10-18 13:42:58.000000000 +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.000000000 +0800 +++ build/gcc/fortran/Make-lang.in 2011-10-18 13:42:09.000000000 +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.in 2011-05-24 02:12:34.000000000 +0800 +++ build/gcc/Makefile.in 2011-10-18 13:35:17.000000000 +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.