Merge branch '14-wasm-libcxx' into '14'

More WebAssembly (wasm32/wasm64) work, including libc++/libc++abi for wasm32-wasi

See merge request pkg-llvm-team/llvm-toolchain!103
This commit is contained in:
Sylvestre Ledru 2022-11-19 09:21:48 +00:00
commit 92b5c74ce9
9 changed files with 239 additions and 41 deletions

17
debian/changelog vendored
View File

@ -1,3 +1,20 @@
llvm-toolchain-14 (1:14.0.6-10) UNRELEASED; urgency=medium
* More WebAssembly (wasm32/wasm64) work:
- Update patch wasm-sysroot-usr to stop including /usr/include when
building for the non-OS (unknown) wasm targets, to avoid inadvertently
including the host's (glibc) headers.
- Re-enable builds on all architectures, previously disabled for
arm64 armel mips64el mipsel ppc64el armhf in 1:14.0.6-4, due to an FTBFS
related to the /usr/include issue above.
- Update patch wasm-sysroot-usr to adjust system include paths for C++
headers as well.
- Build libc++ and libc++abi for wasm32-wasi, generating two new binary
packages, and introducing a build dependency on wasi-libc.
- Misc code organization fixes to debian/rules.
-- Faidon Liambotis <paravoid@debian.org> Fri, 18 Nov 2022 08:21:02 +0200
llvm-toolchain-14 (1:14.0.6-9) unstable; urgency=medium
* Disable the MLIR testsuite run because of a freeze

43
debian/control vendored
View File

