Skip to content

Commit

Permalink
Remove OpenLibm and leverage native Julia implementations
Browse files Browse the repository at this point in the history
Link to the system libm
  • Loading branch information
ViralBShah committed Jul 29, 2023
1 parent 210c5b5 commit 7416f04
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 142 deletions.
39 changes: 5 additions & 34 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ USE_SYSTEM_LLVM:=0
USE_SYSTEM_LIBUNWIND:=0
DISABLE_LIBUNWIND:=0
USE_SYSTEM_PCRE:=0
USE_SYSTEM_LIBM:=0
USE_SYSTEM_OPENLIBM:=0
UNTRUSTED_SYSTEM_LIBM:=0
USE_SYSTEM_DSFMT:=0
USE_SYSTEM_LIBBLASTRAMPOLINE:=0
USE_SYSTEM_BLAS:=0
Expand Down Expand Up @@ -1145,14 +1142,6 @@ LIBLAPACKNAME := liblapack
endif
endif

ifeq ($(USE_SYSTEM_LIBM), 1)
LIBM := -lm
LIBMNAME := libm
else
LIBM := -lopenlibm
LIBMNAME := libopenlibm
endif

ifeq ($(USE_SYSTEM_LIBUV), 1)
LIBUV := $(LOCALBASE)/lib/libuv-julia.a
LIBUV_INC := $(LOCALBASE)/include
Expand Down Expand Up @@ -1236,7 +1225,7 @@ CSL_NEXT_GLIBCXX_VERSION=GLIBCXX_3\.4\.31|GLIBCXX_3\.5\.|GLIBCXX_4\.
# Note: we explicitly _do not_ define `CSL` here, since it requires some more
# advanced techniques to decide whether it should be installed from a BB source
# or not. See `deps/csl.mk` for more detail.
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD LIBTRACYCLIENT
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD LIBTRACYCLIENT
define SET_BB_DEFAULT
# First, check to see if BB is disabled on a global setting
ifeq ($$(USE_BINARYBUILDER),0)
Expand Down Expand Up @@ -1366,7 +1355,6 @@ ifeq ($(ARCH),i686)
JLDFLAGS += -Wl,--large-address-aware
endif
JCPPFLAGS += -D_WIN32_WINNT=0x0502
UNTRUSTED_SYSTEM_LIBM := 1
# Use hard links for files on windows, rather than soft links
# https://stackoverflow.com/questions/3648819/how-to-make-a-symbolic-link-with-cygwin-in-windows-7
# Usage: $(WIN_MAKE_HARD_LINK) <source> <target>
Expand Down Expand Up @@ -1441,12 +1429,6 @@ USE_BINARYBUILDER_OPENBLAS := 0
USE_BINARYBUILDER_LIBSUITESPARSE := 0
endif

ifeq ($(USE_SYSTEM_LIBM),1)
# If we're using system libm, disable BB OpenLibm
USE_BINARYBUILDER_OPENLIBM := 0
endif


# Note: we're passing *FLAGS here computed based on your system compiler to
# clang. If that causes you problems, you might want to build and/or run
# specific clang-sa-* files with clang explicitly selected:
Expand Down Expand Up @@ -1602,20 +1584,13 @@ endif
LIBSTDCXX_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/$(LIBSTDCXX_NAME))
endif


# USE_SYSTEM_LIBM and USE_SYSTEM_OPENLIBM causes it to get symlinked into build_private_shlibdir
ifeq ($(USE_SYSTEM_LIBM),1)
LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_private_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))
else ifeq ($(USE_SYSTEM_OPENLIBM),1)
LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_private_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))
else
LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))
endif
LIBM_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))
# Symlink system libm
LIBMNAME := libm
#LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))
#LIBM_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/$(LIBMNAME).$(SHLIB_EXT))

# We list:
# * libgcc_s, because FreeBSD needs to load ours, not the system one.
# * libopenlibm, because Windows has an untrustworthy libm, and we want to use ours more than theirs
# * libstdc++, because while performing `libstdc++` probing we need to
# know the path to the bundled `libstdc++` library.
# * libjulia-internal, which must always come second-to-last.
Expand All @@ -1637,30 +1612,26 @@ endef

