Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use separate names for internal and exported functions #42151

Merged
merged 10 commits into from
Sep 27, 2021
6 changes: 3 additions & 3 deletions cli/jl_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ JL_EXPORTED_FUNCS_WIN(XX)
#endif
#undef XX

// Define holder locations for function addresses as `const void * $(name)_addr = & $(name);`
#define XX(name) JL_HIDDEN anonfunc * name##_addr = (anonfunc*)&name;
// Define holder locations for function addresses as `const void * $(name)_addr = NULL;
#define XX(name) JL_HIDDEN anonfunc * name##_addr = NULL;
JL_EXPORTED_FUNCS(XX)
#ifdef _OS_WINDOWS_
JL_EXPORTED_FUNCS_WIN(XX)
#endif
#undef XX

// Generate lists of function names and addresses
#define XX(name) #name,
#define XX(name) "i" #name,
static const char *const jl_exported_func_names[] = {
JL_EXPORTED_FUNCS(XX)
#ifdef _OS_WINDOWS_
Expand Down
2 changes: 1 addition & 1 deletion cli/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# endif
#define JL_HIDDEN
#else
# if defined(LIBRARY_EXPORTS) && defined(_OS_LINUX)
# if defined(LIBRARY_EXPORTS) && defined(_OS_LINUX_)
# define JL_DLLEXPORT __attribute__ ((visibility("protected")))
# else
# define JL_DLLEXPORT __attribute__ ((visibility("default")))
Expand Down
4 changes: 2 additions & 2 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
// Once we have libjulia-internal loaded, re-export its symbols:
for (unsigned int symbol_idx=0; jl_exported_func_names[symbol_idx] != NULL; ++symbol_idx) {
void *addr = lookup_symbol(libjulia_internal, jl_exported_func_names[symbol_idx]);
if (addr == NULL || addr == *jl_exported_func_addrs[symbol_idx]) {
jl_loader_print_stderr3("ERROR: Unable to load ", jl_exported_func_names[symbol_idx], " from libjulia-internal");
if (addr == NULL) {
jl_loader_print_stderr3("ERROR: Unable to load ", jl_exported_func_names[symbol_idx], " from libjulia-internal\n");
exit(1);
}
(*jl_exported_func_addrs[symbol_idx]) = addr;
Expand Down
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/julia_flisp.boot
/julia_flisp.boot.inc
/flisp.boot.inc
/jl_internal_funcs.inc

/libjulia-debug.a
/libjulia-debug.so
Expand Down
21 changes: 13 additions & 8 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ JLDFLAGS += $(LDFLAGS)
FLAGS := \
-D_GNU_SOURCE -I$(BUILDDIR) -I$(SRCDIR) \
-I$(SRCDIR)/flisp -I$(SRCDIR)/support \
-I$(LIBUV_INC) -I$(build_includedir) -DLIBRARY_EXPORTS \
-I$(LIBUV_INC) -I$(build_includedir) \
-I$(JULIAHOME)/deps/valgrind
ifneq ($(USEMSVC), 1)
FLAGS += -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -fvisibility=hidden -fno-common \
Expand Down Expand Up @@ -95,12 +95,13 @@ endif

# headers are used for dependency tracking, while public headers will be part of the dist
UV_HEADERS :=
HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h julia_internal.h options.h timing.h) $(addprefix $(BUILDDIR)/, $(DTRACE_HEADERS))
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h julia_gcext.h)
ifeq ($(USE_SYSTEM_LIBUV),0)
UV_HEADERS += uv.h
UV_HEADERS += uv/*.h
endif
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h)
HEADERS := $(PUBLIC_HEADERS) $(addprefix $(SRCDIR)/,julia_internal.h options.h timing.h) $(addprefix $(BUILDDIR)/,$(DTRACE_HEADERS) jl_internal_funcs.inc)
PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,julia_gcext.h)
PUBLIC_HEADER_TARGETS := $(addprefix $(build_includedir)/julia/,$(notdir $(PUBLIC_HEADERS)) $(UV_HEADERS))

LLVM_LDFLAGS := $(shell $(LLVM_CONFIG_HOST) --ldflags)
Expand Down Expand Up @@ -135,8 +136,8 @@ RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a

OBJS := $(SRCS:%=$(BUILDDIR)/%.o)
DOBJS := $(SRCS:%=$(BUILDDIR)/%.dbg.obj)
DEBUGFLAGS += $(FLAGS)
SHIPFLAGS += $(FLAGS)
DEBUGFLAGS += $(FLAGS) -DLIBRARY_EXPORTS
SHIPFLAGS += $(FLAGS) -DLIBRARY_EXPORTS

# if not absolute, then relative to the directory of the julia executable
SHIPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys.$(SHLIB_EXT)\""
Expand Down Expand Up @@ -178,6 +179,9 @@ $(BUILDDIR)/%.h.gen : $(SRCDIR)/%.d
sed 's/JULIA_/JL_PROBE_/' $@ > $@.tmp
mv $@.tmp $@

$(BUILDDIR)/jl_internal_funcs.inc: $(SRCDIR)/jl_exported_funcs.inc
grep 'XX(.\+)' $< | sed -E 's/.*XX\((.+)\).*/#define \1 i\1/g' >$@
vtjnash marked this conversation as resolved.
Show resolved Hide resolved

# source file rules
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(JCFLAGS) $(SHIPFLAGS) $(DISABLE_ASSERTIONS) -c $< -o $@)
Expand Down Expand Up @@ -213,7 +217,7 @@ else
JULIA_SPLITDEBUG := 0
endif
$(build_shlibdir)/libccalltest.$(SHLIB_EXT): $(SRCDIR)/ccalltest.c
@$(call PRINT_CC, $(CC) $(JCFLAGS) $(JCPPFLAGS) $(DEBUGFLAGS) -O3 $< $(fPIC) -shared -o $@.tmp $(JLDFLAGS))
@$(call PRINT_CC, $(CC) $(JCFLAGS) $(JCPPFLAGS) $(FLAGS) -O3 $< $(fPIC) -shared -o $@.tmp $(LDFLAGS))
$(INSTALL_NAME_CMD)libccalltest.$(SHLIB_EXT) $@.tmp
ifeq ($(JULIA_SPLITDEBUG),1)
@# Create split debug info file for libccalltest stacktraces test
Expand All @@ -230,7 +234,7 @@ endif
$(INSTALL_NAME_CMD)libccalltest.$(SHLIB_EXT) $@