@ -24,6 +24,7 @@ Build-Depends: debhelper (>= 10.0), cmake, ninja-build,
libpfm4-dev [linux-any], python3-setuptools, libz3-dev,
llvm-spirv-14 [ amd64 arm64 armel armhf mips64el mipsel ppc64el s390x ] <!stage1> | hello [!i386],
spirv-tools [ linux-any ] | hello [ !i386],
wasi-libc,
libcurl4-dev,
libgrpc++-dev [amd64 arm64 armel armhf mips64el mipsel ppc64 ppc64el powerpc riscv64 s390x],
protobuf-compiler-grpc [amd64 arm64 armel armhf mips64el mipsel ppc64 ppc64el powerpc riscv64 s390x],
@ -648,6 +649,29 @@ Description: LLVM C++ Standard library (development files)
as exception objects, rtti and memory allocation.
* Extensive unit tests.
Package: libc++-14-dev-wasm32
Section: libdevel
Architecture: all
Multi-Arch: foreign
Depends: wasi-libc, libc++abi-14-dev-wasm32, ${misc:Depends}
Provides: libc++-x.y-dev-wasm32
Conflicts: libc++-x.y-dev-wasm32
Replaces: libc++-x.y-dev-wasm32
Description: LLVM C++ Standard library (WASI)
libc++ is another implementation of the C++ standard library
.
Features and Goals
.
* Correctness as defined by the C++ standards.
* Fast execution.
* Minimal memory use.
* Fast compile times.
* ABI compatibility with gcc's libstdc++ for some low-level features such
as exception objects, rtti and memory allocation.
* Extensive unit tests.
.
This package provides a version for the 32-bit WebAssembly System Interface.
# ------------- libcxxabi -------------
Package: libc++abi1-14
@ -687,6 +711,25 @@ Description: LLVM low level support for a standard C++ library (development file
* Correctness as defined by the C++ standards.
* Provide a portable sublayer to ease the porting of libc++
Package: libc++abi-14-dev-wasm32
Section: libdevel
Architecture: all
Multi-Arch: foreign
Depends: wasi-libc, ${misc:Depends}
Provides: libc++abi-x.y-dev-wasm32
Conflicts: libc++abi-x.y-dev-wasm32
Replaces: libc++abi-x.y-dev-wasm32
Description: LLVM low level support for a standard C++ library (WASI)
libc++abi is another implementation of low level support for a standard C++
library.
.
Features and Goals
.
* Correctness as defined by the C++ standards.
* Provide a portable sublayer to ease the porting of libc++
.
This package provides a version for the 32-bit WebAssembly System Interface.
# ------------- libclc -------------
Package: libclc-14

View File

@ -0,0 +1,3 @@
usr/lib/llvm-@LLVM_VERSION@/lib/wasm32-wasi/libc++.a
usr/lib/llvm-@LLVM_VERSION@/include/wasm32-wasi/c++/
usr/lib/llvm-@LLVM_VERSION@/include/wasm32-wasi/c++/v1/

2
debian/libc++-X.Y-dev-wasm32.links.in vendored Normal file
View File

@ -0,0 +1,2 @@
usr/lib/llvm-@LLVM_VERSION@/lib/wasm32-wasi/libc++.a /usr/lib/wasm32-wasi/libc++.a
usr/lib/llvm-@LLVM_VERSION@/include/wasm32-wasi/c++/v1 /usr/include/wasm32-wasi/c++/v1

View File

@ -0,0 +1 @@
usr/lib/llvm-@LLVM_VERSION@/lib/wasm32-wasi/libc++abi.a

View File

@ -0,0 +1 @@
usr/lib/llvm-@LLVM_VERSION@/lib/wasm32-wasi/libc++abi.a /usr/lib/wasm32-wasi/libc++abi.a

View File

@ -27,21 +27,54 @@ Index: llvm-toolchain-14-14.0.6/clang/lib/Driver/ToolChains/WebAssembly.cpp
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
SmallString<128> P(D.ResourceDir);
@@ -421,10 +423,10 @@ void WebAssembly::AddClangSystemIncludeA
@@ -419,27 +421,39 @@ void WebAssembly::AddClangSystemIncludeA
return;
}
+ // add the multiarch path on e.g. wasm32-wasi
if (getTriple().getOS() != llvm::Triple::UnknownOS) {
const std::string MultiarchTriple =
- getMultiarchTriple(D, getTriple(), D.SysRoot);
- addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
+ getMultiarchTriple(D, getTriple(), SysRoot);
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/local/include/" + MultiarchTriple);
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/local/include");
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include/" + MultiarchTriple);
}
- addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
+
+ // also add the non-multiarch path, only on a known OS (as above), or when
+ // a sysroot is given, for backwards compatibility with the original driver
+ if (getTriple().getOS() != llvm::Triple::UnknownOS ||
+ !getDriver().SysRoot.empty())
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
}
void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
@@ -467,3 +469,15 @@ SanitizerMask WebAssembly::getSupportedS
ArgStringList &CC1Args) const {
+ std::string SysRoot = computeSysRoot();
+
if (!DriverArgs.hasArg(options::OPT_nostdlibinc) &&
!DriverArgs.hasArg(options::OPT_nostdincxx)) {
if (getTriple().getOS() != llvm::Triple::UnknownOS) {
const std::string MultiarchTriple =
- getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
+ getMultiarchTriple(getDriver(), getTriple(), SysRoot);
addSystemInclude(DriverArgs, CC1Args,
- getDriver().SysRoot + "/include/" + MultiarchTriple +
+ SysRoot + "/include/" + MultiarchTriple +
"/c++/v1");
}
- addSystemInclude(DriverArgs, CC1Args,
- getDriver().SysRoot + "/include/c++/v1");
+
+ // don't include the host architecture's headers in the search path
+ if (!getDriver().SysRoot.empty())
+ addSystemInclude(DriverArgs, CC1Args, SysRoot + "/include/c++/v1");
}
}
@@ -467,3 +481,15 @@ SanitizerMask WebAssembly::getSupportedS
Tool *WebAssembly::buildLinker() const {
return new tools::wasm::Linker(*this);
}

View File

@ -1361,22 +1361,34 @@ fi
if dpkg -l|grep -q wasi-libc; then
cat <<EOF > printf.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%s\n", "Hello world!");
int main(int argc, char *argv[]) {
printf("%s\n", "Hello World!");
}
EOF
clang-$VERSION -target wasm32-unknown-wasi -o printf printf.c
# wasi-libc supports only wasm32 right now
clang-$VERSION -target wasm32-wasi -o printf printf.c
file printf &> foo.log
if ! grep -q "WebAssembly" foo.log; then
echo "the generated file isn't a WebAssembly file?"
exit 1
fi
rm -f printf.c printf
cat <<EOF > cout.cpp
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
}
EOF
# libcxx requires wasi-libc, which only exists for wasm32 right now
clang++-$VERSION --target=wasm32-wasi -o cout cout.cpp
file cout &> foo.log
if ! grep -q "WebAssembly" foo.log; then
echo "the generated file isn't a WebAssembly file?"
exit 1
fi
rm -f cout.cpp cout
fi
echo '#include <algorithm>' > foo.cpp
# Fails for now
clang++-$VERSION --target=wasm32-wasi -o foo.o -c foo.cpp||true
echo '
#include <vector>

