Skip to content

Commit

Permalink
Clean up handling of compiler support libraries
Browse files Browse the repository at this point in the history
This cleanup eliminates many of the old code paths involved in loading
the correct compiler support libraries (such as `libgcc_s`) by working
it into the JLL stdlib framework.  Additionally, it eliminates many
FreeBSD-specific code paths, as all platforms now collect the CSLs
before build.
  • Loading branch information
staticfloat committed Apr 22, 2020
1 parent 3875180 commit d8c4cfc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 76 deletions.
3 changes: 3 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,10 @@ endif # $(OS) == WINNT
ifeq ($(USE_BINARYBUILDER_CSL),1)
$(eval $(call find_artifact,CompilerSupportLibraries_jll))
CSL_SHLIBDIR = $(CompilerSupportLibraries_jll_DIR)/$(binlib)
else
CSL_SHLIBDIR = $(build_shlibdir)
endif
CSL_LINK = -L$(CSL_SHLIBDIR) $(call rpath_rel_link,$(CSL_SHLIBDIR))


ifeq ($(origin LLVM_CONFIG), undefined)
Expand Down
102 changes: 32 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,42 @@ ifeq ($(BUNDLE_DEBUG_LIBS),1)
JL_TARGETS += julia-debug
endif

# private libraries, that are installed in $(prefix)/lib/julia
JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest
ifeq ($(USE_GPL_LIBS), 1)
JL_PRIVATE_LIBS-0 += libsuitesparse_wrapper
JL_PRIVATE_LIBS-$(USE_SYSTEM_SUITESPARSE) += libamd libcamd libccolamd libcholmod libcolamd libumfpack libspqr libsuitesparseconfig
endif
JL_PRIVATE_LIBS-$(USE_SYSTEM_PCRE) += libpcre2-8
JL_PRIVATE_LIBS-$(USE_SYSTEM_DSFMT) += libdSFMT
JL_PRIVATE_LIBS-$(USE_SYSTEM_GMP) += libgmp
JL_PRIVATE_LIBS-$(USE_SYSTEM_MPFR) += libmpfr
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBSSH2) += libssh2
JL_PRIVATE_LIBS-$(USE_SYSTEM_MBEDTLS) += libmbedtls libmbedcrypto libmbedx509
JL_PRIVATE_LIBS-$(USE_SYSTEM_CURL) += libcurl
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBGIT2) += libgit2
ifeq ($(OS),WINNT)
JL_PRIVATE_LIBS-$(USE_SYSTEM_ZLIB) += zlib
# private libraries that are installed in $(prefix)/lib/julia and need to be installed to
# the installation prefix for distribution. Note that libraries provided by BB will not
# be installed in this fashion; they are safely tucked away in the `artifacts` directory.
define register_private_lib
ifeq ($(USE_SYSTEM_$(1)),1)
JL_PRIVATE_LIBS-1 += $(2)
else ifeq ($(USE_BINARYBUILDER_$(1)),1)
JL_PRIVATE_LIBS-2 += $(2)
else
JL_PRIVATE_LIBS-$(USE_SYSTEM_ZLIB) += libz
endif
ifeq ($(USE_LLVM_SHLIB),1)
JL_PRIVATE_LIBS-$(USE_SYSTEM_LLVM) += libLLVM libLLVM-9jl
JL_PRIVATE_LIBS-0 += $(2)
endif
endef

ifeq ($(USE_SYSTEM_LIBM),0)
JL_PRIVATE_LIBS-$(USE_SYSTEM_OPENLIBM) += libopenlibm
$(eval $(call register_private_lib,,libccalltest libllvmcalltest))
ifeq ($(USE_GPL_LIBS), 1)
$(eval $(call register_private_lib,,libsuitesparse_wrapper))
$(eval $(call register_private_lib,SUITESPARSE,libamd libcamd libccolamd libcholmod libcolamd libumfpack libspqr libsuitesparseconfig))
endif
$(eval $(call register_private_lib,PCRE,libpcre2-8))
$(eval $(call register_private_lib,DSFMT,libdSFMT))
$(eval $(call register_private_lib,GMP,libgmp))
$(eval $(call register_private_lib,MPFR,libmpfr))
$(eval $(call register_private_lib,LIBSSH2,libssh2))
$(eval $(call register_private_lib,MBEDTLS,libmbedtls libmbedcrypto libmbedx509))
$(eval $(call register_private_lib,CURL,libcurl))
$(eval $(call register_private_lib,LIBGIT2,libgit2))
$(eval $(call register_private_lib,ZLIB,libz))
ifeq ($(USE_LLVM_SHLIB),1)
$(eval $(call register_private_lib,LLVM,libLLVM libLLVM-9jl))
endif