LOADER_BUILD_DEP_LIBS = $(call build_deplibs, \
$(LIBGCC_BUILD_DEPLIB) \
$(LIBM_BUILD_DEPLIB) \
@$(LIBSTDCXX_BUILD_DEPLIB) \
@$(LIBJULIAINTERNAL_BUILD_DEPLIB) \
@$(LIBJULIACODEGEN_BUILD_DEPLIB) \
)

LOADER_DEBUG_BUILD_DEP_LIBS = $(call build_deplibs, \
$(LIBGCC_BUILD_DEPLIB) \
$(LIBM_BUILD_DEPLIB) \
@$(LIBSTDCXX_BUILD_DEPLIB) \
@$(LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB) \
@$(LIBJULIACODEGEN_DEBUG_BUILD_DEPLIB) \
)

LOADER_INSTALL_DEP_LIBS = $(call build_deplibs, \
$(LIBGCC_INSTALL_DEPLIB) \
$(LIBM_INSTALL_DEPLIB) \
@$(LIBSTDCXX_INSTALL_DEPLIB) \
@$(LIBJULIAINTERNAL_INSTALL_DEPLIB) \
@$(LIBJULIACODEGEN_INSTALL_DEPLIB) \
)
LOADER_DEBUG_INSTALL_DEP_LIBS = $(call build_deplibs, \
$(LIBGCC_INSTALL_DEPLIB) \
$(LIBM_INSTALL_DEPLIB) \
@$(LIBSTDCXX_INSTALL_DEPLIB) \
@$(LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB) \
@$(LIBJULIACODEGEN_DEBUG_INSTALL_DEPLIB) \
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ JL_PRIVATE_LIBS-$(USE_SYSTEM_LLVM) += libLLVM $(LLVM_SHARED_LIB_NAME)
endif
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBUNWIND) += libunwind

ifeq ($(USE_SYSTEM_LIBM),0)
JL_PRIVATE_LIBS-$(USE_SYSTEM_OPENLIBM) += libopenlibm
endif

JL_PRIVATE_LIBS-$(USE_SYSTEM_BLAS) += $(LIBBLASNAME)
ifneq ($(LIBLAPACKNAME),$(LIBBLASNAME))
JL_PRIVATE_LIBS-$(USE_SYSTEM_LAPACK) += $(LIBLAPACKNAME)
Expand Down Expand Up @@ -291,13 +287,13 @@ endif

# We have a single exception; we want 7z.dll to live in private_libexecdir, not bindir, so that 7z.exe can find it.
-mv $(DESTDIR)$(bindir)/7z.dll $(DESTDIR)$(private_libexecdir)/
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
-$(INSTALL_M) $(build_libdir)/libssp.dll.a $(DESTDIR)$(libdir)/
# The rest are compiler dependencies, as an example memcpy is exported by msvcrt
# These are files from mingw32 and required for creating shared libraries like our caches.
-$(INSTALL_M) $(build_libdir)/libgcc_s.a $(DESTDIR)$(libdir)/
-$(INSTALL_M) $(build_libdir)/libgcc.a $(DESTDIR)$(libdir)/
-$(INSTALL_M) $(build_libdir)/libmsvcrt.a $(DESTDIR)$(libdir)/

else

# Copy over .dSYM directories directly for Darwin
Expand Down
9 changes: 1 addition & 8 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ ifeq ($(XC_HOST),)
else
@echo "const MACHINE = \"$(XC_HOST)\"" >> $@
endif
@echo "const libm_name = \"$(LIBMNAME)\"" >> $@
ifeq ($(USE_BLAS64), 1)
@echo "const USE_BLAS64 = true" >> $@
else
Expand Down Expand Up @@ -218,13 +217,7 @@ $(build_bindir)/lld$(EXE):
ln -svf "$(LLD_PATH)" "$@"

# the following excludes: libuv.a, libutf8proc.a

ifneq ($(USE_SYSTEM_LIBM),0)
$(eval $(call symlink_system_library,LIBM,$(LIBMNAME)))
else ifneq ($(USE_SYSTEM_OPENLIBM),0)
$(eval $(call symlink_system_library,OPENLIBM,$(LIBMNAME)))
endif

