ADDED build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff ================================================================== --- build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff +++ build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff @@ -0,0 +1,77 @@ +diff -uNr tcc-0.9.26.orig/tccpe.c tcc-0.9.26-1win32useopenlibs/tccpe.c +--- tcc-0.9.26.orig/tccpe.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1win32useopenlibs/tccpe.c 2014-05-04 02:00:45.195490003 -0500 +@@ -38,6 +38,9 @@ + # define ADDR3264 DWORD + #endif + ++#ifdef TCC_IS_NATIVE ++#include ++#endif + #ifdef _WIN32 + void dbg_printf (const char *fmt, ...) + { +@@ -831,7 +834,26 @@ + if (dllref) { + if ( !dllref->handle ) + dllref->handle = LoadLibrary(dllref->name); +- v = (ADDR3264)GetProcAddress(dllref->handle, name); ++ if (dllref->handle) { ++ v = (ADDR3264)GetProcAddress(dllref->handle, name); ++ } ++ } ++ if (!v) { ++ HANDLE cur_proc = GetCurrentProcess(); ++ HMODULE *modules; ++ DWORD needed, i; ++ ++ needed = 0; ++ EnumProcessModules(cur_proc, NULL, 0, &needed); ++ modules = tcc_malloc(needed); ++ if (EnumProcessModules(cur_proc, modules, needed, &needed)) { ++ for (i = 0; i < needed / sizeof(HMODULE); i++) { ++ v = (ADDR3264)GetProcAddress(modules[i], name); ++ if (v) { ++ break; ++ } ++ } ++ } + } + if (!v) + tcc_error_noabort("undefined symbol '%s'", name); +@@ -1209,9 +1231,34 @@ + + const char *name = symtab_section->link->data + sym->st_name; + unsigned type = ELFW(ST_TYPE)(sym->st_info); +- int imp_sym = pe_find_import(pe->s1, sym); ++ int imp_sym; + struct import_symbol *is; + ++ imp_sym = pe_find_import(pe->s1, sym); ++ if (0 == imp_sym) { ++ HANDLE cur_proc = GetCurrentProcess(); ++ HMODULE *modules; ++ DWORD needed, i; ++ const char *symname; ++ void *addr; ++ ++ symname = pe_export_name(pe->s1, sym); ++ ++ needed = 0; ++ EnumProcessModules(cur_proc, NULL, 0, &needed); ++ modules = tcc_malloc(needed); ++ if (EnumProcessModules(cur_proc, modules, needed, &needed)) { ++ for (i = 0; i < needed / sizeof(HMODULE); i++) { ++ addr = GetProcAddress(modules[i], symname); ++ if (addr) { ++ put_elf_sym( pe->s1->dynsymtab_section, (ADDR3264) addr, sizeof(addr), ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), 0, SHN_UNDEF, symname); ++ imp_sym = pe_find_import(pe->s1, sym); ++ break; ++ } ++ } ++ } ++ } ++ + if (0 == imp_sym) + goto not_found; + Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -4,10 +4,11 @@ dnl Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_INSTALL AC_GNU_SOURCE +AC_LANG(C) dnl Determine system information DC_CHK_OS_INFO dnl Determine if a shared or static build is requested @@ -33,14 +34,37 @@ if test "${TCC4TCL_TARGET}" = "shared"; then dnl Determine how to make shared objects DC_GET_SHOBJFLAGS dnl Only export symbols we wish to expose - DC_SETVERSIONSCRIPT([tcc4tcl.syms], [tcc4tcl.vers]) - DC_FIND_STRIP_AND_REMOVESYMS([tcc4tcl.syms]) - TARGET="tcc4tcl.${SHOBJEXT}" + + AC_CHECK_HEADERS(windows.h) + AC_CHECK_HEADERS(psapi.h,,, [ +#ifdef HAVE_WINDOWS_H +# include +#endif +]) + + AC_MSG_CHECKING([for EnumProcessModules in -lpsapi]) + SAVE_LIBS="$LIBS" + LIBS="-lpsapi $LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([ +#ifdef HAVE_WINDOWS_H +# include +#endif +#ifdef HAVE_PSAPI_H +# include +#endif +], [ + EnumProcessModules(NULL, NULL, 0, NULL); +])], [ + AC_MSG_RESULT([found]) +], [ + AC_MSG_RESULT([not found]) + LIBS="$SAVE_LIBS" +]) else TARGET="tcc4tcl-static.a" fi AC_SUBST(TARGET) AC_SUBST(TCC4TCL_TARGET) @@ -54,8 +78,14 @@ dnl Look for appropriate headers AC_CHECK_HEADERS(unistd.h stdlib.h string.h strings.h dlfcn.h dl.h) dnl Perform Tcl Extension required stuff TCLEXT_INIT + +dnl This must be done last since it breaks the compilation +if test "${TCC4TCL_TARGET}" = "shared"; then + DC_SETVERSIONSCRIPT([tcc4tcl.syms], [tcc4tcl.vers]) + DC_FIND_STRIP_AND_REMOVESYMS([tcc4tcl.syms]) +fi dnl Produce output AC_OUTPUT(Makefile pkgIndex.tcl tcc4tcl.syms) Index: tcc4tcl.tcl ================================================================== --- tcc4tcl.tcl +++ tcc4tcl.tcl @@ -53,12 +53,10 @@ return } } proc tcc4tcl::to_dll {code dll {libs {}}} { tcc4tcl $::tcc4tcl::dir dll tcc_1 - tcc_1 add_library tcl8.5 - tcc_1 add_library_path . foreach lib $libs {tcc_1 add_library $lib} if {$::tcl_platform(platform) eq "windows"} { tcc_1 define DLL_EXPORT {__declspec(dllexport)} set f [open $::tcc4tcl::dir/c/dllcrt1.c] tcc_1 compile [read $f] @@ -94,12 +92,10 @@ proc ::tcc4tcl::cc {code} { variable tcc if {![info exists tcc(cc)]} { set tcc(cc) tcc1 tcc4tcl $::tcc4tcl::dir $tcc(cc) - $tcc(cc) add_library tcl8.5 - $tcc(cc) add_include_path [file join $::tcc4tcl::dir include] } Log code:$code $tcc(cc) compile $code } #----------------------------------------------------------- New DLL API