refactor build system to support cross-compiling

This commit is contained in:
Joel Dice 2007-10-22 14:56:27 -06:00
parent 3e84d4438a
commit ac4b28ffe6
10 changed files with 140 additions and 113 deletions

170
makefile
View File

@ -1,43 +1,37 @@
MAKEFLAGS = -s
arch = $(shell uname -m)
ifeq ($(arch),i586)
arch = i386
input = $(cls)/Memory.class
build-arch = $(shell uname -m)
ifeq ($(build-arch),i586)
build-arch = i386
endif
ifeq ($(arch),i686)
arch = i386
ifeq ($(build-arch),i686)
build-arch = i386
endif
platform = $(shell uname -s | tr [:upper:] [:lower:])
build-platform = $(shell uname -s | tr [:upper:] [:lower:])
ifeq ($(platform),darwin)
rdynamic =
thread-cflags =
shared = -dynamiclib
so-extension = jnilib
ld-library-path = DYLD_LIBRARY_PATH
else
rdynamic = -rdynamic
thread-cflags = -pthread
shared = -shared
so-extension = so
ld-library-path = LD_LIBRARY_PATH
endif
arch = $(build-arch)
platform = $(build-platform)
process = interpret
mode = debug
build-dir = build/$(build-platform)/$(build-arch)
bld = build/$(platform)/$(arch)/$(mode)
cls = build/classes
src = src
classpath = classpath
test = test
input = $(cls)/Memory.class
build-cxx = g++
build-cc = gcc
cxx = g++
cc = gcc
cxx = $(build-cxx)
cc = $(build-cc)
vg = nice valgrind --suppressions=valgrind.supp --undef-value-errors=no \
--num-callers=32 --db-attach=yes --freelist-vol=100000000
db = gdb --args
@ -45,49 +39,80 @@ javac = javac
strip = :
show-size = :
rdynamic = -rdynamic
thread-cflags = -pthread
shared = -shared
so-extension = so
ld-library-path = LD_LIBRARY_PATH
warnings = -Wall -Wextra -Werror -Wunused-parameter \
-Winit-self -Wconversion
thread-lflags = -lpthread
cflags = $(warnings) -fPIC -fno-rtti -fno-exceptions -fvisibility=hidden \
-I$(src) -I$(bld) $(thread-cflags) -D__STDC_LIMIT_MACROS
-I$(src) -I$(build-dir) $(thread-cflags) -D__STDC_LIMIT_MACROS
lflags = $(thread-lflags) -ldl -lm -lz
lflags = -lpthread -ldl -lm -lz
system = posix
ifeq ($(platform),darwin)
rdynamic =
thread-cflags =
shared = -dynamiclib
so-extension = jnilib
ld-library-path = DYLD_LIBRARY_PATH
endif
ifeq ($(platform),windows)
inc = ../6.0/shared/include/msw
lib = ../6.0/shared/lib/native/msw
system = windows
cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc
rdynamic =
so-extension = dll
thread-cflags =
lflags = -L$(lib) -lm -lz -Wl,--kill-at
cflags = $(warnings) -fno-rtti -fno-exceptions -I$(src) -I$(build-dir) \
$(thread-cflags) -D__STDC_LIMIT_MACROS -I$(inc)
endif
ifeq ($(mode),debug)
cflags += -O0 -g3
cflags += -O0 -g3
endif
ifeq ($(mode),stress)
cflags += -O0 -g3 -DVM_STRESS
cflags += -O0 -g3 -DVM_STRESS
endif
ifeq ($(mode),stress-major)
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
endif
ifeq ($(mode),fast)
cflags += -O3 -DNDEBUG
strip = strip
show-size = ls -l
cflags += -O3 -DNDEBUG
strip = strip
show-size = ls -l
endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x)))
asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(bld)/%-asm.o,$(x)))
ifeq ($(arch),i386)
pointer-size = 4
else
pointer-size = 8
endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x)))
asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(cls)/%.class,$(x)))
stdcpp-sources = $(src)/stdc++.cpp
stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src))
jni-sources = $(shell find $(classpath) -name '*.cpp')
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath))
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(bld))
jni-cflags = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux $(cflags)
jni-library = $(bld)/libnatives.$(so-extension)
generated-code = \
$(bld)/type-enums.cpp \
$(bld)/type-declarations.cpp \
$(bld)/type-constructors.cpp \
$(bld)/type-initializations.cpp \
$(bld)/type-java-initializations.cpp
$(build-dir)/type-enums.cpp \
$(build-dir)/type-declarations.cpp \
$(build-dir)/type-constructors.cpp \
$(build-dir)/type-initializations.cpp \
$(build-dir)/type-java-initializations.cpp
interpreter-depends = \
$(generated-code) \
@ -103,7 +128,7 @@ interpreter-depends = \
$(src)/machine.h
interpreter-sources = \
$(src)/system.cpp \
$(src)/$(system).cpp \
$(src)/finder.cpp \
$(src)/machine.cpp \
$(src)/heap.cpp \
@ -112,12 +137,16 @@ interpreter-sources = \
$(src)/jnienv.cpp \
$(src)/main.cpp
interpreter-asm-sources = $(src)/compile.S $(src)/system.S
interpreter-asm-sources = $(src)/$(system).S
ifeq ($(process),compile)
interpreter-asm-sources += $(src)/compile.S
endif
interpreter-cpp-objects = \
$(call cpp-objects,$(interpreter-sources),$(src))
$(call cpp-objects,$(interpreter-sources),$(src),$(bld))
interpreter-asm-objects = \
$(call asm-objects,$(interpreter-asm-sources),$(src))
$(call asm-objects,$(interpreter-asm-sources),$(src),$(bld))
interpreter-objects = \
$(interpreter-cpp-objects) \
$(interpreter-asm-objects)
@ -127,8 +156,9 @@ generator-headers = \
$(src)/output.h
generator-sources = \
$(src)/type-generator.cpp
generator-objects = $(call cpp-objects,$(generator-sources),$(src))
generator-executable = $(bld)/generator
generator-objects = $(call \
cpp-objects,$(generator-sources),$(src),$(build-dir))
generator-executable = $(build-dir)/generator
executable = $(bld)/vm
@ -157,15 +187,15 @@ run: build
.PHONY: debug
debug: build
LD_LIBRARY_PATH=$(bld) gdb --args $(executable) $(args)
$(ld-library-path)=$(bld) gdb --args $(executable) $(args)
.PHONY: vg
vg: build
LD_LIBRARY_PATH=$(bld) $(vg) $(executable) $(args)
$(ld-library-path)=$(bld) $(vg) $(executable) $(args)
.PHONY: test
test: build
LD_LIBRARY_PATH=$(bld) /bin/bash $(test)/test.sh 2>/dev/null \
$(ld-library-path)=$(bld) /bin/bash $(test)/test.sh 2>/dev/null \
$(executable) $(mode) "$(flags)" $(call class-names,$(test-classes))
.PHONY: clean
@ -175,15 +205,15 @@ clean:
.PHONY: clean-native
clean-native:
@echo "removing $(bld)"
rm -rf $(bld)
@echo "removing $(bld) and $(build-dir)"
rm -rf $(bld) $(build-dir)
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
gen-arg = $(shell echo $(1) | sed -e 's:$(build-dir)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@echo "generating $(@)"
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
$(bld)/type-generator.o: \
$(build-dir)/type-generator.o: \
$(generator-headers)
define compile-class
@ -206,17 +236,16 @@ define compile-object
$(cxx) $(cflags) -c $(<) -o $(@)
endef
$(stdcpp-objects): $(bld)/%.o: $(src)/%.cpp
$(compile-object)
$(interpreter-cpp-objects): $(bld)/%.o: $(src)/%.cpp $(interpreter-depends)
$(compile-object)
$(interpreter-asm-objects): $(bld)/%-asm.o: $(src)/%.S
$(compile-object)
$(generator-objects): $(bld)/%.o: $(src)/%.cpp
$(compile-object)
$(generator-objects): $(build-dir)/%.o: $(src)/%.cpp
@echo "compiling $(@)"
@mkdir -p $(dir $(@))
$(build-cxx) $(cflags) -c $(<) -o $(@)
$(jni-objects): $(bld)/%.o: $(classpath)/%.cpp
@echo "compiling $(@)"
@ -225,25 +254,14 @@ $(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) $(@)
.PHONY: generator
generator: $(generator-executable)
.PHONY: run-generator
run-generator: $(generator-executable)
$(<) < $(src)/types.def
.PHONY: vg-generator
vg-generator: $(generator-executable)
$(vg) $(<) < $(src)/types.def
$(generator-executable): $(generator-objects) $(stdcpp-objects)
$(generator-executable): $(generator-objects)
@echo "linking $(@)"
$(cc) $(lflags) $(^) -o $(@)
$(build-cc) -DPOINTER_SIZE=$(pointer-size) $(^) -o $(@)

View File

@ -45,6 +45,8 @@
inline void* operator new(size_t, void* p) throw() { return p; }
inline void operator delete(void*) { abort(); }
namespace vm {
const unsigned BytesPerWord = sizeof(uintptr_t);

View File

@ -1550,16 +1550,18 @@ exit(Thread* t)
object f = *p;
*p = finalizerNext(t, *p);
reinterpret_cast<void (*)(Thread*, object)>(finalizerFinalize(t, f))
(t, finalizerTarget(t, f));
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
}
for (object* p = &(t->m->tenuredFinalizers); *p;) {
object f = *p;
*p = finalizerNext(t, *p);
reinterpret_cast<void (*)(Thread*, object)>(finalizerFinalize(t, f))
(t, finalizerTarget(t, f));
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
}
disposeAll(t, t->m->rootThread);
@ -2390,7 +2392,10 @@ addFinalizer(Thread* t, object target, void (*finalize)(Thread*, object))
ACQUIRE(t, t->m->referenceLock);
object f = makeFinalizer(t, 0, reinterpret_cast<void*>(finalize), 0);
void* function;
memcpy(&function, &finalize, BytesPerWord);
object f = makeFinalizer(t, 0, function, 0);
finalizerTarget(t, f) = target;
finalizerNext(t, f) = t->m->finalizers;
t->m->finalizers = f;
@ -2602,8 +2607,9 @@ collect(Thread* t, Heap::CollectionType type)
postCollect(m->rootThread);
for (object f = m->finalizeQueue; f; f = finalizerNext(t, f)) {
reinterpret_cast<void (*)(Thread*, object)>(finalizerFinalize(t, f))
(t, finalizerTarget(t, f));
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
}
m->finalizeQueue = 0;

View File

@ -7,6 +7,8 @@
using namespace vm;
extern "C" void __cxa_pure_virtual(void) { abort(); }
namespace {
int

View File

@ -1,13 +0,0 @@
#include "stdlib.h"
extern "C" void
__cxa_pure_virtual(void)
{
abort();
}
void
operator delete(void*)
{
abort();
}

View File

@ -8,21 +8,31 @@
#define UNREACHABLE abort()
inline void operator delete(void*) { abort(); }
extern "C" void __cxa_pure_virtual(void) { abort(); }
namespace {
#ifndef POINTER_SIZE
# define POINTER_SIZE sizeof(void*)
#endif
const unsigned BytesPerWord = POINTER_SIZE;
inline unsigned
pad(unsigned size, unsigned alignment)
{
unsigned n = alignment;
while (size and n % size and n % sizeof(void*)) ++ n;
while (size and n % size and n % BytesPerWord) ++ n;
return n - alignment;
}
inline unsigned
pad(unsigned n)
{
unsigned extra = n % sizeof(void*);
return (extra ? n + sizeof(void*) - extra : n);
unsigned extra = n % BytesPerWord;
return (extra ? n + BytesPerWord - extra : n);
}
template <class T>
@ -393,7 +403,7 @@ addMember(Object* o, Object* member)
case Object::Type: case Object::Pod:
if (member->type == Object::Array) {
static_cast<Type*>(o)->members.append
(Scalar::make(o, 0, "uintptr_t", "length", sizeof(uintptr_t)));
(Scalar::make(o, 0, "uintptr_t", "length", BytesPerWord));
}
static_cast<Type*>(o)->members.append(member);
break;
@ -664,7 +674,7 @@ class MemberIterator {
members(0),
member(0),
index_(-1),
offset_(type->type == Object::Pod ? 0 : sizeof(void*)),
offset_(type->type == Object::Pod ? 0 : BytesPerWord),
size_(0),
padding_(0),
alignment_(0)
@ -705,7 +715,7 @@ class MemberIterator {
case Object::Scalar: {
size_ = memberSize(member);
padding_ = pad(size_, alignment_);
alignment_ = (alignment_ + size_ + padding_) % sizeof(void*);
alignment_ = (alignment_ + size_ + padding_) % BytesPerWord;
} break;
case Object::Array: {
@ -777,9 +787,9 @@ unsigned
sizeOf(const char* type, Object* declarations)
{
if (equal(type, "object")) {
return sizeof(void*);
return BytesPerWord;
} else if (equal(type, "intptr_t")) {
return sizeof(intptr_t);
return BytesPerWord;
} else if (equal(type, "unsigned") or equal(type, "int")) {
return sizeof(int);
} else if (equal(type, "bool")) {
@ -797,7 +807,7 @@ sizeOf(const char* type, Object* declarations)
} else if (endsWith("[0]", type)) {
return 0;
} else if (namesPointer(type)) {
return sizeof(void*);
return BytesPerWord;
} else {
Object* dec = declaration(type, declarations);
if (dec) return typeSize(dec);
@ -1186,7 +1196,7 @@ typeBodyOffset(Object* type, Object* offset)
default: UNREACHABLE;
}
}
unsigned padding = pad(sizeof(void*), it.alignment());
unsigned padding = pad(BytesPerWord, it.alignment());
if (padding) offset = cons(Number::make(padding), offset);
return offset;
}
@ -1198,7 +1208,7 @@ typeOffset(Object* type, Object* super)
return typeBodyOffset(super, typeOffset(super, typeSuper(super)));
} else {
return (type->type == Object::Type ?
cons(Number::make(sizeof(void*)), 0) : 0);
cons(Number::make(BytesPerWord), 0) : 0);
}
}
@ -1489,7 +1499,7 @@ set(uint32_t* mask, unsigned index)
unsigned
typeFixedSize(Object* type)
{
unsigned length = sizeof(void*);
unsigned length = BytesPerWord;
for (MemberIterator it(type); it.hasMore();) {
Object* m = it.next();
switch (m->type) {
@ -1527,13 +1537,13 @@ uint32_t
typeObjectMask(Object* type)
{
assert(typeFixedSize(type) + typeArrayElementSize(type)
< 32 * sizeof(void*));
< 32 * BytesPerWord);
uint32_t mask = 1;
for (MemberIterator it(type); it.hasMore();) {
Object* m = it.next();
unsigned offset = it.offset() / sizeof(void*);
unsigned offset = it.offset() / BytesPerWord;
switch (m->type) {
case Object::Scalar: {
@ -1551,7 +1561,7 @@ typeObjectMask(Object* type)
for (MemberIterator it(memberTypeObject(m)); it.hasMore();) {
Object* m = it.next();
if (memberGC(m)) {
set(&mask, offset + (it.offset() / sizeof(void*)));
set(&mask, offset + (it.offset() / BytesPerWord));
}
}
}
@ -1657,14 +1667,14 @@ writeInitializations(Output* out, Object* declarations)
out->write("t->m->types = allocate(t, pad((");
out->write(count);
out->write(" * sizeof(void*)) + sizeof(uintptr_t) + sizeof(void*)));\n");
out->write(" * BytesPerWord) + (BytesPerWord * 2)));\n");
out->write("cast<object>(t->m->types, 0) = 0;\n");
out->write("arrayLength(t, t->m->types) = ");
out->write(count);
out->write(";\n");
out->write("memset(&arrayBody(t, t->m->types, 0), 0, ");
out->write(count);
out->write(" * sizeof(void*));\n\n");
out->write(" * BytesPerWord);\n\n");
declarations = reorder(declarations);

1
src/windows.S Normal file
View File

@ -0,0 +1 @@
// todo

1
src/windows.cpp Normal file
View File

@ -0,0 +1 @@
// todo