JL_PRIVATE_LIBS-$(USE_SYSTEM_BLAS) += $(LIBBLASNAME)
$(eval $(call register_private_lib,OPENLIBM,libopenlibm))
# Naming mismatches are annoying
USE_SYSTEM_OPENBLAS := $(USE_SYSTEM_BLAS)
$(eval $(call register_private_lib,OPENBLAS,$(LIBBLASNAME)))
ifneq ($(LIBLAPACKNAME),$(LIBBLASNAME))
JL_PRIVATE_LIBS-$(USE_SYSTEM_LAPACK) += $(LIBLAPACKNAME)
$(eval $(call register_private_lib,LAPACK,$(LIBLAPACKNAME)))
endif

ifeq ($(OS),Darwin)
Expand All @@ -195,50 +201,6 @@ endif
endif
endif

# On FreeBSD, /lib/libgcc_s.so.1 is incompatible with Fortran; to use Fortran on FreeBSD,
# we need to link to the libgcc_s that ships with the same GCC version used by libgfortran.
# To work around this, we copy the GCC libraries we need, namely libgfortran, libgcc_s,
# and libquadmath, into our build library directory, $(build_libdir). We also add them to
# JL_PRIVATE_LIBS-0 so that they know where they need to live at install time.
ifeq ($(OS),FreeBSD)
define std_so
julia-deps: | $$(build_libdir)/$(1).so
$$(build_libdir)/$(1).so: | $$(build_libdir)
$$(INSTALL_M) $$(GCCPATH)/$(1).so* $$(build_libdir)
JL_PRIVATE_LIBS-0 += $(1)
endef

$(eval $(call std_so,libgfortran))
$(eval $(call std_so,libgcc_s))
$(eval $(call std_so,libquadmath))
endif # FreeBSD

ifeq ($(OS),WINNT)
# find the standard .dll folders
ifeq ($(XC_HOST),)
STD_LIB_PATH ?= $(PATH)
else
STD_LIB_PATH := $(shell LANG=C $(CC) -print-search-dirs | grep '^programs: =' | sed -e "s/^programs: =//")
STD_LIB_PATH += :$(shell LANG=C $(CC) -print-search-dirs | grep '^libraries: =' | sed -e "s/^libraries: =//")
ifneq (,$(findstring CYGWIN,$(BUILD_OS))) # the cygwin-mingw32 compiler lies about it search directory paths
STD_LIB_PATH := $(shell echo '$(STD_LIB_PATH)' | sed -e "s!/lib/!/bin/!g")
endif
endif

pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(2)))))

