Skip to content

Commit

Permalink
create a compile option for a Julia that is not linked against llvm (…
Browse files Browse the repository at this point in the history
…other than libLLVMSupport.a for APInt support)
  • Loading branch information
vtjnash committed Oct 7, 2015
1 parent 5f32773 commit ac66b65
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 399 deletions.
1 change: 1 addition & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ EXE :=
endif

JULIAGC := MARKSWEEP
JULIACODEGEN := LLVM
USE_COPY_STACKS := 1

# flag for disabling assertions
Expand Down
39 changes: 25 additions & 14 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,44 @@ override CFLAGS += $(JCFLAGS)
override CXXFLAGS += $(JCXXFLAGS)
override CPPFLAGS += $(JCPPFLAGS)

SRCS := \
jltypes gf ast builtins module codegen disasm debuginfo interpreter \
alloc dlload sys init task array dump toplevel jl_uv jlapi signal-handling \
llvm-simdloop simplevector APInt-C runtime_intrinsics
ifeq ($(JULIAGC),MARKSWEEP)
SRCS += gc
endif

HEADERS := $(addprefix $(SRCDIR)/,julia.h julia_internal.h options.h) $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(LIBUV_INC)/uv.h

# -I BUILDDIR comes before -I SRCDIR so that the user can override <options.h> on a per-build-directory basis
# for gcc/clang, suggested content is:
# #include_next <options.h>
# #define ARGUMENT_TO_OVERRIDE 1
FLAGS := \
-D_GNU_SOURCE -I$(BUILDDIR) -I$(SRCDIR) \
-I$(SRCDIR)/flisp -I$(SRCDIR)/support \
-I$(shell $(LLVM_CONFIG_HOST) --includedir) \
-I$(LIBUV_INC) -I$(build_includedir) -DLIBRARY_EXPORTS \
-I$(JULIAHOME)/deps/valgrind
ifneq ($(USEMSVC), 1)
FLAGS += -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -fvisibility=hidden -fno-common
endif


SRCS := \
jltypes gf ast builtins module interpreter \
alloc dlload sys init task array dump toplevel jl_uv jlapi signal-handling \
simplevector APInt-C runtime_intrinsics runtime_ccall
ifeq ($(JULIAGC),MARKSWEEP)
SRCS += gc
endif

ifeq ($(JULIACODEGEN),LLVM)
SRCS += codegen disasm debuginfo llvm-simdloop
FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --includedir)
LLVM_LIBS := all
else
SRCS += anticodegen
LLVM_LIBS := support
endif

HEADERS := $(addprefix $(SRCDIR)/,julia.h julia_internal.h options.h) $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(LIBUV_INC)/uv.h

# In LLVM < 3.4, --ldflags includes both options and libraries, so use it both before and after --libs
# In LLVM >= 3.4, --ldflags has only options, and --system-libs has the libraries.
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --libs) $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null)
ifeq ($(USE_LLVM_SHLIB),1)
ifneq ($(USE_LLVM_SHLIB),1)
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --libs $(LLVM_LIBS)) $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null)
else
ifeq ($(LLVM_USE_CMAKE),1)
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) -lLLVM
else
Expand Down Expand Up @@ -102,7 +112,8 @@ $(BUILDDIR)/julia_flisp.boot: $(addprefix $(SRCDIR)/,jlfrontend.scm \
$(call cygpath_w,$(SRCDIR)/mk_julia_flisp_boot.scm) $(call cygpath_w,$(dir $<)) $(notdir $<) $(call cygpath_w,$@))

