mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH v2] llvm/clang support for musl-cross-make
@ 2021-01-12 22:31 Patrick Oppenlander
  0 siblings, 0 replies; only message in thread
From: Patrick Oppenlander @ 2021-01-12 22:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Hi,

attached is a v2 of the musl-cross-make clang build patch.

Changes from v1:

* Install clang-resource-headers (fixes missing stdatomic.h, etc.)
* Fix installed symlinks (fixes missing cc, c++, cpp)
* Statically link libunwind and libc++abi into libc++.a and libc++.so
* Updated patch for armv7m clang VFP asm crash
* Support setting COMPILER from config.mak
* Support target specific musl config by setting MUSL_CONFIG_<target> variable

Patrick

[-- Attachment #2: 0001-clang-support.patch --]
[-- Type: text/x-patch, Size: 25231 bytes --]

From f6b8eb0b72b6f4ddda37acebb589ab8569a4810d Mon Sep 17 00:00:00 2001
From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
Date: Tue, 5 Jan 2021 09:33:53 +1100
Subject: [PATCH 1/2] clang support

---
 Makefile                                      |  58 ++++--
 hashes/llvm-project-11.0.0.tar.xz.sha1        |   1 +
 litecross/Makefile.clang                      | 186 ++++++++++++++++++
 litecross/{Makefile => Makefile.gcc}          |   0
 ...add-builtins-to-dynamic-library-link.patch |  30 +++
 ...able-crt-support-on-armv7-and-armv7m.patch |  25 +++
 ...panding-target-triple-in-sysroot-pat.patch |  39 ++++
 ...orkarounds-for-clang-vfp-asm-crashes.patch |  95 +++++++++
 8 files changed, 415 insertions(+), 19 deletions(-)
 create mode 100644 hashes/llvm-project-11.0.0.tar.xz.sha1
 create mode 100644 litecross/Makefile.clang
 rename litecross/{Makefile => Makefile.gcc} (100%)
 create mode 100644 patches/llvm-project-11.0.0/0001-libcxxabi-add-builtins-to-dynamic-library-link.patch
 create mode 100644 patches/llvm-project-11.0.0/0002-compiler-rt-enable-crt-support-on-armv7-and-armv7m.patch
 create mode 100644 patches/llvm-project-11.0.0/0003-clang-support-expanding-target-triple-in-sysroot-pat.patch
 create mode 100644 patches/musl-1.2.1/0001-math-more-workarounds-for-clang-vfp-asm-crashes.patch

diff --git a/Makefile b/Makefile
index a412f60..0e29588 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,7 @@
 
 SOURCES = sources
 
-CONFIG_SUB_REV = 3d5db9ebe860
-BINUTILS_VER = 2.33.1
-GCC_VER = 9.2.0
-MUSL_VER = 1.2.1
-GMP_VER = 6.1.2
-MPC_VER = 1.1.0
-MPFR_VER = 4.0.2
-LINUX_VER = headers-4.19.88
+COMPILER = gcc
 
 GNU_SITE = https://ftp.gnu.org/pub/gnu
 GCC_SITE = $(GNU_SITE)/gcc
@@ -17,6 +10,7 @@ GMP_SITE = $(GNU_SITE)/gmp
 MPC_SITE = $(GNU_SITE)/mpc
 MPFR_SITE = $(GNU_SITE)/mpfr
 ISL_SITE = http://isl.gforge.inria.fr/
+LLVM_SITE = https://github.com/llvm/llvm-project/releases/download
 
 MUSL_SITE = https://www.musl-libc.org/releases
 MUSL_REPO = git://git.musl-libc.org/musl
@@ -30,24 +24,47 @@ SHA1_CMD = sha1sum -c
 COWPATCH = $(CURDIR)/cowpatch.sh
 
 HOST = $(if $(NATIVE),$(TARGET))
-BUILD_DIR = build/$(if $(HOST),$(HOST),local)/$(TARGET)
+BUILD_DIR = build-$(COMPILER)/$(if $(HOST),$(HOST),local)/$(TARGET)
 OUTPUT = $(CURDIR)/output$(if $(HOST),-$(HOST))
 
-REL_TOP = ../../..
+REL_TOP = ../..$(if $(TARGET),/..)
 
 -include config.mak
 
-SRC_DIRS = gcc-$(GCC_VER) binutils-$(BINUTILS_VER) musl-$(MUSL_VER) \
+MUSL_VER ?= 1.2.1
+LINUX_VER ?= headers-4.19.88
+
+ifeq ($(COMPILER),gcc)
+
+CONFIG_SUB_REV ?= 3d5db9ebe860
+BINUTILS_VER ?= 2.33.1
+GCC_VER ?= 9.2.0
+GMP_VER ?= 6.1.2
+MPC_VER ?= 1.1.0
+MPFR_VER ?= 4.0.2
+
+endif
+
+ifeq ($(COMPILER),clang)
+
+LLVM_VER ?= 11.0.0
+
+endif
+
+SRC_DIRS = musl-$(MUSL_VER) \
+	$(if $(GCC_VER),gcc-$(GCC_VER)) \
+	$(if $(BINUTILS_VER),binutils-$(BINUTILS_VER)) \
 	$(if $(GMP_VER),gmp-$(GMP_VER)) \
 	$(if $(MPC_VER),mpc-$(MPC_VER)) \
 	$(if $(MPFR_VER),mpfr-$(MPFR_VER)) \
 	$(if $(ISL_VER),isl-$(ISL_VER)) \
-	$(if $(LINUX_VER),linux-$(LINUX_VER))
+	$(if $(LINUX_VER),linux-$(LINUX_VER)) \
+	$(if $(LLVM_VER),llvm-project-$(LLVM_VER))
 
 all:
 
 clean:
-	rm -rf gcc-* binutils-* musl-* gmp-* mpc-* mpfr-* isl-* build build-* linux-*
+	rm -rf gcc-* binutils-* musl-* gmp-* mpc-* mpfr-* isl-* build build-* linux-* llvm-project-*
 
 distclean: clean
 	rm -rf sources
@@ -70,6 +87,7 @@ $(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-4*)): SITE = $(LIN
 $(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-3*)): SITE = $(LINUX_SITE)/v3.x
 $(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-2.6*)): SITE = $(LINUX_SITE)/v2.6
 $(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/linux-headers-*)): SITE = $(LINUX_HEADERS_SITE)