#$(eval $(call symlink_system_library,LIBM,$(LIBMNAME)))
# On macOS, libgcc_s has soversion 1.1 always on aarch64 and only for GCC 12+
# (-> libgfortran 5) on x86_64
ifeq ($(OS),Darwin)
Expand Down
1 change: 1 addition & 0 deletions base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ sub_fast(x::T, y::T) where {T<:FloatTypes} = sub_float_fast(x, y)
mul_fast(x::T, y::T) where {T<:FloatTypes} = mul_float_fast(x, y)
div_fast(x::T, y::T) where {T<:FloatTypes} = div_float_fast(x, y)


add_fast(x::T, y::T, zs::T...) where {T<:FloatTypes} =
add_fast(add_fast(x, y), zs...)
mul_fast(x::T, y::T, zs::T...) where {T<:FloatTypes} =
Expand Down
2 changes: 1 addition & 1 deletion base/linking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function link_image_cmd(path, out)
SHLIBDIR = "-L$(shlibdir())"
LIBS = is_debug() ? ("-ljulia-debug", "-ljulia-internal-debug") : ("-ljulia", "-ljulia-internal")
@static if Sys.iswindows()
LIBS = (LIBS..., "-lopenlibm", "-lssp", "-lgcc_s", "-lgcc", "-lmsvcrt")
LIBS = (LIBS..., "-lssp", "-lgcc_s", "-lgcc", "-lucrt")
end

V = VERBOSE[] ? "--verbose" : ""
Expand Down
3 changes: 0 additions & 3 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ log(b::Number, x::Number) = log(promote(b,x)...)

# type specific math functions

const libm = Base.libm_name

# functions with no domain error
"""
sinh(x)
Expand Down Expand Up @@ -1164,7 +1162,6 @@ function rem(x::T, p::T, ::RoundingMode{:Nearest}) where T<:IEEEFloat
return flipsign(x, oldx)
end


"""
modf(x)
Expand Down
2 changes: 1 addition & 1 deletion contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function ldlibs(doframework)
(Sys.isapple() ? string() : "-Wl,-rpath,$(shell_escape(private_libDir())) ") *
"-l$libname"
else
return "-l$libname -lopenlibm"
return "-l$libname -lm"
end
end

Expand Down
2 changes: 1 addition & 1 deletion contrib/refresh_checksums.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CLANG_TRIPLETS=$(filter %-darwin %-freebsd,$(TRIPLETS))
NON_CLANG_TRIPLETS=$(filter-out %-darwin %-freebsd,$(TRIPLETS))

# These are the projects currently using BinaryBuilder; both GCC-expanded and non-GCC-expanded:
BB_PROJECTS=mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind llvmunwind dsfmt objconv p7zip zlib libsuitesparse openlibm blastrampoline libtracyclient
BB_PROJECTS=mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind llvmunwind dsfmt objconv p7zip zlib libsuitesparse blastrampoline libtracyclient
BB_GCC_EXPANDED_PROJECTS=openblas csl
BB_CXX_EXPANDED_PROJECTS=gmp llvm clang llvm-tools lld
# These are non-BB source-only deps
Expand Down
13 changes: 3 additions & 10 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ BUILDDIR := $(BUILDDIR)$(MAYBE_HOST)
# if you are adding a new target, it can help to copy an similar, existing target
#
# autoconf configure-driven scripts: pcre unwind gmp mpfr patchelf libuv curl
# custom Makefile rules: openlibm dsfmt libsuitesparse lapack blastrampoline openblas utf8proc objconv libwhich
# custom Makefile rules: dsfmt libsuitesparse lapack blastrampoline openblas utf8proc objconv libwhich
# CMake libs: llvm llvmunwind libgit2 libssh2 mbedtls libtracyclient
#
# downloadable via git: llvm-svn, libuv, libopenlibm, utf8proc, libgit2, libssh2, libtracyclient
# downloadable via git: llvm-svn, libuv, utf8proc, libgit2, libssh2, libtracyclient
#
# to debug 'define' rules, replace eval at the usage site with info or error

Expand Down Expand Up @@ -82,12 +82,6 @@ PATCHELF_BIN := $(CUSTOM_LD_LIBRARY_PATH) $(PATCHELF)