$(build_shlibdir)/libllvmcalltest.$(SHLIB_EXT): $(SRCDIR)/llvmcalltest.cpp $(LLVM_CONFIG_ABSOLUTE)
@$(call PRINT_CC, $(CXX) $(LLVM_CXXFLAGS) $(JCXXFLAGS) $(JCPPFLAGS) $(DEBUGFLAGS) -O3 $< $(fPIC) -shared -o $@ $(JLDFLAGS) -L$(build_shlibdir) -L$(build_libdir) $(NO_WHOLE_ARCHIVE) $(LLVMLINK)) -lpthread
@$(call PRINT_CC, $(CXX) $(LLVM_CXXFLAGS) $(FLAGS) $(CPPFLAGS) $(CXXFLAGS) -O3 $< $(fPIC) -shared -o $@ $(LDFLAGS) $(COMMON_LIBPATHS) $(NO_WHOLE_ARCHIVE) $(LLVMLINK)) -lpthread

julia_flisp.boot.inc.phony: $(BUILDDIR)/julia_flisp.boot.inc

Expand Down Expand Up @@ -265,6 +269,7 @@ $(BUILDDIR)/llvm-alloc-opt.o $(BUILDDIR)/llvm-alloc-opt.dbg.obj: $(SRCDIR)/codeg
$(BUILDDIR)/llvm-final-gc-lowering.o $(BUILDDIR)/llvm-final-gc-lowering.dbg.obj: $(SRCDIR)/llvm-pass-helpers.h
$(BUILDDIR)/llvm-gc-invariant-verifier.o $(BUILDDIR)/llvm-gc-invariant-verifier.dbg.obj: $(SRCDIR)/codegen_shared.h
$(BUILDDIR)/llvm-late-gc-lowering.o $(BUILDDIR)/llvm-late-gc-lowering.dbg.obj: $(SRCDIR)/llvm-pass-helpers.h
$(BUILDDIR)/llvm-lower-handlers.o $(BUILDDIR)/llvm-lower-handlers.dbg.obj: $(SRCDIR)/codegen_shared.h
$(BUILDDIR)/llvm-multiversioning.o $(BUILDDIR)/llvm-multiversioning.dbg.obj: $(SRCDIR)/codegen_shared.h
$(BUILDDIR)/llvm-pass-helpers.o $(BUILDDIR)/llvm-pass-helpers.dbg.obj: $(SRCDIR)/llvm-pass-helpers.h $(SRCDIR)/codegen_shared.h
$(BUILDDIR)/llvm-ptls.o $(BUILDDIR)/llvm-ptls.dbg.obj: $(SRCDIR)/codegen_shared.h
Expand Down Expand Up @@ -367,7 +372,7 @@ $(build_shlibdir)/libGCCheckerPlugin.$(SHLIB_EXT): $(SRCDIR)/clangsa/GCChecker.c
install-analysis-deps:
$(MAKE) -C $(JULIAHOME)/deps install-llvm install-clang install-llvm-tools install-libuv install-utf8proc install-unwind

analyzegc-deps-check: $(BUILDDIR)/julia_version.h $(BUILDDIR)/julia_flisp.boot.inc
analyzegc-deps-check: $(BUILDDIR)/julia_version.h $(BUILDDIR)/julia_flisp.boot.inc $(BUILDDIR)/jl_internal_funcs.inc
ifeq ($(USE_BINARYBUILDER_LLVM),0)
ifneq ($(BUILD_LLVM_CLANG),1)
$(error Clang must be available to use the clang analyzer. Either build it (BUILD_LLVM_CLANG=1) or use BinaryBuilder)
Expand Down
7 changes: 4 additions & 3 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,13 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
return args[6 + i];
};

auto _is_libjulia_func = [&] (uintptr_t ptr, const char *name) {
auto _is_libjulia_func = [&] (uintptr_t ptr, StringRef name) {
if ((uintptr_t)fptr == ptr)
return true;
if (f_lib) {
#ifdef _OS_WINDOWS_
if ((f_lib == JL_EXE_LIBNAME) || // preventing invalid pointer access
(f_lib == JL_LIBJULIA_DL_LIBNAME) ||
(f_lib == JL_LIBJULIA_INTERNAL_DL_LIBNAME) ||
(!strcmp(f_lib, jl_crtdll_basename))) {
// libjulia-like
Expand All @@ -1280,9 +1281,9 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
return false;
#endif
}
return f_name && !strcmp(f_name, name);
return f_name && f_name == name;
};
#define is_libjulia_func(name) _is_libjulia_func((uintptr_t)&(name), #name)
#define is_libjulia_func(name) _is_libjulia_func((uintptr_t)&(name), StringRef(#name))

// emit arguments
jl_cgval_t *argv = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * nccallargs);
Expand Down
Loading