+$(patsubst hashes/%.sha1,$(SOURCES)/%,$(wildcard hashes/llvm-project-*)): SITE = $(LLVM_SITE)/llvmorg-$(patsubst llvm-project-%,%,$(basename $(basename $(notdir $@))))
 
 $(SOURCES):
 	mkdir -p $@
@@ -150,10 +168,10 @@ extract_all: | $(SRC_DIRS)
 
 # Rules for building.
 
-ifeq ($(TARGET),)
+ifeq ($(COMPILER)$(TARGET),gcc)
 
 all:
-	@echo TARGET must be set via config.mak or command line.
+	@echo TARGET must be set for gcc build via config.mak or command line.
 	@exit 1
 
 else
@@ -162,20 +180,22 @@ $(BUILD_DIR):
 	mkdir -p $@
 
 $(BUILD_DIR)/Makefile: | $(BUILD_DIR)
-	ln -sf $(REL_TOP)/litecross/Makefile $@
+	ln -sf $(REL_TOP)/litecross/Makefile.$(COMPILER) $@
 
 $(BUILD_DIR)/config.mak: | $(BUILD_DIR)
 	printf >$@ '%s\n' \
-	"TARGET = $(TARGET)" \
+	$(if $(TARGET),"TARGET = $(TARGET)") \
 	"HOST = $(HOST)" \
 	"MUSL_SRCDIR = $(REL_TOP)/musl-$(MUSL_VER)" \
-	"GCC_SRCDIR = $(REL_TOP)/gcc-$(GCC_VER)" \
-	"BINUTILS_SRCDIR = $(REL_TOP)/binutils-$(BINUTILS_VER)" \
+	$(if $(GCC_VER),"GCC_SRCDIR = $(REL_TOP)/gcc-$(GCC_VER)") \
+	$(if $(BINUTILS_VER),"BINUTILS_SRCDIR = $(REL_TOP)/binutils-$(BINUTILS_VER)") \
 	$(if $(GMP_VER),"GMP_SRCDIR = $(REL_TOP)/gmp-$(GMP_VER)") \
 	$(if $(MPC_VER),"MPC_SRCDIR = $(REL_TOP)/mpc-$(MPC_VER)") \
 	$(if $(MPFR_VER),"MPFR_SRCDIR = $(REL_TOP)/mpfr-$(MPFR_VER)") \
 	$(if $(ISL_VER),"ISL_SRCDIR = $(REL_TOP)/isl-$(ISL_VER)") \
 	$(if $(LINUX_VER),"LINUX_SRCDIR = $(REL_TOP)/linux-$(LINUX_VER)") \
