Skip to content

Commit

Permalink
Fix broken linking and initialization due to JuliaLang#36588
Browse files Browse the repository at this point in the history
And speed up startup.
  • Loading branch information
yuyichao committed Sep 25, 2020
1 parent 3b55dae commit 18daf29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ $(build_bindir)/julia-debug$(EXE): $(BUILDDIR)/Info.plist
endif

$(build_shlibdir)/libjulialoader.$(JL_MAJOR_MINOR_SHLIB_EXT): $(LIB_OBJS)
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) -shared $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH_LIB))
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) -shared $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH_LIB)) $(build_shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT)
ifneq ($(OS), WINNT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader.$(JL_MAJOR_SHLIB_EXT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader.$(SHLIB_EXT)
endif


$(build_shlibdir)/libjulialoader-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(LIB_DOBJS)
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) -shared $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH_LIB))
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) -shared $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH_LIB)) $(build_shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT)
ifneq ($(OS), WINNT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader-debug.$(JL_MAJOR_SHLIB_EXT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader-debug.$(SHLIB_EXT)
endif

$(build_bindir)/julia$(EXE): $(OBJS)
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH))
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH) $(build_shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT))

$(build_bindir)/julia-debug$(EXE): $(DOBJS)
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH))
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS) $(RPATH) $(build_shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT))


clean: | $(CLEAN_TARGETS)
Expand Down
9 changes: 7 additions & 2 deletions cli/loader_exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ extern "C" {

/* Define ptls getter, as this cannot be defined within a shared library. */
#if !defined(_OS_WINDOWS_) && !defined(_OS_DARWIN_)
__attribute__ ((visibility("default"))) JL_CONST_FUNC void * jl_get_ptls_states_static(void)
void jl_set_ptls_states_getter(void *(*f)(void));
static JL_CONST_FUNC void * jl_get_ptls_states_static(void)
{
/* Because we can't #include <julia.h> in this file, we define a TLS state object with
* hopefully enough room; at last check, the `jl_tls_states_t` struct was <16KB. */
static __attribute__((tls_model("local-exec"))) __thread char tls_states[32768];
return &tls_states;
}
__attribute__((constructor)) void jl_register_ptls_states_getter(void)
{
jl_set_ptls_states_getter(jl_get_ptls_states_static);
}
#endif

#ifdef _OS_WINDOWS_
Expand All @@ -27,7 +32,7 @@ int main(int argc, char * argv[])
{
#endif
// Immediately get the current exe dir, allowing us to calculate relative paths.
const char * exe_dir = get_exe_dir();
const char * exe_dir = NULL; // get_exe_dir();

#ifdef _OS_WINDOWS_
// Convert Windows wchar_t values to UTF8
Expand Down
3 changes: 3 additions & 0 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ const char * get_exe_dir()
return exe_dir;
}

int repl_entrypoint(int argc, char *argv[]);

// Load libjulia and run the REPL with the given arguments (in UTF-8 format)
int load_repl(const char * exe_dir, int argc, char * argv[])
{
return repl_entrypoint(argc, (char **)argv);
// Pre-load libraries that libjulia needs.
int deps_len = strlen(dep_libs);
char * curr_dep = &dep_libs[0];
Expand Down

0 comments on commit 18daf29

Please sign in to comment.