-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Basic support for builtins from compiler-rt #18734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ include $(SRCDIR)/tools/git-external.mk | |
# prevent installing libs into usr/lib64 on opensuse | ||
unexport CONFIG_SITE | ||
|
||
DEP_LIBS := | ||
DEP_LIBS := compiler-rt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is more complicated than that. As far as I can tell we will need to unconditionally build with compiler-rt (except for llvm-free builds). |
||
|
||
ifeq ($(USE_GPL_LIBS), 1) | ||
DEP_LIBS += suitesparse-wrapper | ||
|
@@ -175,9 +175,10 @@ uninstall: $(addprefix uninstall-, $(DEP_LIBS_STAGED)) | |
cleanall: $(addprefix clean-, $(DEP_LIBS)) | ||
distcleanall: $(addprefix distclean-, $(DEP_LIBS)) | ||
rm -rf $(build_prefix) | ||
getall: get-llvm get-libuv get-pcre get-openlibm get-openspecfun get-dsfmt get-openblas get-lapack get-fftw get-suitesparse get-arpack get-unwind get-osxunwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-curl get-libgit2 | ||
getall: get-llvm get-compiler-rt get-libuv get-pcre get-openlibm get-openspecfun get-dsfmt get-openblas get-lapack get-fftw get-suitesparse get-arpack get-unwind get-osxunwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-curl get-libgit2 | ||
|
||
include $(SRCDIR)/llvm.mk | ||
include $(SRCDIR)/compiler-rt.mk | ||
include $(SRCDIR)/libuv.mk | ||
include $(SRCDIR)/pcre.mk | ||
include $(SRCDIR)/openlibm.mk | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
## | ||
# In order to support fallbacks within llvm we need to support | ||
# compiler-rt. This means linking sys.so against it and resolving | ||
# symbols during JIT compilation (see jitlayers.cpp). For the latter part we need to create | ||
# a .so that we can load, but compiler-rt only comes in a .a. | ||
# | ||
# There are several configurations to take into account. | ||
# 1. STANDALONE_COMPILER_RT == 1 | ||
# Download and install compiler_rt independently of llvm/clang. | ||
# We still use the the LLVM_VER to pick the right compiler-rt. | ||
# 2. STANDALONE_COMPILER_RT == 0 | ||
# On LLVM >= 3.8 we can build compiler-rt along side LLVM. | ||
# 3. USE_SYSTEM_LLVM == 1 && STANDALONE_COMPILER_RT == 0 | ||
# Fallback definition. | ||
# libclang_rt.builtins is distributed with clang and so | ||
# we assume that USE_SYSTEM_LLVM == 1 means that clang is also | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure this is a safe assumption to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this adds an implicit dependency on clang... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least for Fedora RPMs, I need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Installing clang will be enough or you can set |
||
# installed. | ||
# This is intended as a last ressort and if you use USE_SYSTEM_LLVM | ||
# consider setting STANDALONE_COMPILER_RT:=1 | ||
# | ||
# Since we need the shared objectfile for JIT, there is no USE_SYSTEM_COMPILER_RT | ||
## | ||
COMPILER_RT_BUILDDIR := $(BUILDDIR)/compiler-rt-$(LLVM_VER) | ||
COMPILER_RT_SRCDIR := $(SRCDIR)/srccache/compiler-rt-$(LLVM_VER) | ||
COMPILER_RT_LIBFILE := libcompiler-rt.$(SHLIB_EXT) | ||
COMPILER_RT_STATICLIBFILE := libcompiler-rt.$(STATICLIB_EXT) | ||
|
||
## | ||
# The naming of the static file for compiler-rt is slightly weird | ||
# and we have to figure out what the proper name is on the current | ||
# platform. | ||
# | ||
# TODO: | ||
# - Currently this build-mode is not supported on Windows. | ||
## | ||
CRT_OS := $(call lower,$(OS)) | ||
CRT_LDFLAGS := | ||
ifneq (,$(filter $(ARCH), powerpc64le ppc64le)) | ||
CRT_ARCH := ppc | ||
else ifneq (,$(filter $(ARCH), armv7l armv6l)) | ||
CRT_ARCH := armhf | ||
CRT_LDFLAGS += -Wl,--allow-multiple-definition | ||
else | ||
CRT_ARCH := $(call patsubst,i%86,i386,$(ARCH)) | ||
CRT_LDFLAGS := | ||
endif | ||
CRT_STATIC_NAME := clang_rt.builtins-$(CRT_ARCH) | ||
|
||
ifeq ($(STANDALONE_COMPILER_RT),1) | ||
COMPILER_RT_TAR := $(SRCDIR)/srccache/compiler-rt-$(LLVM_TAR_EXT) | ||
else | ||
COMPILER_RT_TAR := | ||
ifeq ($(USE_SYSTEM_LLVM), 1) | ||
CRT_VER:=$(word 1,$(subst svn-, ,$(shell llvm-config --version))) | ||
CRT_DIR := $(shell llvm-config --libdir)/clang/$(CRT_VER)/lib/$(CRT_OS) | ||
else ifeq ($(BUILD_LLVM_COMPILER_RT), 1) | ||
CRT_DIR := $(LLVM_BUILDDIR_withtype)/lib/clang/$(LLVM_VER)/lib/$(CRT_OS) | ||
$(CRT_DIR)/lib$(CRT_STATIC_NAME).$(STATICLIB_EXT): | $(LLVM_BUILDDIR_withtype)/build-compiled | ||
else | ||
$(error Compiler-rt is not available, please set STANDALONE_COMPILER_RT:=1) | ||
endif | ||
endif | ||
|
||
$(COMPILER_RT_SRCDIR)/source-extracted: | $(COMPILER_RT_TAR) | ||
mkdir -p $(COMPILER_RT_SRCDIR) | ||
ifneq ($(COMPILER_RT_TAR),) | ||
$(JLCHECKSUM) $(COMPILER_RT_TAR) | ||
$(TAR) -C $(COMPILER_RT_SRCDIR) --strip-components 1 -xf $(COMPILER_RT_TAR) | ||
endif | ||
echo 1 > $@ | ||
|
||
$(COMPILER_RT_BUILDDIR): | ||
mkdir -p $@ | ||
$(COMPILER_RT_BUILDDIR)/$(CRT_ARCH): | ||
mkdir -p $@ | ||
|
||
ifeq ($(STANDALONE_COMPILER_RT),1) | ||
$(COMPILER_RT_BUILDDIR)/Makefile: compiler-rt_standalone.mk | $(COMPILER_RT_BUILDDIR) | ||
cp $< $@ | ||
$(COMPILER_RT_BUILDDIR)/build-configured: $(COMPILER_RT_BUILDDIR)/Makefile | $(COMPILER_RT_BUILDDIR)/$(CRT_ARCH) | ||
echo 1 > $@ | ||
|
||
$(COMPILER_RT_BUILDDIR)/build-compiled: | $(COMPILER_RT_SRCDIR)/source-extracted $(COMPILER_RT_BUILDDIR)/build-configured | ||
$(MAKE) -C $(COMPILER_RT_BUILDDIR) \ | ||
CC='$(CC)' \ | ||
AR='$(AR)' \ | ||
LIBFILE=$(COMPILER_RT_LIBFILE) \ | ||
SLIBFILE=$(COMPILER_RT_STATICLIBFILE) \ | ||
CRT_SRCDIR=$(COMPILER_RT_SRCDIR) \ | ||
OS=$(CRT_OS) \ | ||
ARCH=$(CRT_ARCH) \ | ||
USE_CLANG=$(USE_CLANG) \ | ||
fPIC=$(fPIC) all | ||
$(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_LIBFILE): | $(COMPILER_RT_BUILDDIR)/build-compiled | ||
$(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_STATICLIBFILE): | $(COMPILER_RT_BUILDDIR)/build-compiled | ||
else | ||
$(COMPILER_RT_BUILDDIR)/build-configured: $(COMPILER_RT_BUILDDIR) | ||
echo 1 > $@ | ||
# Use compiler-rt from the clang installation | ||
$(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_LIBFILE): $(CRT_DIR)/lib$(CRT_STATIC_NAME).$(STATICLIB_EXT) | $(COMPILER_RT_BUILDDIR)/build-configured | ||
$(CC) $(LDFLAGS) -nostdlib $(CRT_LDFLAGS) -shared $(fPIC) -o $@ $(WHOLE_ARCHIVE) -L$(dir $<) -l$(CRT_STATIC_NAME) $(WHOLE_NOARCHIVE) | ||
$(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_STATICLIBFILE): $(CRT_DIR)/lib$(CRT_STATIC_NAME).$(STATICLIB_EXT) | $(COMPILER_RT_BUILDDIR)/build-configured | ||
cp $^ $@ | ||
endif | ||
|
||
ifneq ($(COMPILER_RT_TAR),) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this rule makes sense overall if |
||
ifeq ($(LLVM_COMPILER_RT_TAR),) | ||
$(COMPILER_RT_TAR): | $(SRCDIR)/srccache | ||
$(JLDOWNLOAD) $@ $(LLVM_SRC_URL)/$(notdir $@) | ||
endif | ||
endif | ||
|
||
get-compiler-rt: $(COMPILER_RT_TAR) | ||
ifeq ($(STANDALONE_COMPILER_RT), 0) | ||
extract-compiler-rt: #NONE | ||
else | ||
extract-compiler-rt: $(COMPILER_RT_SRCDIR)/source-extracted | ||
endif | ||
|
||
$(build_shlibdir)/$(COMPILER_RT_LIBFILE): $(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_LIBFILE) | ||
mkdir -p $(dir $@) | ||
cp $< $@ | ||
@$(INSTALL_NAME_CMD)$(notdir $@) $@ | ||
@$(DSYMUTIL) $@ | ||
|
||
$(build_private_libdir)/$(COMPILER_RT_STATICLIBFILE): $(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_STATICLIBFILE) | ||
mkdir -p $(dir $@) | ||
cp $< $@ | ||
|
||
$(build_prefix)/manifest/compiler-rt: | $(build_prefix)/manifest | ||
echo "compiler-rt-$(LLVM_VER)" > $@ | ||
|
||
check-compiler-rt: #NONE | ||
fastcheck-compiler-rt: #NONE | ||
configure-compiler-rt: $(COMPILER_RT_BUILDDIR)/build-configured | ||
clean-compiler-rt: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think clean should depend on uninstall, most of the autogenerated ones do IIRC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See L145. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makefiles are awful |
||
rm -rf $(COMPILER_RT_BUILDDIR) | ||
distclean-compiler-rt: clean-compiler-rt | ||
rm -f $(COMPILER_RT_TAR) | ||
rm -rf $(COMPILER_RT_SRCDIR) | ||
uninstall-compiler-rt: | ||
rm -f $(build_prefix)/manifest/compiler-rt | ||
rm -f $(build_shlibdir)/$(COMPILER_RT_LIBFILE) | ||
rm -f $(build_private_libdir)/$(COMPILER_RT_STATICLIBFILE) | ||
distclean-compiler-rt clean-compiler-rt: | uninstall-compiler-rt | ||
|
||
compile-compiler-rt: $(COMPILER_RT_BUILDDIR)/$(COMPILER_RT_LIBFILE) | ||
install-compiler-rt: $(build_shlibdir)/$(COMPILER_RT_LIBFILE) $(build_private_libdir)/$(COMPILER_RT_STATICLIBFILE) $(build_prefix)/manifest/compiler-rt | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
## | ||
# This Makefile will be executed in $(BUILDDIR)/compiler-rt-$(LLVM_VER) | ||
# Expected variables from the parent | ||
# CRT_SRCDIR | ||
# LIBFILE | ||
# SLIBFILE | ||
# OS (CRT_OS not JL_OS) | ||
# ARCH (CRT_ARCH not JL_ARCH) | ||
# USE_CLANG | ||
# fPIC | ||
## | ||
|
||
# The standalone compiler-rt build is inspired by | ||
# https://github.com/ReservedField/arm-compiler-rt | ||
SRCDIR := $(CRT_SRCDIR)/lib/builtins | ||
|
||
ifeq ($(ARCH), armhf) | ||
ARCH_SRCDIR := $(SRCDIR)/arm | ||
else ifeq ($(ARCH), aarch64) | ||
ARCH_SRCDIR := $(SRCDIR)/arm64 | ||
else | ||
ARCH_SRCDIR := $(SRCDIR)/$(ARCH) | ||
endif | ||
|
||
INCLUDES := -I$(SRCDIR) -I$(ARCH_SRCDIR) | ||
# TODO(vchuravy) discover architecture flags | ||
CRT_CFLAGS := $(CPPFLAGS) $(CFLAGS) -O2 -std=c11 \ | ||
$(fPIC) $(INCLUDES) \ | ||
-fno-builtin -ffreestanding | ||
ifeq ($(USE_CLANG),1) | ||
CRT_CFLAGS += -Wno-unknown-attributes -Wno-macro-redefined | ||
endif | ||
|
||
## | ||
# Blacklist a few files we don't want to deal with | ||
## | ||
MAKEFLAGS := --no-builtin-rules | ||
BLACKLIST := atomic.o atomic_flag_clear.o atomic_flag_clear_explicit.o \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tkelman the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit that and we could try throwing it at the buildbots again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like that fixes the windows build (need to run tests locally, will see) but not whatever's wrong with the 32 bit linux buildbot |
||
atomic_flag_test_and_set.o atomic_flag_test_and_set_explicit.o \ | ||
atomic_signal_fence.o atomic_thread_fence.o emutls.o | ||
|
||
CRT_LDFLAGS := | ||
ifeq ($(ARCH),ppc) | ||
BLACKLIST += saveFP.o restFP.o | ||
else ifeq ($(ARCH), armhf) | ||
CRT_LDFLAGS += -Wl,--allow-multiple-definition | ||
endif | ||
|
||
|
||
ifeq ($(OS),darwin) | ||
# Which blacklist should we choose | ||
BLACKLIST += $(shell cat $(SRCDIR)/Darwin-excludes/osx.txt) | ||
else ifeq ($(OS), winnt) | ||
CRT_CFLAGS += -D_WIN32 | ||
endif | ||
|
||
CFILES := $(wildcard $(SRCDIR)/*.c) | ||
GENERAL_OBJS1 := $(filter-out $(BLACKLIST), $(notdir $(CFILES:.c=.o))) | ||
|
||
ARCH_CFILES := $(wildcard $(ARCH_SRCDIR)/*.c) | ||
ARCH_SFILES := $(wildcard $(ARCH_SRCDIR)/*.S) | ||
ARCH_OBJS := $(filter-out $(BLACKLIST), $(notdir $(join $(ARCH_CFILES:.c=.o),$(ARCH_SFILES:.S=.o)))) | ||
|
||
GENERAL_OBJS := $(filter-out $(ARCH_OBJS), $(GENERAL_OBJS1)) | ||
|
||
OBJS := $(GENERAL_OBJS) $(ARCH_OBJS) | ||
|
||
%.o: $(SRCDIR)/%.c | ||
$(CC) $(CRT_CFLAGS) -c $< -o $@ | ||
|
||
%.o: $(SRCDIR)/%.S | ||
$(CC) $(CRT_CFLAGS) -c $< -o $@ | ||
|
||
%.o: $(ARCH_SRCDIR)/%.c | ||
$(CC) $(CRT_CFLAGS) -c $< -o $@ | ||
|
||
%.o: $(ARCH_SRCDIR)/%.S | ||
$(CC) $(CRT_CFLAGS) -c $< -o $@ | ||
|
||
$(LIBFILE): $(OBJS) | ||
$(CC) $(CRT_LDFLAGS) $(CRT_CFLAGS) $(LDFLAGS) -shared -o $@ $^ | ||
|
||
$(SLIBFILE): $(OBJS) | ||
$(AR) rs $@ $^ | ||
|
||
.PHONY: all | ||
all: $(LIBFILE) $(SLIBFILE) | ||
clean: $(OBJS) $(LIBFILE) $(SLIBFILE) | ||
rm $^ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only with msvc. where are you dealing with a lib file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also under mingw64? ce33683 changed that we are now linking sys.so statically against compiler-rt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, mingw static libraries are .a extension. compiler-rt's build system is probably full of wrong windows==msvc assumptions that should be fixed rather than worked around the wrong way here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will fix this in the morning (It was my wrong assumption, not compiler-rts)
Is there a way of detecting the compiler from the Makefile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a USEMSVC or some flag like that but it's a hack, you probably shouldn't worry about it. if we ever support msvc properly it'll be via cmake anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just changing
lib
toa
would be sufficient for now?