define std_dll
julia-deps-libs: | $$(build_bindir)/lib$(1).dll $$(build_depsbindir)/lib$(1).dll
$$(build_bindir)/lib$(1).dll: | $$(build_bindir)
cp $$(or $$(call pathsearch,lib$(1).dll,$$(STD_LIB_PATH)),$$(error can't find lib$1.dll)) $$(build_bindir)
$$(build_depsbindir)/lib$(1).dll: | $$(build_depsbindir)
cp $$(or $$(call pathsearch,lib$(1).dll,$$(STD_LIB_PATH)),$$(error can't find lib$1.dll)) $$(build_depsbindir)
JL_TARGETS += $(1)
endef
julia-deps: julia-deps-libs
endif


define stringreplace
$(build_depsbindir)/stringreplace $$(strings -t x - $1 | grep '$2' | awk '{print $$1;}') '$3' 255 "$(call cygpath_w,$1)"
endef
Expand Down Expand Up @@ -408,7 +370,7 @@ ifeq ($(OS),FreeBSD)
# don't set libgfortran's RPATH, it won't be able to find its friends on systems
# that don't have the exact GCC port installed used for the build.
for lib in $(DESTDIR)$(private_libdir)/libgfortran*$(SHLIB_EXT)*; do \
$(PATCHELF) --set-rpath '$$ORIGIN' $$lib; \
[ ! -f $$lib ] || $(PATCHELF) --set-rpath '$$ORIGIN' $$lib; \
done
endif

Expand Down
13 changes: 10 additions & 3 deletions deps/csl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ define fortran_src
$(CSL_FORTRAN_LIBDIR)/$(1)*.$(SHLIB_EXT)*
endef

CXX_LIB_PATHS := $(foreach f,$(wildcard $(foreach lib,$(CXX_LIBS),$(call cxx_src,$(lib)))),$(realpath $(f)))
FORTRAN_LIB_PATHS := $(foreach f,$(wildcard $(foreach lib,$(FORTRAN_LIBS),$(call fortran_src,$(lib)))),$(realpath $(f)))

UNINSTALL_compilersupportlibraries = delete-uninstaller "$(wildcard $(foreach lib,$(CXX_LIBS) $(FORTRAN_LIBS),$(build_shlibdir)/$(lib)*.$(SHLIB_EXT)*))"
$(build_prefix)/manifest/compilersupportlibraries: | $(build_shlibdir) $(build_prefix)/manifest
cp -va -l $(CXX_LIB_PATHS) $(build_shlibdir)/
cp -va $(FORTRAN_LIB_PATHS) $(build_shlibdir)/
echo '$(UNINSTALL_compilersupportlibraries)' > "$@"

get-compilersupportlibraries:
extract-compilersupportlibraries:
configure-compilersupportlibraries:
compile-compilersupportlibraries:
install-compilersupportlibraries: | $(build_libdir)
cp -va $(foreach lib,$(CXX_LIBS),$(call cxx_src $(lib))) $(build_libdir)/
cp -va $(foreach lib,$(FORTRAN_LIBS),$(call fortran_src $(lib))) $(build_libdir)/
install-compilersupportlibraries: $(build_prefix)/manifest/compilersupportlibraries

$(eval $(call jll-generate,CompilerSupportLibraries_jll, \
libgcc_s=\"libgcc_s\" \
Expand Down
3 changes: 1 addition & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ ifeq ($(OS), Darwin)
CLANG_LDFLAGS += -Wl,-undefined,dynamic_lookup
endif

CSLLINK = $(call rpath_rel_link,$(CSL_SHLIBDIR))
COMMON_LIBS := -L$(build_shlibdir) -L$(build_libdir) $(LIBUV) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LLVMLINK) $(OSLIBS) $(LIBUNWIND) $(CSLLINK)
COMMON_LIBS := -L$(build_shlibdir) -L$(build_libdir) $(LIBUV) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(CSL_LINK) $(LLVMLINK) $(OSLIBS) $(LIBUNWIND)
DEBUG_LIBS := $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a $(COMMON_LIBS)
RELEASE_LIBS := $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a $(COMMON_LIBS)

Expand Down
2 changes: 1 addition & 1 deletion ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ OBJS := $(SRCS:%=$(BUILDDIR)/%.o)
DOBJS := $(SRCS:%=$(BUILDDIR)/%.dbg.obj)
DEBUGFLAGS += $(FLAGS)
SHIPFLAGS += $(FLAGS)
JLDFLAGS += $(LDFLAGS) $(NO_WHOLE_ARCHIVE) $(OSLIBS) $(RPATH)
JLDFLAGS += $(LDFLAGS) $(NO_WHOLE_ARCHIVE) $(OSLIBS) $(RPATH) $(CSL_LINK)

ifeq ($(USE_SYSTEM_LIBM),0)
ifneq ($(UNTRUSTED_SYSTEM_LIBM),0)
Expand Down

0 comments on commit d8c4cfc

Please sign in to comment.