$(BUILDDIR)/ast.o $(BUILDDIR)/ast.dbg.obj: $(BUILDDIR)/julia_flisp.boot.inc $(SRCDIR)/flisp/*.h
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,intrinsics.cpp cgutils.cpp ccall.cpp abi_*.cpp)
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,intrinsics.cpp intrinsics.h cgutils.cpp ccall.cpp abi_*.cpp)
$(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.h
$(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/table.c
$(BUILDDIR)/gc.o $(BUILDDIR)/gc.dbg.obj: $(SRCDIR)/gc-debug.c
$(BUILDDIR)/signal-handling.o $(BUILDDIR)/signal-handling.dbg.obj: $(addprefix $(SRCDIR)/,signals-*.c)
Expand Down
9 changes: 9 additions & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,15 @@ jl_value_t *jl_box_bool(int8_t x)
return jl_false;
}

DLLEXPORT jl_value_t *jl_new_box(jl_value_t *v)
{
jl_value_t *box = (jl_value_t*)jl_gc_alloc_1w();
jl_set_typeof(box, jl_box_any_type);
// if (v) jl_gc_wb(box, v); // write block not needed: box was just allocated
box->fieldptr[0] = v;
return box;
}

// Expr constructor for internal use ------------------------------------------

jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
Expand Down
50 changes: 50 additions & 0 deletions src/anticodegen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "julia.h"
#include "julia_internal.h"

#include "intrinsics.h"

int globalUnique = 0;

#define UNAVAILABLE { jl_errorf("%s: not available in this build of Julia", __func__); }

void jl_dump_bitcode(char *fname, const char *sysimg_data, size_t sysimg_len) UNAVAILABLE
void jl_dump_objfile(char *fname, int jit_model, const char *sysimg_data, size_t sysimg_len) UNAVAILABLE
int32_t jl_get_llvm_gv(jl_value_t *p) UNAVAILABLE
void jl_write_malloc_log(void) UNAVAILABLE
void jl_write_coverage_data(void) UNAVAILABLE
void jl_generate_fptr(jl_function_t *f) {
jl_lambda_info_t *li = f->linfo;
if (li->fptr == &jl_trampoline) UNAVAILABLE
f->fptr = li->fptr;
}

DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE
DLLEXPORT void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE
DLLEXPORT const jl_value_t *jl_dump_function_asm(void *f, int raw_mc) UNAVAILABLE
DLLEXPORT const jl_value_t *jl_dump_function_ir(void *f, uint8_t strip_ir_metadata, uint8_t dump_module) UNAVAILABLE

void jl_init_codegen(void) { }
void jl_compile(jl_function_t *f) { }
void jl_fptr_to_llvm(void *fptr, jl_lambda_info_t *lam, int specsig)
{
if (!specsig)
lam->fptr = (jl_fptr_t)fptr;
}
void jl_getFunctionInfo(char **name, char **filename, size_t *line,
char **inlinedat_file, size_t *inlinedat_line,
size_t pointer, int *fromC, int skipC, int skipInline)
{
*name = NULL;
*line = -1;
*filename = NULL;
*inlinedat_file = NULL;
*inlinedat_line = -1;
*fromC = 0;
}

jl_value_t *jl_static_eval(jl_value_t *ex, void *ctx_, jl_module_t *mod,
jl_value_t *sp, jl_expr_t *ast, int sparams, int allow_alloc)
{
return NULL;
}
128 changes: 4 additions & 124 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
@@ -1,126 +1,6 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

// --- the ccall intrinsic ---

// --- library symbol lookup ---

// map from "libX" to full soname "libX.so.ver"
#if defined(__linux__) || defined(__FreeBSD__)
static std::map<std::string, std::string> sonameMap;
static bool got_sonames = false;

extern "C" DLLEXPORT void jl_read_sonames(void)
{
char *line=NULL;
size_t sz=0;
#if defined(__linux__)
FILE *ldc = popen("/sbin/ldconfig -p", "r");
#else
FILE *ldc = popen("/sbin/ldconfig -r", "r");
#endif

while (!feof(ldc)) {
ssize_t n = getline(&line, &sz, ldc);
if (n == -1)
break;
if (n > 2 && isspace((unsigned char)line[0])) {
#ifdef __linux__
int i = 0;
while (isspace((unsigned char)line[++i])) ;
char *name = &line[i];
char *dot = strstr(name, ".so");
i = 0;
#else
char *name = strstr(line, ":-l");
if (name == NULL) continue;
strncpy(name, "lib", 3);
char *dot = strchr(name, '.');
#endif

if (NULL == dot)
continue;

#ifdef __linux__
// Detect if this entry is for the current architecture
while (!isspace((unsigned char)dot[++i])) ;
while (isspace((unsigned char)dot[++i])) ;
int j = i;
while (!isspace((unsigned char)dot[++j])) ;
char *arch = strstr(dot+i,"x86-64");
if (arch != NULL && arch < dot + j) {
#ifdef _P32
continue;
#endif
}
else {
#ifdef _P64
continue;
#endif
}
#endif // __linux__

char *abslibpath = strrchr(line, ' ');
if (dot != NULL && abslibpath != NULL) {
std::string pfx(name, dot - name);
// Do not include ' ' in front and '\n' at the end
std::string soname(abslibpath+1, line+n-(abslibpath+1)-1);
sonameMap[pfx] = soname;
}
}
}

free(line);
pclose(ldc);
}

extern "C" DLLEXPORT const char *jl_lookup_soname(const char *pfx, size_t n)
{
if (!got_sonames) {
jl_read_sonames();
got_sonames = true;
}
std::string str(pfx, n);
if (sonameMap.find(str) != sonameMap.end()) {
return sonameMap[str].c_str();
}
return NULL;
}
#endif

// map from user-specified lib names to handles
static std::map<std::string, uv_lib_t*> libMap;

static uv_lib_t *get_library(char *lib)
{
uv_lib_t *hnd;
#ifdef _OS_WINDOWS_
if ((intptr_t)lib == 1)
return jl_exe_handle;
if ((intptr_t)lib == 2)
return jl_dl_handle;
#endif
if (lib == NULL)
return jl_RTLD_DEFAULT_handle;
hnd = libMap[lib];
if (hnd != NULL)
return hnd;
hnd = (uv_lib_t *) jl_load_dynamic_library(lib, JL_RTLD_DEFAULT);
if (hnd != NULL)
libMap[lib] = hnd;
return hnd;
}

extern "C" DLLEXPORT
void *jl_load_and_lookup(char *f_lib, char *f_name, uv_lib_t **hnd)
{
uv_lib_t *handle = *hnd;
if (!handle)
*hnd = handle = get_library(f_lib);
void *ptr = jl_dlsym_e(handle, f_name);
if (!ptr)
jl_errorf("symbol \"%s\" could not be found: %s", f_name, uv_dlerror(handle));
return ptr;
}
// --- the ccall, cglobal, and llvm intrinsics ---

static std::map<std::string, GlobalVariable*> libMapGV;
static std::map<std::string, GlobalVariable*> symMapGV;
Expand Down Expand Up @@ -161,7 +41,7 @@ static Value *runtime_sym_lookup(PointerType *funcptype, char *f_lib, char *f_na
false, GlobalVariable::PrivateLinkage,
initnul, f_lib);
libMapGV[f_lib] = libptrgv;
libsym = get_library(f_lib);
libsym = jl_get_library(f_lib);
assert(libsym != NULL);
#ifdef USE_MCJIT
jl_llvm_to_jl_value[libptrgv] = libsym;
Expand Down Expand Up @@ -565,7 +445,7 @@ static jl_cgval_t emit_cglobal(jl_value_t **args, size_t nargs, jl_codectx_t *ct
res = runtime_sym_lookup((PointerType*)lrt, sym.f_lib, sym.f_name, ctx);
}
else {
void *symaddr = jl_dlsym_e(get_library(sym.f_lib), sym.f_name);
void *symaddr = jl_dlsym_e(jl_get_library(sym.f_lib), sym.f_name);
if (symaddr == NULL) {
std::stringstream msg;
msg << "cglobal: could not find symbol ";
Expand Down Expand Up @@ -1370,7 +1250,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
llvmf = runtime_sym_lookup(funcptype, f_lib, f_name, ctx);
}
else {
void *symaddr = jl_dlsym_e(get_library(f_lib), f_name);
void *symaddr = jl_dlsym_e(jl_get_library(f_lib), f_name);
if (symaddr == NULL) {
JL_GC_POP();
std::stringstream msg;
Expand Down
20 changes: 0 additions & 20 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,17 +658,6 @@ extern "C" {
int globalUnique = 0;
}

extern "C" DLLEXPORT
jl_value_t *jl_get_cpu_name(void)
{
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5
std::string HostCPUName = llvm::sys::getHostCPUName();
#else
StringRef HostCPUName = llvm::sys::getHostCPUName();
#endif
return jl_pchar_to_string(HostCPUName.data(), HostCPUName.size());
}

static void emit_write_barrier(jl_codectx_t*, Value*, Value*);

#include "cgutils.cpp"
Expand Down Expand Up @@ -5208,15 +5197,6 @@ extern "C" void jl_fptr_to_llvm(void *fptr, jl_lambda_info_t *lam, int specsig)
}
}

extern "C" DLLEXPORT jl_value_t *jl_new_box(jl_value_t *v)
{
jl_value_t *box = (jl_value_t*)jl_gc_alloc_1w();
jl_set_typeof(box, jl_box_any_type);
// if (v) jl_gc_wb(box, v); // write block not needed: box was just allocated
box->fieldptr[0] = v;
return box;
}

#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 3 && SYSTEM_LLVM
#define INSTCOMBINE_BUG
#define V128_BUG
Expand Down
Loading

0 comments on commit ac66b65

Please sign in to comment.