diff --git a/makefile b/makefile index 8ec37fdd50..de21c012b8 100755 --- a/makefile +++ b/makefile @@ -71,6 +71,8 @@ ifeq ($(build-platform),cygwin) native-path = cygpath -m endif +windows-path = echo + path-separator = : ifneq (,$(filter mingw32 cygwin,$(build-platform))) @@ -500,8 +502,9 @@ ld := $(cc) build-ld := $(build-cc) ifdef msvc - windows-java-home := $(shell cygpath -m "$(JAVA_HOME)") - zlib := $(shell cygpath -m "$(win32)/msvc") + windows-path = $(native-path) + windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") + zlib := $(shell $(windows-path) "$(win32)/msvc") cxx = "$(msvc)/BIN/cl.exe" cc = $(cxx) ld = "$(msvc)/BIN/link.exe" @@ -512,6 +515,11 @@ ifdef msvc -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -DTARGET_BYTES_PER_WORD=$(pointer-size) + + ifneq ($(lzma),) + cflags += -I$(shell $(windows-path) "$(lzma)") + endif + shared = -dll lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ -DEFAULTLIB:zlib -MANIFEST -debug @@ -638,7 +646,7 @@ generator-sources = \ $(src)/finder.cpp ifneq ($(lzma),) - common-cflags += -I$(lzma)/C -DAVIAN_USE_LZMA -D_7ZIP_ST + common-cflags += -I$(lzma) -DAVIAN_USE_LZMA -D_7ZIP_ST vm-sources += \ $(src)/lzma-decode.cpp @@ -673,7 +681,7 @@ ifneq ($(lzma),) lzma-encoder-lzma-sources = $(lzma-encode-sources) $(lzma-decode-sources) lzma-encoder-lzma-objects = \ - $(call c-objects,$(lzma-encoder-lzma-sources),$(lzma)/C,$(build)) + $(call generator-c-objects,$(lzma-encoder-lzma-sources),$(lzma)/C,$(build)) lzma-loader = $(build)/lzma/load.o endif @@ -904,7 +912,7 @@ $(test-extra-dep): $(test-extra-sources) define compile-object @echo "compiling $(@)" @mkdir -p $(dir $(@)) - $(cxx) $(cflags) -c $(<) $(call output,$(@)) + $(cxx) $(cflags) -c $$($(windows-path) $(<)) $(call output,$(@)) endef define compile-asm-object @@ -993,7 +1001,7 @@ $(generator-objects): $(generator-depends) $(generator-objects): $(build)/%-build.o: $(src)/%.cpp $(compile-generator-object) -$(generator-lzma-objects): $(build)/%-build.o: $(lzma)/C/%.c +$(build)/%-build.o: $(lzma)/C/%.c $(compile-generator-object) $(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp diff --git a/src/compile.cpp b/src/compile.cpp index 86edcb033e..ce67081480 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -10022,7 +10022,7 @@ compileVirtualThunk(MyThread* t, unsigned index, unsigned* size) sprintf(RUNTIME_ARRAY_BODY(virtualThunkName), "%s%d", virtualThunkBaseName, index); - logCompile(t, start, *size, 0, virtualThunkName, 0); + logCompile(t, start, *size, 0, RUNTIME_ARRAY_BODY(virtualThunkName), 0); return reinterpret_cast(start); } diff --git a/src/lzma-decode.cpp b/src/lzma-decode.cpp index 7710934ddd..f51b86af83 100644 --- a/src/lzma-decode.cpp +++ b/src/lzma-decode.cpp @@ -9,7 +9,7 @@ details. */ #include "lzma-util.h" -#include "LzmaDec.h" +#include "C/LzmaDec.h" using namespace vm; diff --git a/src/lzma-encode.cpp b/src/lzma-encode.cpp index d1b002476a..cc7f8ad178 100644 --- a/src/lzma-encode.cpp +++ b/src/lzma-encode.cpp @@ -9,7 +9,7 @@ details. */ #include "lzma-util.h" -#include "LzmaEnc.h" +#include "C/LzmaEnc.h" using namespace vm; diff --git a/src/lzma-util.h b/src/lzma-util.h index 105a9e4077..e7fc3093a0 100644 --- a/src/lzma-util.h +++ b/src/lzma-util.h @@ -12,7 +12,7 @@ #define LZMA_UTIL_H #include "lzma.h" -#include "Types.h" +#include "C/Types.h" #include "system.h" #include "allocator.h" diff --git a/src/lzma/load.cpp b/src/lzma/load.cpp index f4fc57965c..3584c50e6a 100644 --- a/src/lzma/load.cpp +++ b/src/lzma/load.cpp @@ -2,22 +2,31 @@ #include #include #include -#include -#include #include #include #include -#include -#include "LzmaDec.h" +#include "C/LzmaDec.h" -#ifdef __MINGW32__ +#if (defined __MINGW32__) || (defined _MSC_VER) # define EXPORT __declspec(dllexport) +# include +# define open _open +# define write _write +# define close _close +# ifdef _MSC_VER +# define S_IRWXU (_S_IREAD | _S_IWRITE) +# define and && +# endif #else # define EXPORT __attribute__ ((visibility("default"))) +# include +# include +# include +# define O_BINARY 0 #endif -#if defined __MINGW32__ && ! defined __x86_64__ +#if (! defined __x86_64__) && ((defined __MINGW32__) || (defined _MSC_VER)) # define SYMBOL(x) binary_exe_##x #else # define SYMBOL(x) _binary_exe_##x @@ -44,6 +53,70 @@ myFree(void*, void* address) free(address); } +#if (defined __MINGW32__) || (defined _MSC_VER) + +void* +openLibrary(const char* name) +{ + return LoadLibrary(name); +} + +void* +librarySymbol(void* library, const char* name) +{ + void* address; + FARPROC p = GetProcAddress(static_cast(library), name); + memcpy(&address, &p, sizeof(void*)); + return address; +} + +const char* +libraryError(void*) +{ + return "unknown error"; +} + +const char* +temporaryFileName(char* buffer, unsigned size) +{ + unsigned c = GetTempPathA(size, buffer); + if (c) { + if (GetTempFileNameA(buffer, "223", 0, buffer + c)) { + DeleteFileA(buffer + c); + return buffer + c; + } + } + return 0; +} + +#else + +void* +openLibrary(const char* name) +{ + return dlopen(name, RTLD_LAZY | RTLD_LOCAL); +} + +void* +librarySymbol(void* library, const char* name) +{ + return dlsym(library, name); +} + +const char* +libraryError(void*) +{ + return dlerror(); +} + +const char* +temporaryFileName(char* buffer, unsigned) +{ + return tmpnam(buffer); +} + +#endif + } // namespace int @@ -67,28 +140,31 @@ main(int ac, const char** av) (out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start), PropHeaderSize, LZMA_FINISH_END, &status, &allocator)) { - char name[L_tmpnam]; - if (tmpnam(name)) { - int file = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRWXU); + const unsigned BufferSize = 1024; + char buffer[BufferSize]; + const char* name = temporaryFileName(buffer, BufferSize); + if (name) { + int file = open(name, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IRWXU); if (file != -1) { SizeT result = write(file, out, outSize); free(out); if (close(file) == 0 and outSize == result) { - void* library = dlopen(name, RTLD_LAZY | RTLD_GLOBAL); + void* library = openLibrary(name); unlink(name); if (library) { - void* main = dlsym(library, "main"); + void* main = librarySymbol(library, "avianMain"); if (main) { - int (*mainFunction)(int, const char**); + int (*mainFunction)(const char*, int, const char**); memcpy(&mainFunction, &main, sizeof(void*)); - return mainFunction(ac, av); + return mainFunction(name, ac, av); } else { fprintf(stderr, "unable to find main in %s", name); } } else { - fprintf(stderr, "unable to dlopen %s: %s\n", name, dlerror()); + fprintf(stderr, "unable to load %s: %s\n", name, + libraryError(library)); } } else { unlink(name); diff --git a/src/machine.cpp b/src/machine.cpp index 6e242dd8b8..67f70196fe 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2925,6 +2925,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, shutdownLock(0), libraries(0), errorLog(0), + bootimage(0), types(0), roots(0), finalizers(0),