+	$(if $(LLVM_VER),"LLVM_SRCDIR = $(REL_TOP)/llvm-project-$(LLVM_VER)") \
+	$(if $(LLVM_VER),"LLVM_VER = $(LLVM_VER)") \
 	"-include $(REL_TOP)/config.mak"
 
 all: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.mak
diff --git a/hashes/llvm-project-11.0.0.tar.xz.sha1 b/hashes/llvm-project-11.0.0.tar.xz.sha1
new file mode 100644
index 0000000..ef4b704
--- /dev/null
+++ b/hashes/llvm-project-11.0.0.tar.xz.sha1
@@ -0,0 +1 @@
+3c88390b19ac6779c8d9c89256892d690903412b  llvm-project-11.0.0.tar.xz
diff --git a/litecross/Makefile.clang b/litecross/Makefile.clang
new file mode 100644
index 0000000..9059b4a
--- /dev/null
+++ b/litecross/Makefile.clang
@@ -0,0 +1,186 @@
+
+OUTPUT = $(CURDIR)/output
+
+LLVM_SRCDIR = LLVM_SRCDIR_not_set
+MUSL_SRCDIR = MUSL_SRCDIR_not_set
+
+TARGETS = \
+	aarch64-linux-musleabi \
+	armv7-linux-musleabi \
+	armv7-linux-musleabihf \
+	armv7m-linux-musleabi \
+	armv7m-linux-musleabihf \
+	x86_64-linux-musl \
+	# end
+
+DEFAULT_TARGET = x86_64-linux-musl
+
+TOOLS = \
+	llvm-ar \
+	llvm-nm \
+	llvm-objcopy \
+	llvm-objdump \
+	llvm-ranlib \
+	llvm-size \
+	llvm-strip \
+	# end
+
+-include config.mak
+
+# TODO: determine LLVM_TARGETS_TO_BUILD from TARGETS?
+FULL_LLVM_CONFIG = $(LLVM_CONFIG) \
+	-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
+	-DCLANG_DEFAULT_LINKER=lld \
+	-DCLANG_DEFAULT_OBJCOPY=llvm-objcopy \
+	-DCLANG_DEFAULT_RTLIB=compiler-rt \
+	-DCMAKE_BUILD_TYPE=MinSizeRel \
+	-DCMAKE_INSTALL_PREFIX=/clang \
+	-DDEFAULT_SYSROOT=../../TARGET \
+	-DLLVM_BUILTIN_TARGETS='$(subst $(subst ,, ),;,$(TARGETS))' \
+	-DLLVM_DEFAULT_TARGET_TRIPLE=$(DEFAULT_TARGET) \
+	-DLLVM_DISTRIBUTION_COMPONENTS='clang;clang-resource-headers;lld;LTO;$(subst $(subst ,, ),;,$(TOOLS))' \
+	-DLLVM_ENABLE_PROJECTS='clang;lld' \
+	-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
+	-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
+	-DLLVM_RUNTIME_TARGETS='$(subst $(subst ,, ),;,$(TARGETS))' \
+	-DLLVM_TARGETS_TO_BUILD='AArch64;ARM;Mips;PowerPC;X86' \
+	$(foreach t,$(TARGETS),-DBUILTINS_$(t)_CMAKE_SYSROOT=$(CURDIR)/obj_sysroot/$(t)) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_CMAKE_CXX_FLAGS='-L$(CURDIR)/obj_musl/$(t)/lib -B$(CURDIR)/obj_musl/$(t)/lib -Qunused-arguments') \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_CMAKE_C_FLAGS='-L$(CURDIR)/obj_musl/$(t)/lib -B$(CURDIR)/obj_musl/$(t)/lib -Qunused-arguments') \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_CMAKE_SYSROOT=$(CURDIR)/obj_sysroot/$(t)) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_COMPILER_RT_BUILD_LIBFUZZER=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_COMPILER_RT_BUILD_SANITIZERS=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_COMPILER_RT_BUILD_XRAY=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_ENABLE_SHARED=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_ENABLE_STATIC_UNWINDER=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_INSTALL_LIBRARY=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_USE_COMPILER_RT=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_USE_LLVM_UNWINDER=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXX_HAS_MUSL_LIBC=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXX_USE_COMPILER_RT=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBUNWIND_ENABLE_SHARED=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBUNWIND_INSTALL_LIBRARY=OFF) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBUNWIND_USE_COMPILER_RT=ON) \
+	# end
+
+all: llvm musl
+
+install: install-llvm install-musl install-kernel-headers install-configs install-symlinks
+
+llvm: | obj_llvm/.lc_built_3
+musl: | $(foreach t,$(TARGETS),obj_musl/$(t)/.lc_built)
+install-musl: $(foreach t,$(TARGETS),install-musl_$(t))
+install-kernel-headers: $(foreach t,$(TARGETS),install-kernel-headers_$(t))
+install-configs: $(foreach t,$(TARGETS),install-configs_$(t))
+install-symlinks: $(foreach t,$(TARGETS),install-symlinks_$(t))
+
+.PHONY: all llvm musl install-llvm install-musl install-kernel-headers install-configs install-symlinks clean
+
+src_llvm: | $(LLVM_SRCDIR)
+	ln -sf $(LLVM_SRCDIR) $@
+
+src_musl: | $(MUSL_SRCDIR)
+	ln -sf $(MUSL_SRCDIR) $@
+
+src_kernel_headers: | $(LINUX_SRCDIR)
+	ln -sf "$(LINUX_SRCDIR)" $@
+
+%/:
+	mkdir -p $@
+
+obj_llvm/.lc_configured: | obj_llvm/ src_llvm
+	cd obj_llvm && cmake -G "Unix Makefiles" $(FULL_LLVM_CONFIG) ../src_llvm/llvm
+	touch $@
+
+obj_llvm/.lc_built_1: | obj_llvm/.lc_configured
+	cd obj_llvm && $(MAKE) distribution
+	touch $@
+
+obj_musl/%/.lc_configured: | obj_musl/%/ src_musl obj_llvm/.lc_built_1
+	cd obj_musl/$* && ../../src_musl/configure \
+		--prefix= \
+		--target=$* \
+		--disable-wrapper \
+		LIBCC=../../obj_llvm/lib/clang/$(LLVM_VER)/lib/$*/libclang_rt.builtins.a \
+		CC="../../obj_llvm/bin/clang --target=$*" \
+		$(MUSL_CONFIG) $(MUSL_CONFIG_$*)
+	touch $@
+
+obj_sysroot/%/.lc_headers: | obj_sysroot/ obj_musl/%/.lc_configured
+	cd obj_musl/$* && $(MAKE) DESTDIR=$(CURDIR)/obj_sysroot/$* install-headers
+	touch $@
+
+obj_llvm/.lc_built_2: | $(foreach t,$(TARGETS),obj_sysroot/$(t)/.lc_headers)
+	cd obj_llvm && $(MAKE) builtins
+	touch $@
+
+obj_musl/%/.lc_built: | obj_musl/%/.lc_configured obj_llvm/.lc_built_2
+	cd obj_musl/$* && $(MAKE) AR=../../obj_llvm/bin/llvm-ar \
+				  RANLIB=../../obj_llvm/bin/llvm-ranlib
+	touch $@
+
+obj_sysroot/%/.lc_crt_workaround:
+	# Some configure tests for llvm runtimes fail without crtbegin and
+	# crtend files in the sysroot. The runtimes build generates these files
+	# leading to a chicken-egg problem.
+	mkdir -p obj_sysroot/$*/lib
+	cd obj_sysroot/$*/lib && touch crtbeginT.o crtbeginS.o crtbegin.o crtend.o crtendS.o
+	touch $@
+
+obj_kernel_headers/%/.lc_built: | src_kernel_headers
+	mkdir -p $(CURDIR)/obj_kernel_headers/$*/staged
+	cd src_kernel_headers && $(MAKE) ARCH=$(call fn_linux_arch,$*) O=$(CURDIR)/obj_kernel_headers/$* INSTALL_HDR_PATH=$(CURDIR)/obj_kernel_headers/$*/staged headers_install
+	find obj_kernel_headers/$*/staged/include '(' -name .install -o -name ..install.cmd ')' -exec rm {} +
+	touch $@
+
+obj_sysroot/%/.lc_linux_headers: | obj_kernel_headers/%/.lc_built
+	mkdir -p obj_sysroot/$*/include
+	cp -R obj_kernel_headers/$*/staged/include/* obj_sysroot/$*/include
+
+obj_llvm/.lc_built_3: | $(foreach t,$(TARGETS),obj_musl/$(t)/.lc_built \
+					       obj_sysroot/$(t)/.lc_crt_workaround \
+					       obj_sysroot/$(t)/.lc_linux_headers)
+	cd obj_llvm && $(MAKE) runtimes
+	touch $@
+
+install-llvm: | obj_llvm/.lc_built_3
+	# -j1 because there's a broken dependency in the llvm build somewhere
+	#  which often results in missing c++ libraries for some targets
+	cd obj_llvm && $(MAKE) -j1 DESTDIR=$(DESTDIR)$(OUTPUT) install-distribution install-builtins install-runtimes
+
+install-musl_%: | obj_musl/%/.lc_built
+	cd obj_musl/$* && $(MAKE) $(MUSL_VARS) DESTDIR=$(DESTDIR)$(OUTPUT)/$* install
+
+install-kernel-headers_%: | obj_kernel_headers/%/.lc_built
+	mkdir -p $(DESTDIR)$(OUTPUT)/$*/include
+	cp -R obj_kernel_headers/$*/staged/include/* $(DESTDIR)$(OUTPUT)/$*/include
+
+install-configs_%: | $(DESDIR)$(OUTPUT)/clang/bin/
+	echo "--target=$*" > $(DESTDIR)$(OUTPUT)/clang/bin/$*-clang.cfg
+	echo "--target=$*" > $(DESTDIR)$(OUTPUT)/clang/bin/$*-clang++.cfg
+
+install-symlinks_%: | $(DESTDIR)$(OUTPUT)/bin/
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/clang $*-clang
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/clang++ $*-clang++
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/clang-cpp $*-cpp
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/clang $*-cc
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/clang++ $*-c++
+	cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/ld.lld $*-ld
+	$(foreach t,$(TOOLS),cd $(DESTDIR)$(OUTPUT)/bin && ln -sf ../clang/bin/$(t) $*-$(subst llvm-,,$(t);))
+
+clean:
+	rm -rf src_* obj_*
+
+# $(call fn_linux_arch,target-triple)
+#     Determine linux architecture from target triple
+ifeq ($(LINUX_SRCDIR),)
+$(error LINUX_SRCDIR is required for llvm libc++ build)
+endif
+LINUX_ARCH_LIST := $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
+fn_target_arch = $(firstword $(subst -, ,$(1)))
+fn_target_arch_mangled = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(call fn_target_arch,$(1))))
+fn_linux_arch = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(call fn_target_arch_mangled,$(1))),$(a))))
+
+.SECONDARY:
diff --git a/litecross/Makefile b/litecross/Makefile.gcc
similarity index 100%
rename from litecross/Makefile
rename to litecross/Makefile.gcc
diff --git a/patches/llvm-project-11.0.0/0001-libcxxabi-add-builtins-to-dynamic-library-link.patch b/patches/llvm-project-11.0.0/0001-libcxxabi-add-builtins-to-dynamic-library-link.patch
new file mode 100644
index 0000000..e7c4914
--- /dev/null
+++ b/patches/llvm-project-11.0.0/0001-libcxxabi-add-builtins-to-dynamic-library-link.patch
@@ -0,0 +1,30 @@
+From 6f437b42e66c7552c3b92fd1bd46c96ed484dfbf Mon Sep 17 00:00:00 2001
+From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
+Date: Fri, 8 Jan 2021 16:46:37 +1100
+Subject: [PATCH 1/3] libcxxabi: add builtins to dynamic library link
+
+Otherwise libc++abi.so fails to link on arm with undefined references to
+some __aeabi_ builtins.
+---
+ libcxxabi/src/CMakeLists.txt | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
+index 42bec421d2be..9dba22ea3d43 100644
+--- a/libcxxabi/src/CMakeLists.txt
++++ b/libcxxabi/src/CMakeLists.txt
+@@ -73,6 +73,11 @@ else()
+   add_library_flags_if(LIBCXXABI_HAS_C_LIB c)
+ endif()
+ 
++if (LIBCXXABI_USE_COMPILER_RT)
++  find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
++  list(APPEND LIBCXXABI_SHARED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
++endif ()
++
+ if (LIBCXXABI_USE_LLVM_UNWINDER)
+   # Prefer using the in-tree version of libunwind, either shared or static. If
+   # none are found fall back to using -lunwind.
+-- 
+2.30.0
+
diff --git a/patches/llvm-project-11.0.0/0002-compiler-rt-enable-crt-support-on-armv7-and-armv7m.patch b/patches/llvm-project-11.0.0/0002-compiler-rt-enable-crt-support-on-armv7-and-armv7m.patch
new file mode 100644
index 0000000..50a78f5
--- /dev/null
+++ b/patches/llvm-project-11.0.0/0002-compiler-rt-enable-crt-support-on-armv7-and-armv7m.patch
@@ -0,0 +1,25 @@
+From 2425a718046a82e705d05400bd9204b265ca3262 Mon Sep 17 00:00:00 2001
+From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
+Date: Fri, 8 Jan 2021 21:34:39 +1100
+Subject: [PATCH 2/3] compiler-rt: enable crt support on armv7 and armv7m
+
+---
+ compiler-rt/cmake/config-ix.cmake | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
+index 2edc1dabd90d..7d8b95146e9a 100644
+--- a/compiler-rt/cmake/config-ix.cmake
++++ b/compiler-rt/cmake/config-ix.cmake
+@@ -255,7 +255,7 @@ function(is_valid_apple_platform platform is_valid_out)
+ endfunction()
+ 
+ set(ARM64 aarch64)
+-set(ARM32 arm armhf)
++set(ARM32 arm armv7 armv7m armhf)
+ set(HEXAGON hexagon)
+ set(X86 i386)
+ set(X86_64 x86_64)
+-- 
+2.30.0
+
diff --git a/patches/llvm-project-11.0.0/0003-clang-support-expanding-target-triple-in-sysroot-pat.patch b/patches/llvm-project-11.0.0/0003-clang-support-expanding-target-triple-in-sysroot-pat.patch
new file mode 100644
index 0000000..9644633
--- /dev/null
+++ b/patches/llvm-project-11.0.0/0003-clang-support-expanding-target-triple-in-sysroot-pat.patch
@@ -0,0 +1,39 @@
+From f0ecb3850d7825cd967d22c09ed73d990605c70b Mon Sep 17 00:00:00 2001
+From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
+Date: Mon, 11 Jan 2021 10:39:27 +1100
+Subject: [PATCH 3/3] clang: support expanding target triple in sysroot path
+
+This allows clang to switch sysroot (or, more usefully, default sysroot)
+based on target triple.
+
+For example, configuring with
+
+-DDEFAULT_SYSROOT=../TARGET
+
+will automatically select a target specific sysroot one level up from
+the clang binary location.
+---
+ clang/lib/Driver/Driver.cpp | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
+index ece8222dcf24..8a3b068d86b9 100644
+--- a/clang/lib/Driver/Driver.cpp
++++ b/clang/lib/Driver/Driver.cpp
+@@ -1121,6 +1121,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
+                     .Default(SaveTempsCwd);
+   }
+ 
++  // expand TARGET in sysroot path
++  if (!SysRoot.empty()) {
++    size_t pos{0};
++    while ((pos = SysRoot.find("TARGET", pos)) != std::string::npos)
++      SysRoot.replace(pos, 6, TargetTriple);
++  }
++
+   setLTOMode(Args);
+ 
+   // Process -fembed-bitcode= flags.
+-- 
+2.30.0
+
diff --git a/patches/musl-1.2.1/0001-math-more-workarounds-for-clang-vfp-asm-crashes.patch b/patches/musl-1.2.1/0001-math-more-workarounds-for-clang-vfp-asm-crashes.patch
new file mode 100644
index 0000000..1badd21
--- /dev/null
+++ b/patches/musl-1.2.1/0001-math-more-workarounds-for-clang-vfp-asm-crashes.patch
@@ -0,0 +1,95 @@
+From 76b39f971d296a313d71d1313091a5b18fa94f94 Mon Sep 17 00:00:00 2001
+From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
+Date: Mon, 11 Jan 2021 14:24:57 +1100
+Subject: [PATCH 1/3] math: more workarounds for clang vfp asm crashes
+
+clang-11.0.0 crashes with the following output when building sqrt.c and
+fabs.c for armv7-m:
+
+../../obj_llvm/bin/clang --target=armv7m-linux-musleabihf -std=c99 -nostdinc -ffreestanding -frounding-math -Wa,--noexecstack -D_XOPEN_SOURCE=700 -I../../src_musl/arch/arm -I../../src_musl/arch/generic -Iobj/src/internal -I../../src_musl/src/include -I../../src_musl/src/internal -Iobj/include -I../../src_musl/include  -Os -pipe -fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -w -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith -Qunused-arguments -mimplicit-it=always -Wa,-mthumb -DBROKEN_VFP_ASM  -fPIC -c -o obj/src/math/arm/sqrt.lo ../../src_musl/src/math/arm/sqrt.c
+PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
+Stack dump:
+0.	Program arguments: ../../obj_llvm/bin/clang --target=armv7m-linux-musleabihf -std=c99 -nostdinc -ffreestanding -frounding-math -Wa,--noexecstack -D_XOPEN_SOURCE=700 -I../../src_musl/arch/arm -I../../src_musl/arch/generic -Iobj/src/internal -I../../src_musl/src/include -I../../src_musl/src/internal -Iobj/include -I../../src_musl/include -Os -pipe -fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -w -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith -Qunused-arguments -mimplicit-it=always -Wa,-mthumb -DBROKEN_VFP_ASM -fPIC -c -o obj/src/math/arm/sqrt.lo ../../src_musl/src/math/arm/sqrt.c
+1.	<eof> parser at end of file
+2.	Code generation
+3.	Running pass 'Function Pass Manager' on module '../../src_musl/src/math/arm/sqrt.c'.
+4.	Running pass 'ARM Instruction Selection' on function '@sqrt'
+../../obj_llvm/bin/clang(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x2a)[0x557581a86b42]
+../../obj_llvm/bin/clang(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x557581a858ac]
+../../obj_llvm/bin/clang(+0x16cc327)[0x557581a3e327]
+../../obj_llvm/bin/clang(+0x16cc786)[0x557581a3e786]
+/usr/lib/libpthread.so.0(+0x140f0)[0x7fbcbc4760f0]
+../../obj_llvm/bin/clang(+0xbcfc9c)[0x557580f41c9c]
+../../obj_llvm/bin/clang(_ZNK4llvm12RegsForValue13getCopyToRegsENS_7SDValueERNS_12SelectionDAGERKNS_5SDLocERS1_PS1_PKNS_5ValueENS_3ISD8NodeTypeE+0x2b0)[0x5575820f5c20]
+../../obj_llvm/bin/clang(_ZN4llvm19SelectionDAGBuilder14visitInlineAsmERKNS_8CallBaseE+0x1e4c)[0x55758210f5a6]
+../../obj_llvm/bin/clang(_ZN4llvm19SelectionDAGBuilder5visitERKNS_11InstructionE+0x60)[0x55758211c954]
+../../obj_llvm/bin/clang(_ZN4llvm16SelectionDAGISel16SelectBasicBlockENS_14ilist_iteratorINS_12ilist_detail12node_optionsINS_11InstructionELb0ELb0EvEELb0ELb1EEES6_Rb+0x7d)[0x557582143d05]
+../../obj_llvm/bin/clang(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0xe07)[0x557582146397]
+../../obj_llvm/bin/clang(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x572)[0x557582146aa6]
+../../obj_llvm/bin/clang(+0xd218e3)[0x5575810938e3]
+../../obj_llvm/bin/clang(+0x12260df)[0x5575815980df]
+../../obj_llvm/bin/clang(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x20a)[0x557581774958]
+../../obj_llvm/bin/clang(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2d)[0x557581774cdd]
+../../obj_llvm/bin/clang(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x244)[0x557581774526]
+../../obj_llvm/bin/clang(_ZN5clang17EmitBackendOutputERNS_17DiagnosticsEngineERKNS_19HeaderSearchOptionsERKNS_14CodeGenOptionsERKNS_13TargetOptionsERKNS_11LangOptionsERKN4llvm10DataLayoutEPNSE_6ModuleENS_13BackendActionESt10unique_ptrINSE_17raw_pwrite_streamESt14default_deleteISM_EE+0x2e83)[0x557581b95ac0]
+../../obj_llvm/bin/clang(+0x1e667c6)[0x5575821d87c6]
+../../obj_llvm/bin/clang(_ZN5clang8ParseASTERNS_4SemaEbb+0x29a)[0x5575826800c6]
+../../obj_llvm/bin/clang(_ZN5clang14FrontendAction7ExecuteEv+0x55)[0x557581ea6211]
+../../obj_llvm/bin/clang(_ZN5clang16CompilerInstance13ExecuteActionERNS_14FrontendActionE+0x5ba)[0x557581e81166]
+../../obj_llvm/bin/clang(_ZN5clang25ExecuteCompilerInvocationEPNS_16CompilerInstanceE+0x2fc)[0x557581efbeb8]
+../../obj_llvm/bin/clang(_Z8cc1_mainN4llvm8ArrayRefIPKcEES2_Pv+0x848)[0x557580efd525]
+../../obj_llvm/bin/clang(+0xb89e71)[0x557580efbe71]
+../../obj_llvm/bin/clang(+0x1a7bb68)[0x557581dedb68]
+../../obj_llvm/bin/clang(_ZN4llvm20CrashRecoveryContext9RunSafelyENS_12function_refIFvvEEE+0x8b)[0x557581a3e49d]
+../../obj_llvm/bin/clang(+0x1a7c1a6)[0x557581dee1a6]
+../../obj_llvm/bin/clang(_ZNK5clang6driver11Compilation14ExecuteCommandERKNS0_7CommandERPS3_+0x246)[0x557581dd8ede]
+../../obj_llvm/bin/clang(_ZNK5clang6driver11Compilation11ExecuteJobsERKNS0_7JobListERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x64)[0x557581dd8fca]
+../../obj_llvm/bin/clang(_ZN5clang6driver6Driver18ExecuteCompilationERNS0_11CompilationERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0xbf)[0x557581ddc385]
+../../obj_llvm/bin/clang(main+0x19d6)[0x557580e85de8]
+/usr/lib/libc.so.6(__libc_start_main+0xf2)[0x7fbcbbee6152]
+../../obj_llvm/bin/clang(_start+0x2e)[0x557580efb42e]
+clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
+clang version 11.0.0 (https://github.com/richfelker/musl-cross-make 79528a0baad2c85087d33075f2ccdbf13dc556dd)
+Target: armv7m-unknown-linux-musleabihf
+Thread model: posix
+InstalledDir: /home/patrick/src/toolchain/musl-cross-make/build-clang/local/obj_musl/armv7m-linux-musleabihf/../../obj_llvm/bin
+clang-11: note: diagnostic msg:
+********************
+
+PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
+Preprocessed source(s) and associated run script(s) are located at:
+clang-11: note: diagnostic msg: /tmp/sqrt-71be55.c
+clang-11: note: diagnostic msg: /tmp/sqrt-71be55.sh
+clang-11: note: diagnostic msg:
+---
+ src/math/arm/fabs.c | 2 +-
+ src/math/arm/sqrt.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/math/arm/fabs.c b/src/math/arm/fabs.c
+index f890520a..ac97c04d 100644
+--- a/src/math/arm/fabs.c
++++ b/src/math/arm/fabs.c
+@@ -1,6 +1,6 @@
+ #include <math.h>
+ 
+-#if __ARM_PCS_VFP
++#if __ARM_PCS_VFP && (!BROKEN_VFP_ASM || !__thumb2__)
+ 
+ double fabs(double x)
+ {
+diff --git a/src/math/arm/sqrt.c b/src/math/arm/sqrt.c
+index 874af960..026e44bb 100644
+--- a/src/math/arm/sqrt.c
++++ b/src/math/arm/sqrt.c
+@@ -1,6 +1,6 @@
+ #include <math.h>
+ 
+-#if __ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)
++#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && (!BROKEN_VFP_ASM || !__thumb2__)
+ 
+ double sqrt(double x)
+ {
+-- 
+2.30.0
+
-- 
2.30.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-12 22:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 22:31 [musl] [PATCH v2] llvm/clang support for musl-cross-make Patrick Oppenlander

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git