mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH] llvm/clang support for musl-cross-make
@ 2021-01-11  5:33 Patrick Oppenlander
  2021-01-11 21:23 ` [musl] " Patrick Oppenlander
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Oppenlander @ 2021-01-11  5:33 UTC (permalink / raw)
  To: musl

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

Hi Rich,

Recently I briefly mentioned on IRC I've been working on a musl-cross-make
build for llvm/clang. I've reused the source download & patch infrastructure in
musl-cross-make and have added a new litecross implementation for clang.

The clang build tries to follow the same philosophy as the gcc build with one
key difference - it builds multiple targets into one toolchain.

Currently either gcc or clang is built by setting the COMPILER variable
(default gcc). It should be possible to do both at once but that would be a
bigger change.

I've had to fix a few things along the way to get this to hang together and
have included patches for the issues I came across. If you're happy with the
approach I'll submit these upstream.

The configure tests for the llvm runtime libraries are fairly awful and seem to
assume that a complete toolchain is available. There's two workarounds:
1. The RUNTIMES_*_CMAKE_{C,CXX}_FLAGS variables contain a -Qunused-arguments
   flag otherwise the cmake C/CXX compiler ABI detection tests fail. I couldn't
   work out another way of specifying the library/binary paths that worked.
2. The sysroot needs to contain crtbegin{T,S,}.o and crtend{S,}.o files for
   a few configure tests. I currently put empty dummies in there.

There doesn't appear to be a way to specify a name prefix for the clang/llvm
binaries. The build currently installs clang into a clang directory and
populates a bin directory with prefixed symlinks. This is to avoid clashing
with system binaries if the toolchain is added to $PATH.

I included a clang patch to support automatically selecting a sysroot based on
the --target argument. I thought it would be possible to do this using clang
configuration files but the --sysroot command line argument can't specify a
sysroot path which is relative to the clang binary. Only the build time
DEFAULT_SYSROOT has that capability.

There's a parallel build dependency problem somewhere in the install-runtimes
target of the llvm build system. It almost always fails to copy some files so
I've forced it to run single threaded for now.

I haven't used the resultant toolchain much yet. It builds working C and C++
"hello world" tests both statically and dynamically. I tried a toybox build and
that worked too.

I've attached a patch which should apply the current tip of the musl-cross-make
tree.

Patrick

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

From 8d73f3f432ec209d1bae0c2e2e5790b461d3d3a6 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] clang support

---
 Makefile                                      |  46 +++--
 hashes/llvm-project-11.0.0.tar.xz.sha1        |   1 +
 litecross/Makefile.clang                      | 177 ++++++++++++++++++
 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 ++++
 ...karound-armv7m-clang-vfp-asm-crashes.patch |  92 +++++++++
 8 files changed, 397 insertions(+), 13 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-workaround-armv7m-clang-vfp-asm-crashes.patch

diff --git a/Makefile b/Makefile
index a412f60..f66cecd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,27 @@
 
 SOURCES = sources
 
+COMPILER = gcc
+
+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
-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
+
+endif
+
+ifeq ($(COMPILER),clang)
+
+LLVM_VER = 11.0.0
+
+endif
 
 GNU_SITE = https://ftp.gnu.org/pub/gnu
 GCC_SITE = $(GNU_SITE)/gcc
@@ -17,6 +30,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 +44,27 @@ 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) \
+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..d7e9f22
--- /dev/null
+++ b/litecross/Makefile.clang
@@ -0,0 +1,177 @@
+
+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;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_USE_COMPILER_RT=ON) \
+	$(foreach t,$(TARGETS),-DRUNTIMES_$(t)_LIBCXXABI_USE_LLVM_UNWINDER=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_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)
+	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=$* -lc++abi -lunwind" > $(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 $*-clang-cpp
+	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-workaround-armv7m-clang-vfp-asm-crashes.patch b/patches/musl-1.2.1/0001-math-workaround-armv7m-clang-vfp-asm-crashes.patch
new file mode 100644
index 0000000..fb2b6f8
--- /dev/null
+++ b/patches/musl-1.2.1/0001-math-workaround-armv7m-clang-vfp-asm-crashes.patch
@@ -0,0 +1,92 @@
+From 01b58f48c609ec75a77726033503890e4205c605 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] math: workaround armv7m clang vfp asm crashes
+
+../../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..316ba776 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
+ 
+ double fabs(double x)
+ {
+diff --git a/src/math/arm/sqrt.c b/src/math/arm/sqrt.c
+index 874af960..ac1a6ed1 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
+ 
+ double sqrt(double x)
+ {
+-- 
+2.30.0
+
-- 
2.30.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [musl] Re: [PATCH] llvm/clang support for musl-cross-make
  2021-01-11  5:33 [musl] [PATCH] llvm/clang support for musl-cross-make Patrick Oppenlander
@ 2021-01-11 21:23 ` Patrick Oppenlander
  2021-01-12  1:26   ` Patrick Oppenlander
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Oppenlander @ 2021-01-11 21:23 UTC (permalink / raw)
  To: musl

On Mon, Jan 11, 2021 at 4:33 PM Patrick Oppenlander
<patrick.oppenlander@gmail.com> wrote:
>
>
> I've attached a patch which should apply the current tip of the musl-cross-make
> tree.
>

The musl patch included is a bit overly pessimistic -- the crash only
occurs for armv7m so the #if test should probably be narrowed down a
bit.

I also forgot to mention that I'll provide documentation updates if
you are happy to go ahead in this direction.

Patrick

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [musl] Re: [PATCH] llvm/clang support for musl-cross-make
  2021-01-11 21:23 ` [musl] " Patrick Oppenlander
@ 2021-01-12  1:26   ` Patrick Oppenlander
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Oppenlander @ 2021-01-12  1:26 UTC (permalink / raw)
  To: musl

On Tue, Jan 12, 2021 at 8:23 AM Patrick Oppenlander
<patrick.oppenlander@gmail.com> wrote:
>
> On Mon, Jan 11, 2021 at 4:33 PM Patrick Oppenlander
> <patrick.oppenlander@gmail.com> wrote:
> >
> >
> > I've attached a patch which should apply the current tip of the musl-cross-make
> > tree.
> >
>
> The musl patch included is a bit overly pessimistic -- the crash only
> occurs for armv7m so the #if test should probably be narrowed down a
> bit.
>
> I also forgot to mention that I'll provide documentation updates if
> you are happy to go ahead in this direction.
>

A couple more issues:

* There's some missing symlinks (cc, c++, cpp).
* The installed toolchain is missing a stdatomic.h.

I'm looking into stdatomic but haven't managed to get anywhere yet.

Patrick

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-12  1:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11  5:33 [musl] [PATCH] llvm/clang support for musl-cross-make Patrick Oppenlander
2021-01-11 21:23 ` [musl] " Patrick Oppenlander
2021-01-12  1:26   ` 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