148
debian/rules vendored
View File

@ -302,12 +302,6 @@ ifeq ($(LIBUNWIND_ENABLE),yes)
endif
endif
COMPILER_RT_WASM_ENABLE=yes
ifneq (,$(filter $(DEB_HOST_ARCH), arm64 armel mips64el mipsel ppc64el armhf))
COMPILER_RT_WASM_ENABLE=no
endif
# Do not install objects
STAGE_ALL_CMAKE_EXTRA += -DMLIR_INSTALL_AGGREGATE_OBJECTS=OFF
@ -715,17 +709,17 @@ debian-libclc-build:
ninja $(NJOBS) $(VERBOSE)
touch $@
debian-rtlib-wasm-build:
ifeq (${COMPILER_RT_WASM_ENABLE},yes)
echo "Using cmake: $(CMAKE_BIN)"
for build in wasm32 wasm64; do \
mkdir -p build-compiler-rt-$$build; \
$(CMAKE_BIN) -B build-compiler-rt-$$build -S compiler-rt/lib/builtins/ \
build-wasm/compiler-rt-%: cpu = $(@:build-wasm/compiler-rt-%=%)
build-wasm/compiler-rt-%:
@echo "Building compiler-rt for $(cpu)"
@echo "Using cmake: $(CMAKE_BIN)"
mkdir -p "$@"
$(CMAKE_BIN) -B "$@" -S compiler-rt/lib/builtins/ \
-G Ninja \
$(SCCACHE_CMAKE) \
-DCMAKE_C_COMPILER_TARGET=$$build-unknown-unknown \
-DCMAKE_CXX_COMPILER_TARGET=$$build-unknown-unknown \
-DCMAKE_ASM_COMPILER_TARGET=$$build-unknown-unknown \
-DCMAKE_C_COMPILER_TARGET=$(cpu)-unknown-unknown \
-DCMAKE_CXX_COMPILER_TARGET=$(cpu)-unknown-unknown \
-DCMAKE_ASM_COMPILER_TARGET=$(cpu)-unknown-unknown \
-DCMAKE_C_COMPILER=$(STAGE_2_BIN_DIR)/clang \
-DCMAKE_CXX_COMPILER=$(STAGE_2_BIN_DIR)/clang++ \
-DCMAKE_C_FLAGS="$(opt_flags) $(STAGE_2_CFLAGS)" \
@ -742,15 +736,95 @@ ifeq (${COMPILER_RT_WASM_ENABLE},yes)
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DCOMPILER_RT_USE_LIBCXX=OFF \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
-DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=$$build-unknown-unknown \
-DCOMPILER_RT_OS_DIR=wasi; \
ninja -C build-compiler-rt-$$build $(NJOBS) $(VERBOSE); \
done
else
echo "Skip on this arch"
endif
touch $@
-DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=$(cpu)-unknown-unknown \
-DCOMPILER_RT_OS_DIR=wasi
ninja -C "$@" $(NJOBS) $(VERBOSE)
build-wasm/libcxx-%-wasi: cpu = $(@:build-wasm/libcxx-%-wasi=%)
build-wasm/libcxx-%-wasi: build-wasm/compiler-rt-%
@echo "Building libcxx for $(cpu)"
@echo "Using cmake: $(CMAKE_BIN)"
# We need a functioning clang, which in turn requires a linker. We
# patch clang to use a versioned wasm-ld (cf. wasm-ld-path.diff), so
# create wasm-ld-$(LLVM_VERSION) in the stage2 bin dir manually.
cp $(STAGE_2_BIN_DIR)/wasm-ld $(STAGE_2_BIN_DIR)/wasm-ld-$(LLVM_VERSION)
# We need a wasm compiler-rt. Depend on the make target that builds it,
# and manually copy it to the stage2 lib dir from there
mkdir -p \
$(STAGE_2_LIB_DIR)/clang/$(LLVM_VERSION_FULL)/lib/wasi/
cp build-wasm/compiler-rt-$(cpu)/lib/wasi/libclang_rt.builtins-$(cpu).a \
$(STAGE_2_LIB_DIR)/clang/$(LLVM_VERSION_FULL)/lib/wasi/
# Notes:
# - Uses $(LDFLAGS) instead of $(STAGE_2_LDFLAGS), because wasm-ld does not
# support --build-id yet. Upstream is working on it, cf. D107662.
# - Pass -fno-stack-protector to disable -fstack-protector-strong that is
# passed by default, as this is not supported yet in WebAssembly, cf.
# https://github.com/WebAssembly/wasi-libc/issues/157
# - Use llvm-ar and llvm-ranlib, as binutils does not currently support
# WebAssembly and creates invalid indexes.
# - Use LLVM_LIBDIR_SUFFIX to install to /usr/lib/wasm32-wasi. To be
# replaced by CMAKE_INSTALL_LIBDIR=lib/$(cpu)-wasi when D130586
# ships.
mkdir -p "$@"
$(CMAKE_BIN) -B "$@" -S runtimes \
-G $(GENERATOR) \
$(SCCACHE_CMAKE) \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DLLVM_COMPILER_CHECKED=ON \
-DCMAKE_C_COMPILER_TARGET=$(cpu)-unknown-wasi \
-DCMAKE_CXX_COMPILER_TARGET=$(cpu)-unknown-wasi \
-DCMAKE_ASM_COMPILER_TARGET=$(cpu)-unknown-wasi \
-DCMAKE_C_COMPILER=$(STAGE_2_BIN_DIR)/clang \
-DCMAKE_CXX_COMPILER=$(STAGE_2_BIN_DIR)/clang++ \
-DCMAKE_AR=$(STAGE_2_BIN_DIR)/llvm-ar \
-DCMAKE_RANLIB=$(STAGE_2_BIN_DIR)/llvm-ranlib \
-DCMAKE_C_FLAGS="$(opt_flags) $(STAGE_2_CFLAGS) -fno-stack-protector" \
-DCMAKE_CXX_FLAGS="$(opt_flags) $(STAGE_2_CXXFLAGS) -fno-stack-protector" \
-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
-DCMAKE_MODULE_LINKER_FLAGS="$(LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
-DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
-DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-$(LLVM_VERSION) \
-DCMAKE_INSTALL_INCLUDEDIR=include/$(cpu)-wasi \
-DLLVM_LIBDIR_SUFFIX=/$(cpu)-wasi \
-DLLVM_CONFIG=$(STAGE_2_BIN_DIR)/llvm-config \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON \
-DLIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_ABI_VERSION=2 \
-DLIBCXX_HAS_MUSL_LIBC:BOOL=ON \
-DLIBCXX_ENABLE_SHARED:BOOL=OFF \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \
-DLIBCXX_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=OFF \
-DLIBCXX_ENABLE_THREADS:BOOL=OFF \
-DLIBCXX_HAS_PTHREAD_API:BOOL=OFF \
-DLIBCXX_HAS_EXTERNAL_THREAD_API:BOOL=OFF \
-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXXABI_ENABLE_SHARED:BOOL=OFF \
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXXABI_SILENT_TERMINATE:BOOL=ON \
-DLIBCXXABI_ENABLE_THREADS:BOOL=OFF \
-DLIBCXXABI_HAS_PTHREAD_API:BOOL=OFF \
-DLIBCXXABI_HAS_EXTERNAL_THREAD_API:BOOL=OFF \
-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF
ninja -C "$@" $(NJOBS) $(VERBOSE)
# Build compiler-rt for wasm32 and wasm64. Build libcxx only for wasm32, as
# libcxx requires wasi-libc, which only exists for wasm32 right now.
debian-wasm-build: \
build-wasm/compiler-rt-wasm32 \
build-wasm/libcxx-wasm32-wasi \
build-wasm/compiler-rt-wasm64
touch $@
sccache-stats:
# If we used sccache, shows stats
@ -762,7 +836,12 @@ sccache-stats:
fi
touch $@
override_dh_auto_build: debian-full-build debian-libfuzzer-build debian-libclc-build debian-rtlib-wasm-build sccache-stats
override_dh_auto_build: \
debian-full-build \
debian-libfuzzer-build \
debian-libclc-build \
debian-wasm-build \
sccache-stats
override_dh_prep: build_doc
dh_prep
@ -901,10 +980,10 @@ endif
$(DEB_INST)/usr/lib/llvm-$(LLVM_VERSION)/build/utils/lit/lit/*/__pycache__/
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C libclc/build install
ifeq (${COMPILER_RT_WASM_ENABLE},yes)
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C build-compiler-rt-wasm32 install
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C build-compiler-rt-wasm64 install
endif
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C build-wasm/compiler-rt-wasm32 install
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C build-wasm/compiler-rt-wasm64 install
DESTDIR=$(DEB_INST) ninja $(VERBOSE) -C build-wasm/libcxx-wasm32-wasi install
# Rename binaries
mkdir -p $(DEB_INST)/usr/bin/
@ -1058,7 +1137,7 @@ ifeq ($(shell dpkg --compare-versions $(shell dpkg-query -W -f '$${Version}' bin
else
# GNU strip doesn't recognize WebAssembly binaries, and actually corrupts them.
# llvm-strip (as of 15.0.2) fails with --strip-debug (but works with --strip-all)
dh_strip -a -v -Xlibclang_rt.builtins-wasm32.a -Xlibclang_rt.builtins-wasm64.a
dh_strip -a -v -Xlibclang_rt.builtins-wasm32.a -Xlibclang_rt.builtins-wasm64.a -Xusr/lib/wasm32-wasi
endif
override_dh_install:
@ -1088,6 +1167,13 @@ override_dh_installdeb:
# Remove some libc++ abi files in the libc++ file. See bug #969274
rm -f $(CURDIR)/debian/libc++-$(LLVM_VERSION)-dev/usr/lib/llvm-$(LLVM_VERSION)/include/c++/__cxxabi_config.h $(CURDIR)/debian/libc++-$(LLVM_VERSION)-dev/usr/lib/llvm-$(LLVM_VERSION)/include/c++/cxxabi.h
mkdir -p $(CURDIR)/debian/libc++abi-$(LLVM_VERSION)-dev-wasm32/usr/lib/llvm-$(LLVM_VERSION)/include/wasm32-wasi/c++/v1
mv $(CURDIR)/debian/libc++-$(LLVM_VERSION)-dev-wasm32/usr/lib/llvm-$(LLVM_VERSION)/include/wasm32-wasi/c++/v1/__cxxabi_config.h \
$(CURDIR)/debian/libc++abi-$(LLVM_VERSION)-dev-wasm32/usr/lib/llvm-$(LLVM_VERSION)/include/wasm32-wasi/c++/v1/__cxxabi_config.h
mv $(CURDIR)/debian/libc++-$(LLVM_VERSION)-dev-wasm32/usr/lib/llvm-$(LLVM_VERSION)/include/wasm32-wasi/c++/v1/cxxabi.h \
$(CURDIR)/debian/libc++abi-$(LLVM_VERSION)-dev-wasm32/usr/lib/llvm-$(LLVM_VERSION)/include/wasm32-wasi/c++/v1/cxxabi.h
# Remove auto generated python pyc
find $(CURDIR)/debian/llvm-$(LLVM_VERSION)-tools/usr/lib/llvm-$(LLVM_VERSION)/ -name '*.pyc' | xargs -r rm -f
@ -1196,7 +1282,7 @@ override_dh_auto_clean:
rm -f $(CURDIR)/clang/tools/clang-format/clang-format-diff-$(LLVM_VERSION)
rm -f $(CURDIR)/clang/tools/clang-format/clang-format-$(LLVM_VERSION).py
rm -rf libclc/build
rm -rf build-compiler-rt-wasm32 build-compiler-rt-wasm64
rm -rf build-wasm
if test -f lld/docs/ld.lld-$(LLVM_VERSION).1; then \
mv lld/docs/ld.lld-$(LLVM_VERSION).1 lld/docs/ld.lld.1; \
fi
@ -1212,4 +1298,4 @@ override_dh_auto_clean:
: # remove extra stamps
rm -f debian-*-build
.PHONY: override_dh_strip preconfigure debian-full-build debian-libfuzzer-build debian-libclc-build debian-rtlib-wasm-build
.PHONY: override_dh_strip preconfigure