add support for LZMA on Windows

This commit is contained in:
Joel Dice 2012-06-02 15:43:42 -06:00
parent f07a8c7ec4
commit d61501453f
7 changed files with 109 additions and 24 deletions

View File

@ -71,6 +71,8 @@ ifeq ($(build-platform),cygwin)
native-path = cygpath -m native-path = cygpath -m
endif endif
windows-path = echo
path-separator = : path-separator = :
ifneq (,$(filter mingw32 cygwin,$(build-platform))) ifneq (,$(filter mingw32 cygwin,$(build-platform)))
@ -500,8 +502,9 @@ ld := $(cc)
build-ld := $(build-cc) build-ld := $(build-cc)
ifdef msvc ifdef msvc
windows-java-home := $(shell cygpath -m "$(JAVA_HOME)") windows-path = $(native-path)
zlib := $(shell cygpath -m "$(win32)/msvc") windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)")
zlib := $(shell $(windows-path) "$(win32)/msvc")
cxx = "$(msvc)/BIN/cl.exe" cxx = "$(msvc)/BIN/cl.exe"
cc = $(cxx) cc = $(cxx)
ld = "$(msvc)/BIN/link.exe" ld = "$(msvc)/BIN/link.exe"
@ -512,6 +515,11 @@ ifdef msvc
-Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \ -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \
-I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \
-DTARGET_BYTES_PER_WORD=$(pointer-size) -DTARGET_BYTES_PER_WORD=$(pointer-size)
ifneq ($(lzma),)
cflags += -I$(shell $(windows-path) "$(lzma)")
endif
shared = -dll shared = -dll
lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \
-DEFAULTLIB:zlib -MANIFEST -debug -DEFAULTLIB:zlib -MANIFEST -debug
@ -638,7 +646,7 @@ generator-sources = \
$(src)/finder.cpp $(src)/finder.cpp
ifneq ($(lzma),) 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 += \ vm-sources += \
$(src)/lzma-decode.cpp $(src)/lzma-decode.cpp
@ -673,7 +681,7 @@ ifneq ($(lzma),)
lzma-encoder-lzma-sources = $(lzma-encode-sources) $(lzma-decode-sources) lzma-encoder-lzma-sources = $(lzma-encode-sources) $(lzma-decode-sources)
lzma-encoder-lzma-objects = \ 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 lzma-loader = $(build)/lzma/load.o
endif endif
@ -904,7 +912,7 @@ $(test-extra-dep): $(test-extra-sources)
define compile-object define compile-object
@echo "compiling $(@)" @echo "compiling $(@)"
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(cxx) $(cflags) -c $(<) $(call output,$(@)) $(cxx) $(cflags) -c $$($(windows-path) $(<)) $(call output,$(@))
endef endef
define compile-asm-object define compile-asm-object
@ -993,7 +1001,7 @@ $(generator-objects): $(generator-depends)
$(generator-objects): $(build)/%-build.o: $(src)/%.cpp $(generator-objects): $(build)/%-build.o: $(src)/%.cpp
$(compile-generator-object) $(compile-generator-object)
$(generator-lzma-objects): $(build)/%-build.o: $(lzma)/C/%.c $(build)/%-build.o: $(lzma)/C/%.c
$(compile-generator-object) $(compile-generator-object)
$(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp $(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp

View File

@ -10022,7 +10022,7 @@ compileVirtualThunk(MyThread* t, unsigned index, unsigned* size)
sprintf(RUNTIME_ARRAY_BODY(virtualThunkName), "%s%d", virtualThunkBaseName, index); 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<uintptr_t>(start); return reinterpret_cast<uintptr_t>(start);
} }

View File

@ -9,7 +9,7 @@
details. */ details. */
#include "lzma-util.h" #include "lzma-util.h"
#include "LzmaDec.h" #include "C/LzmaDec.h"
using namespace vm; using namespace vm;

View File

@ -9,7 +9,7 @@
details. */ details. */
#include "lzma-util.h" #include "lzma-util.h"
#include "LzmaEnc.h" #include "C/LzmaEnc.h"
using namespace vm; using namespace vm;

View File

@ -12,7 +12,7 @@
#define LZMA_UTIL_H #define LZMA_UTIL_H
#include "lzma.h" #include "lzma.h"
#include "Types.h" #include "C/Types.h"
#include "system.h" #include "system.h"
#include "allocator.h" #include "allocator.h"

View File

@ -2,22 +2,31 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include "LzmaDec.h" #include "C/LzmaDec.h"
#ifdef __MINGW32__ #if (defined __MINGW32__) || (defined _MSC_VER)
# define EXPORT __declspec(dllexport) # define EXPORT __declspec(dllexport)
# include <io.h>
# define open _open
# define write _write
# define close _close
# ifdef _MSC_VER
# define S_IRWXU (_S_IREAD | _S_IWRITE)
# define and &&
# endif
#else #else
# define EXPORT __attribute__ ((visibility("default"))) # define EXPORT __attribute__ ((visibility("default")))
# include <dlfcn.h>
# include <unistd.h>
# include <errno.h>
# define O_BINARY 0
#endif #endif
#if defined __MINGW32__ && ! defined __x86_64__ #if (! defined __x86_64__) && ((defined __MINGW32__) || (defined _MSC_VER))
# define SYMBOL(x) binary_exe_##x # define SYMBOL(x) binary_exe_##x
#else #else
# define SYMBOL(x) _binary_exe_##x # define SYMBOL(x) _binary_exe_##x
@ -44,6 +53,70 @@ myFree(void*, void* address)
free(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<HMODULE>(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 } // namespace
int int
@ -67,28 +140,31 @@ main(int ac, const char** av)
(out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start), (out, &outSize, SYMBOL(start) + HeaderSize, &inSize, SYMBOL(start),
PropHeaderSize, LZMA_FINISH_END, &status, &allocator)) PropHeaderSize, LZMA_FINISH_END, &status, &allocator))
{ {
char name[L_tmpnam]; const unsigned BufferSize = 1024;
if (tmpnam(name)) { char buffer[BufferSize];
int file = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRWXU); 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) { if (file != -1) {
SizeT result = write(file, out, outSize); SizeT result = write(file, out, outSize);
free(out); free(out);
if (close(file) == 0 and outSize == result) { if (close(file) == 0 and outSize == result) {
void* library = dlopen(name, RTLD_LAZY | RTLD_GLOBAL); void* library = openLibrary(name);
unlink(name); unlink(name);
if (library) { if (library) {
void* main = dlsym(library, "main"); void* main = librarySymbol(library, "avianMain");
if (main) { if (main) {
int (*mainFunction)(int, const char**); int (*mainFunction)(const char*, int, const char**);
memcpy(&mainFunction, &main, sizeof(void*)); memcpy(&mainFunction, &main, sizeof(void*));
return mainFunction(ac, av); return mainFunction(name, ac, av);
} else { } else {
fprintf(stderr, "unable to find main in %s", name); fprintf(stderr, "unable to find main in %s", name);
} }
} else { } else {
fprintf(stderr, "unable to dlopen %s: %s\n", name, dlerror()); fprintf(stderr, "unable to load %s: %s\n", name,
libraryError(library));
} }
} else { } else {
unlink(name); unlink(name);

View File

@ -2925,6 +2925,7 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder,
shutdownLock(0), shutdownLock(0),
libraries(0), libraries(0),
errorLog(0), errorLog(0),
bootimage(0),
types(0), types(0),
roots(0), roots(0),
finalizers(0), finalizers(0),