diff --git a/classpath/java-util-zip.cpp b/classpath/java-util-zip.cpp index 17ac1ca1a0..b9e685fe4e 100644 --- a/classpath/java-util-zip.cpp +++ b/classpath/java-util-zip.cpp @@ -1,6 +1,6 @@ #include "stdlib.h" #include "string.h" -#include "zlib.h" +#include "zlib-custom.h" #include "jni.h" #include "jni-util.h" diff --git a/makefile b/makefile index c24e663c10..02ee0cb687 100644 --- a/makefile +++ b/makefile @@ -8,6 +8,19 @@ ifeq ($(arch),i686) arch = i386 endif +platform = $(shell uname -s) +ifeq ($(platform),Darwin) + rdynamic = + thread-cflags = + shared = -dynamiclib + so-extension = dylib +else + rdynamic = -rdynamic + thread-cflags = -pthread + shared = -shared + so-extension = so +endif + mode = debug bld = build/$(arch)/$(mode) @@ -16,7 +29,7 @@ src = src classpath = classpath test = test -input = $(cls)/GC.class +input = $(cls)/Hello.class cxx = g++ cc = gcc @@ -30,7 +43,6 @@ show-size = : warnings = -Wall -Wextra -Werror -Wold-style-cast -Wunused-parameter \ -Winit-self -Wconversion -thread-cflags = -pthread thread-lflags = -lpthread cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \ @@ -63,7 +75,7 @@ stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src)) jni-sources = $(shell find $(classpath) -name '*.cpp') jni-objects = $(call cpp-objects,$(jni-sources),$(classpath)) jni-cflags = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux $(cflags) -jni-library = $(bld)/libnatives.so +jni-library = $(bld)/libnatives.$(so-extension) generated-code = \ $(bld)/type-enums.cpp \ @@ -213,11 +225,11 @@ $(jni-objects): $(bld)/%.o: $(classpath)/%.cpp $(jni-library): $(jni-objects) @echo "linking $(@)" - $(cc) $(lflags) -shared $(^) -o $(@) + $(cc) $(lflags) $(shared) $(^) -o $(@) $(executable): $(interpreter-objects) $(stdcpp-objects) @echo "linking $(@)" - $(cc) $(lflags) -rdynamic $(^) -o $(@) + $(cc) $(lflags) $(rdynamic) $(^) -o $(@) @$(strip) --strip-all $(@) @$(show-size) $(@) diff --git a/src/builtin.cpp b/src/builtin.cpp index 48dc22711e..cb15584d9a 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -1,4 +1,3 @@ -#include "builtin.h" #include "machine.h" #include "constants.h" #include "run.h" diff --git a/src/cdecl.S b/src/cdecl.S index 4abdc9aa09..9573eb9002 100644 --- a/src/cdecl.S +++ b/src/cdecl.S @@ -1,10 +1,10 @@ #include "types.h" .text -.globl cdeclCall -.type cdeclCall, @function +.globl _cdeclCall +//.type cdeclCall, @function -cdeclCall: +_cdeclCall: pushl %ebp movl %esp,%ebp diff --git a/src/common.h b/src/common.h index 3f0ba59894..5c9646c51a 100644 --- a/src/common.h +++ b/src/common.h @@ -11,11 +11,14 @@ #ifdef __i386__ # define LD "d" +# define ULD "lu" # define LLD "lld" #elif defined __x86_64__ # define LD "ld" +# define ULD "lu" # define LLD "ld" -# define LLD "ld" +#else +#error "Unsupported architecture" #endif #define NO_RETURN __attribute__((noreturn)) diff --git a/src/finder.cpp b/src/finder.cpp index f543ad090e..e4f808c74b 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -1,4 +1,4 @@ -#include "zlib.h" +#include "zlib-custom.h" #include "system.h" #include "finder.h" diff --git a/src/machine.h b/src/machine.h index 44266d1195..95c1528629 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1663,7 +1663,7 @@ inline uint32_t popInt(Thread* t) { if (DebugStack) { - fprintf(stderr, "pop int %"LD" at %d\n", + fprintf(stderr, "pop int %"ULD" at %d\n", t->stack[((t->sp - 1) * 2) + 1], t->sp - 1); } @@ -1721,7 +1721,7 @@ inline uint32_t peekInt(Thread* t, unsigned index) { if (DebugStack) { - fprintf(stderr, "peek int %"LD" at %d\n", + fprintf(stderr, "peek int %"ULD" at %d\n", t->stack[(index * 2) + 1], index); } diff --git a/src/system.cpp b/src/system.cpp index 021c54940c..12404c1646 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -25,7 +25,7 @@ cdeclCall(void* function, void* stack, unsigned stackSize, namespace { inline uint64_t -dynamicCall(void* function, uint32_t* arguments, uint8_t*, +dynamicCall(void* function, uintptr_t* arguments, uint8_t*, unsigned, unsigned argumentsSize, unsigned returnType) { return cdeclCall(function, arguments, argumentsSize, returnType); @@ -511,7 +511,7 @@ class MySystem: public System { count -= *up; if (Verbose) { - fprintf(stderr, "free %"LD"; count: %d; limit: %d\n", + fprintf(stderr, "free %"ULD"; count: %d; limit: %d\n", *up, count, limit); } diff --git a/src/zlib-custom.h b/src/zlib-custom.h new file mode 100644 index 0000000000..5f8cdb3c32 --- /dev/null +++ b/src/zlib-custom.h @@ -0,0 +1,7 @@ +#include "zlib.h" + +#ifdef inflateInit2 +#undef inflateInit2 +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, static_cast(sizeof(z_stream))) +#endif