## USE_SYSTEM_LIBS options

ifeq ($(USE_SYSTEM_OPENLIBM), 0)
ifeq ($(USE_SYSTEM_LIBM), 0)
DEP_LIBS += openlibm
endif
endif

ifeq ($(USE_SYSTEM_DSFMT), 0)
DEP_LIBS += dsfmt
endif
Expand Down Expand Up @@ -190,7 +184,7 @@ DEP_LIBS_STAGED := $(DEP_LIBS)

# list all targets
DEP_LIBS_STAGED_ALL := llvm llvm-tools clang llvmunwind unwind libuv pcre \
openlibm dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
objconv mbedtls libssh2 nghttp2 curl libgit2 libwhich zlib p7zip csl \
sanitizers libsuitesparse lld libtracyclient ittapi JuliaSyntax
DEP_LIBS_ALL := $(DEP_LIBS_STAGED_ALL)
Expand Down Expand Up @@ -232,7 +226,6 @@ include $(SRCDIR)/ittapi.mk
include $(SRCDIR)/llvm.mk
include $(SRCDIR)/libuv.mk
include $(SRCDIR)/pcre.mk
include $(SRCDIR)/openlibm.mk
include $(SRCDIR)/dsfmt.mk
include $(SRCDIR)/objconv.mk
include $(SRCDIR)/blastrampoline.mk
Expand Down
34 changes: 0 additions & 34 deletions deps/checksums/openlibm

This file was deleted.

34 changes: 0 additions & 34 deletions deps/openlibm.mk

This file was deleted.

7 changes: 0 additions & 7 deletions deps/openlibm.version

This file was deleted.

3 changes: 1 addition & 2 deletions pkgimage.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ print-depot-path:
@$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --startup-file=no -e '@show Base.DEPOT_PATH')

STDLIBS := ArgTools Artifacts Base64 CRC32c FileWatching Libdl NetworkOptions SHA Serialization \
GMP_jll LLVMLibUnwind_jll LibUV_jll LibUnwind_jll MbedTLS_jll OpenLibm_jll PCRE2_jll \
GMP_jll LLVMLibUnwind_jll LibUV_jll LibUnwind_jll MbedTLS_jll PCRE2_jll \
Zlib_jll dSFMT_jll libLLVM_jll libblastrampoline_jll OpenBLAS_jll Printf Random Tar \
LibSSH2_jll MPFR_jll LinearAlgebra Dates Distributed Future LibGit2 Profile SparseArrays UUIDs \
SharedArrays TOML Test LibCURL Downloads Pkg Dates LazyArtifacts Sockets Unicode Markdown \
Expand Down Expand Up @@ -85,7 +85,6 @@ $(eval $(call pkgimg_builder,LibUV_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,LibUnwind_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,MbedTLS_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,nghttp2_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,OpenLibm_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,PCRE2_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,Zlib_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,dSFMT_jll,Artifacts Libdl))
Expand Down
1 change: 0 additions & 1 deletion stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ function versioninfo(io::IO=stdout; verbose::Bool=false)
println(io)
end
println(io, " WORD_SIZE: ", Sys.WORD_SIZE)
println(io, " LIBM: ",Base.libm_name)
println(io, " LLVM: libLLVM-",Base.libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")")
println(io, " Threads: ", Threads.maxthreadid(), " on ", Sys.CPU_THREADS, " virtual cores")

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DIRS := $(build_datarootdir)/julia/stdlib/$(VERSDIR) $(build_prefix)/manifest/$(
$(foreach dir,$(DIRS),$(eval $(call dir_target,$(dir))))

JLLS = DSFMT GMP CURL LIBGIT2 LLVM LIBSSH2 LIBUV MBEDTLS MPFR NGHTTP2 \
BLASTRAMPOLINE OPENBLAS OPENLIBM P7ZIP PCRE LIBSUITESPARSE ZLIB \
BLASTRAMPOLINE OPENBLAS P7ZIP PCRE LIBSUITESPARSE ZLIB \
LLVMUNWIND CSL UNWIND LLD

# Initialize this with JLLs that aren't in "deps/$(LibName).version"
Expand Down

0 comments on commit 7416f04

Please sign in to comment.