diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2024-07-30 09:27:38 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2024-10-17 00:58:44 -0500 |
commit | 595bc02f3080bbf44fa78068e5b56e13821ab6a6 (patch) | |
tree | f935d24387678ff6c85255cf48ac8a0270c272e9 | |
parent | 0f5207bac6c6280ecf6d9910ddfb04f35cec6244 (diff) | |
download | packages-595bc02f3080bbf44fa78068e5b56e13821ab6a6.tar.gz packages-595bc02f3080bbf44fa78068e5b56e13821ab6a6.tar.bz2 packages-595bc02f3080bbf44fa78068e5b56e13821ab6a6.tar.xz packages-595bc02f3080bbf44fa78068e5b56e13821ab6a6.zip |
bootstrap/llvm16: New package
-rw-r--r-- | bootstrap/llvm16/APKBUILD | 256 | ||||
-rw-r--r-- | bootstrap/llvm16/disable-FileSystemTest.CreateDir-perms-assert.patch | 61 | ||||
-rw-r--r-- | bootstrap/llvm16/dwarf-info.patch | 28 | ||||
-rw-r--r-- | bootstrap/llvm16/dyld-elf-ppc32.patch | 24 | ||||
-rw-r--r-- | bootstrap/llvm16/exegesis-mcjit.patch | 348 | ||||
-rw-r--r-- | bootstrap/llvm16/hexagon.patch | 95 | ||||
-rw-r--r-- | bootstrap/llvm16/llvm-fix-build-with-musl-libc.patch | 46 | ||||
-rw-r--r-- | bootstrap/llvm16/macho32.patch | 17 | ||||
-rw-r--r-- | bootstrap/llvm16/musl-ppc64-elfv2.patch | 28 | ||||
-rw-r--r-- | bootstrap/llvm16/python3-test.patch | 8 | ||||
-rw-r--r-- | bootstrap/llvm16/roundeven.patch | 49 |
11 files changed, 960 insertions, 0 deletions
diff --git a/bootstrap/llvm16/APKBUILD b/bootstrap/llvm16/APKBUILD new file mode 100644 index 000000000..2562db7a6 --- /dev/null +++ b/bootstrap/llvm16/APKBUILD @@ -0,0 +1,256 @@ +# Contributor: Travis Tilley <ttilley@gmail.com> +# Contributor: Mitch Tishmack <mitch.tishmack@gmail.com> +# Contributor: Jakub Jirutka <jakub@jirutka.cz> +# Maintainer: A. Wilcox <awilfox@adelielinux.org> +_pkgname=llvm +pkgver=16.0.6 +_majorver=${pkgver%%.*} +pkgname=$_pkgname$_majorver +pkgrel=0 +pkgdesc="Low Level Virtual Machine compiler system, version $_majorver" +url="https://llvm.org/" +arch="all" +options="!checkroot !dbg" +license="NCSA AND (Apache-2.0 WITH LLVM-exception)" +depends="" +depends_dev="$pkgname=$pkgver-r$pkgrel libexecinfo-dev libxml2-dev" +checkdepends="cmd:which" +makedepends="binutils-dev chelf chrpath cmake file libexecinfo-dev libffi-dev + libxml2-dev python3 zlib-dev" +subpackages="$pkgname-static $pkgname-libs $pkgname-dev + $pkgname-test-utils:_test_utils" +source="https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/llvm-project-$pkgver.src.tar.xz + llvm-fix-build-with-musl-libc.patch + disable-FileSystemTest.CreateDir-perms-assert.patch + dyld-elf-ppc32.patch + exegesis-mcjit.patch + hexagon.patch + macho32.patch + musl-ppc64-elfv2.patch + python3-test.patch + roundeven.patch + " +builddir="$srcdir/$_pkgname-project-$pkgver.src/llvm" + +# ARM has few failures in test suite that we don't care about currently and +# also it takes forever to run them on the builder. +case "$CARCH" in + arm*) options="$options !check";; +esac + +# Whether is this package the default (latest) LLVM version. +_default_llvm="no" + +if [ "$_default_llvm" = yes ]; then + provides="llvm=$pkgver-r$pkgrel" + replaces="llvm" +fi + +# NOTE: It seems that there's no (sane) way how to change includedir, sharedir +# etc. separately, just the CMAKE_INSTALL_PREFIX. Standard CMake variables and +# even LLVM-specific variables, that are related to these paths, actually +# don't work (in llvm 3.7). +# +# When building a software that depends on LLVM, utility llvm-config should be +# used to discover where is LLVM installed. It provides options to print +# path of bindir, includedir, and libdir separately, but in its source, all +# these paths are actually hard-coded against INSTALL_PREFIX. We can patch it +# and move paths manually, but I'm really not sure what it may break... +# +# Also note that we should *not* add version suffix to files in llvm bindir! +# It breaks build system of some software that depends on LLVM, because they +# don't expect these files to have a sufix. +# +# So, we install all the LLVM files into /usr/lib/llvm$_majorver. +# BTW, Fedora and Debian do the same thing. +# +_prefix="usr/lib/llvm$_majorver" + +prepare() { + default_prepare + + # https://bugs.llvm.org//show_bug.cgi?id=31870 + rm test/tools/llvm-symbolizer/print_context.c + + case $CARCH in + pmmx|x86|ppc|armhf|armv7) + # Appears to not work when building 32-bit code on 64-bit host. + rm test/tools/llvm-size/radix.test;; + esac + + # appears to be an issue on musl and glibc, but only fails on musl: + # https://github.com/NixOS/nixpkgs/blob/bb7e9e46/pkgs/development/compilers/llvm/8/llvm.nix#L74 + rm -f test/CodeGen/AArch64/wineh4.mir + + #1053 + rm -fr \ + test/tools/UpdateTestChecks \ + test/ExecutionEngine/MCJIT/load-object-a.ll \ + ; +} + +build() { + # Auto-detect it by guessing either. + ffi_include_dir="$(pkg-config --cflags-only-I libffi | sed 's|^-I||g')" + + # Disabled m68k because the endianness fix from llvm18 doesn't work. + cmake -G "Unix Makefiles" -Wno-dev \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/$_prefix \ + -DCMAKE_VERBOSE_MAKEFILE=NO \ + -DFFI_INCLUDE_DIR="$ffi_include_dir" \ + -DLLVM_BINUTILS_INCDIR=/usr/include \ + -DLLVM_BUILD_DOCS=OFF \ + -DLLVM_BUILD_EXAMPLES=OFF \ + -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON \ + -DLLVM_BUILD_LLVM_DYLIB=ON \ + -DLLVM_BUILD_TESTS=ON \ + -DLLVM_DEFAULT_TARGET_TRIPLE="$CBUILD" \ + -DLLVM_ENABLE_ASSERTIONS=OFF \ + -DLLVM_ENABLE_FFI=ON \ + -DLLVM_ENABLE_LIBCXX=OFF \ + -DLLVM_ENABLE_PIC=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_ENABLE_SPHINX=OFF \ + -DLLVM_ENABLE_TERMINFO=ON \ + -DLLVM_ENABLE_ZLIB=ON \ + -DLLVM_HOST_TRIPLE="$CHOST" \ + -DLLVM_INCLUDE_BENCHMARKS=OFF \ + -DLLVM_INCLUDE_EXAMPLES=OFF \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_LINK_LLVM_DYLIB=ON \ + -DLLVM_TARGETS_TO_BUILD='AArch64;AMDGPU;ARM;BPF;Hexagon;Lanai;Mips;MSP430;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86;XCore' \ + -Bbuild . + + make -C build llvm-tblgen + make -C build + + python3 utils/lit/setup.py build +} + +check() { + make -C build check-llvm +} + +package() { + make DESTDIR="$pkgdir" -C build install + + cd "$pkgdir"/$_prefix + + # Remove RPATHs. + file lib/*.so bin/* \ + | awk -F: '$2~/ELF/{print $1}' \ + | xargs -r chrpath -d + + # Thread 3 requires a lot of stack space to LTO when targeting ARM. + # Note that this occurs even when crossing (on a ppc64 host). + chelf -s 1048576 bin/llvm-lto2 + + # Symlink files from /usr/lib/llvm*/bin to /usr/bin. + mkdir -p "$pkgdir"/usr/bin + for full_name in bin/*; do + bin_name=${full_name##*/} + # If this package provides=llvm (i.e. it's the default/latest + # llvm package), omit version infix/suffix. + if [ "$_default_llvm" = yes ]; then + link_name=$bin_name + # ..otherwise, add version infix/suffix to the executable name. + else case "$bin_name" in + llvm-*) link_name="llvm$_majorver-${bin_name#llvm-}";; + *) link_name="$bin_name$_majorver";; + esac + fi + case "$name" in + FileCheck | obj2yaml | yaml2obj) continue;; + esac + ln -s ../lib/llvm$_majorver/bin/$bin_name "$pkgdir"/usr/bin/$link_name + done + + # Move /usr/lib/$pkgname/include/ into /usr/include/$pkgname/ + # and symlink it back. + mkdir -p "$pkgdir"/usr/include/$pkgname + mv include/* "$pkgdir"/usr/include/$pkgname/ + rmdir include + ln -s ../../include/$pkgname include + + ln -s "$pkgdir"/usr/lib/cmake/llvm ../$pkgname/lib/cmake/llvm +} + +static() { + pkgdesc="LLVM $_majorver static libraries" + _common_subpkg + + mkdir -p "$subpkgdir"/$_prefix/lib + mv "$pkgdir"/$_prefix/lib/*.a "$subpkgdir"/$_prefix/lib/ + strip -d "$subpkgdir"/$_prefix/lib/*.a +} + +libs() { + pkgdesc="LLVM $_majorver runtime library" + main_soname="libLLVM-$_majorver.so" + ver_soname="libLLVM-$pkgver.so" + _common_subpkg + + # libLLVM should be in /usr/lib. This is needed for binaries that are + # dynamically linked with libLLVM, so they can find it on default path. + mkdir -p "$subpkgdir"/usr/lib + mv "$pkgdir"/$_prefix/lib/$main_soname "$subpkgdir"/usr/lib/ + ln -s $main_soname "$subpkgdir"/usr/lib/$ver_soname + strip "$subpkgdir"/usr/lib/$ver_soname #797 + + # And also symlink it back to the LLVM prefix. + mkdir -p "$subpkgdir"/$_prefix/lib + ln -s ../../$main_soname "$subpkgdir"/$_prefix/lib/$main_soname + ln -s ../../$main_soname "$subpkgdir"/$_prefix/lib/$ver_soname +} + +dev() { + _common_subpkg + default_dev + + mkdir -p "$subpkgdir"/$_prefix/bin + + mv "$pkgdir"/$_prefix/lib "$subpkgdir"/$_prefix/ + mv "$pkgdir"/$_prefix/include "$subpkgdir"/$_prefix/ + + mv "$pkgdir"/$_prefix/bin/llvm-config "$subpkgdir"/$_prefix/bin/ +} + +_test_utils() { + pkgdesc="LLVM $_majorver utilities for executing LLVM and Clang style test suites" + depends="python3" + _common_subpkg + replaces="" + + litver="$(python3 "$builddir"/utils/lit/setup.py --version 2>/dev/null \ + | sed 's/\.dev.*$//')" + test -n "$litver" || return 1 + provides="$provides lit=$litver-r$pkgrel" + + cd "$builddir"/build + + install -D -m 755 bin/FileCheck "$subpkgdir"/$_prefix/bin/FileCheck + install -D -m 755 bin/count "$subpkgdir"/$_prefix/bin/count + install -D -m 755 bin/not "$subpkgdir"/$_prefix/bin/not + + python3 ../utils/lit/setup.py install --prefix=/usr --root="$subpkgdir" + ln -s ../../../bin/lit "$subpkgdir"/$_prefix/bin/lit +} + +_common_subpkg() { + if [ "$_default_llvm" = yes ]; then + replaces="llvm${subpkgname#$pkgname}" + provides="$replaces=$pkgver-r$pkgrel" + fi +} + +sha512sums="89a67ebfbbc764cc456e8825ecfa90707741f8835b1b2adffae0b227ab1fe5ca9cce75b0efaffc9ca8431cae528dc54fd838867a56a2b645344d9e82d19ab1b7 llvm-project-16.0.6.src.tar.xz +e6fec46f3a1183774e4a47b81f3287adc5aa28ebdd52f614c1111fb157cd3137d1b86e04ca76a92b192c900eb5fa4c44f0c00984da14f0a9bb3ee8e488773e00 llvm-fix-build-with-musl-libc.patch +8e694af50a9f1f8a3dcf7c0e1ce1165237011767e3514271984877882962e492057efd16f0e6e303ee534a48c039c8ec00ed8a34eb9e9826b0324100292695f9 disable-FileSystemTest.CreateDir-perms-assert.patch +962ea62f96927f397a234c8770fd5a41d5c8ef528de56da6da76908369ee0e9faca2fcba46b3957a928b8138b46c7c0d8c5f353088009e1921f9c3cfffd96081 dyld-elf-ppc32.patch +5f24f99e31b8e0d1d7a7253be028df55f3524ff600c037404a4870ed22c02467f378b222d7fdd3d7af5b1ef006a90ec0c32c44122771e2ea8763eb62dcfca9dc exegesis-mcjit.patch +807587a0c897d47a01a846c5c4f7cbf1f2d16437a163b66ee2381a7147e9d04b0141b2c76d022db61903d0d2841ddb267ba98c66c9e41501ca41837659743df8 hexagon.patch +de9791cc476817782b553c4edab696132da4ed2b9a3d80dbf1b85b7dc7a8c5e4caf14f2f26e33c27cd80a91b36709d3b24caea910c0a6315ffbb297cb748468d macho32.patch +bec1fe4761dae33a8012a54b7bbdd179cac82febcd46ace1844772c06f207661c903f05fcb7a5ebbbece3e33a88b20a5d9b31b40e8a8cd5c626aec04cb6735be musl-ppc64-elfv2.patch +89ef5fbab039b017a5652656adf17b680525f1c5dd0b1afc8034fe0b34a2ca196d87640f54cc826356cfcd88c6e5f10754b7e38f04ca49ede4f3864080b787bd python3-test.patch +5e0868a96ecd3344a4badb3c23e7e9060a96e3fc7cb4a092febca93eff8c040839041c7a3c8a29955541b585081f84ab8c1ced26198ac93ad2d9db616faf1088 roundeven.patch" diff --git a/bootstrap/llvm16/disable-FileSystemTest.CreateDir-perms-assert.patch b/bootstrap/llvm16/disable-FileSystemTest.CreateDir-perms-assert.patch new file mode 100644 index 000000000..a1d8fc28a --- /dev/null +++ b/bootstrap/llvm16/disable-FileSystemTest.CreateDir-perms-assert.patch @@ -0,0 +1,61 @@ +Do not assert permissions of file created in /tmp directory. + +This assertion fails, probably due to some specific setup of /tmp +on build servers. + + FAIL: LLVM-Unit :: Support/SupportTests/FileSystemTest.CreateDir (1293 of 17222) + ******************** TEST 'LLVM-Unit :: Support/SupportTests/FileSystemTest.CreateDir' FAILED ******************** + Note: Google Test filter = FileSystemTest.CreateDir + [==========] Running 1 test from 1 test case. + [----------] Global test environment set-up. + [----------] 1 test from FileSystemTest + [ RUN ] FileSystemTest.CreateDir + /home/buildozer/aports/testing/llvm3.9/src/llvm-3.9.1.src/unittests/Support/Path.cpp:591: Failure + Value of: fs::perms::owner_read | fs::perms::owner_exe + Actual: 320 + Expected: Status.permissions() & fs::perms::all_all + Which is: 448 + +--- a/unittests/Support/Path.cpp ++++ b/unittests/Support/Path.cpp +@@ -994,23 +994,23 @@ + ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo")); + + #ifdef LLVM_ON_UNIX +- // Set a 0000 umask so that we can test our directory permissions. +- mode_t OldUmask = ::umask(0000); +- +- fs::file_status Status; +- ASSERT_NO_ERROR( +- fs::create_directory(Twine(TestDirectory) + "baz500", false, +- fs::perms::owner_read | fs::perms::owner_exe)); +- ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz500", Status)); +- ASSERT_EQ(Status.permissions() & fs::perms::all_all, +- fs::perms::owner_read | fs::perms::owner_exe); +- ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "baz777", false, +- fs::perms::all_all)); +- ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz777", Status)); +- ASSERT_EQ(Status.permissions() & fs::perms::all_all, fs::perms::all_all); +- +- // Restore umask to be safe. +- ::umask(OldUmask); ++// // Set a 0000 umask so that we can test our directory permissions. ++// mode_t OldUmask = ::umask(0000); ++// ++// fs::file_status Status; ++// ASSERT_NO_ERROR( ++// fs::create_directory(Twine(TestDirectory) + "baz500", false, ++// fs::perms::owner_read | fs::perms::owner_exe)); ++// ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz500", Status)); ++// ASSERT_EQ(Status.permissions() & fs::perms::all_all, ++// fs::perms::owner_read | fs::perms::owner_exe); ++// ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "baz777", false, ++// fs::perms::all_all)); ++// ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz777", Status)); ++// ASSERT_EQ(Status.permissions() & fs::perms::all_all, fs::perms::all_all); ++// ++// // Restore umask to be safe. ++// ::umask(OldUmask); + #endif + + #ifdef _WIN32 diff --git a/bootstrap/llvm16/dwarf-info.patch b/bootstrap/llvm16/dwarf-info.patch new file mode 100644 index 000000000..9357c6519 --- /dev/null +++ b/bootstrap/llvm16/dwarf-info.patch @@ -0,0 +1,28 @@ +Author: A. Wilcox <awilfox@adelielinux.org> + +This isn't the proper fix, but debugging the LLVM formatter is a bit +above my paygrade at the moment. + +The issue shows up in the DWARF X86 test on ppc and armv7: + +error: Simplified template DW_AT_name could not be reconstituted: + original: f3<char, '\x00', '\x01', '\x06', '\a', '\r', '\x0e', '\x1f', ' ', '!', '\x7f', '\x80'> + reconstituted: f3<char, '\x00', '\x00', '\x00', '\a', '\r', '\x00', '\x00', ' ', '!', '\x00', '\x00'> + +With this patch, this error does not occur. Debugging shows that the +llvm::format overload called in the error case is <long long>, so I +think it is having an issue converting a 64-bit value on platforms +where char is default-unsigned. + +(pmmx does not show this issue, and has signed char.) +--- llvm-14.0.6.src/lib/DebugInfo/DWARF/DWARFDie.cpp.old 2022-06-22 16:46:24.000000000 +0000 ++++ llvm-14.0.6.src/lib/DebugInfo/DWARF/DWARFDie.cpp 2022-11-28 10:32:05.573627744 +0000 +@@ -506,7 +506,7 @@ + OS << (char)Val; + OS << "'"; + } else if (Val < 256) +- OS << to_string(llvm::format("'\\x%02x'", Val)); ++ OS << to_string(llvm::format("'\\x%02x'", (unsigned char)Val)); + else if (Val <= 0xFFFF) + OS << to_string(llvm::format("'\\u%04x'", Val)); + else diff --git a/bootstrap/llvm16/dyld-elf-ppc32.patch b/bootstrap/llvm16/dyld-elf-ppc32.patch new file mode 100644 index 000000000..42f0abb53 --- /dev/null +++ b/bootstrap/llvm16/dyld-elf-ppc32.patch @@ -0,0 +1,24 @@ +Author: A. Wilcox <awilfox@adelielinux.org> +Upstream-Status: Pending + +This implements the R_PPC_REL32 relocation type, which is needed for the +OrcJIT to work properly on 32-bit PowerPC. + +Needs more tests before submitting upstream, but seems to DTRT. + +--- llvm-14.0.6.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp.old 2022-06-22 16:46:24.000000000 +0000 ++++ llvm-14.0.6.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp 2022-11-28 06:33:12.239921624 +0000 +@@ -825,6 +825,13 @@ + case ELF::R_PPC_ADDR16_HA: + writeInt16BE(LocalAddress, applyPPCha(Value + Addend)); + break; ++ case ELF::R_PPC_REL32: ++ uint32_t FinalAddress = Section.getLoadAddressWithOffset(Offset); ++ int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend); ++ if (SignExtend64<32>(delta) != delta) ++ llvm_unreachable("Relocation R_PPC_REL32 overflow"); ++ writeInt32BE(LocalAddress, delta); ++ break; + } + } + diff --git a/bootstrap/llvm16/exegesis-mcjit.patch b/bootstrap/llvm16/exegesis-mcjit.patch new file mode 100644 index 000000000..7363965c2 --- /dev/null +++ b/bootstrap/llvm16/exegesis-mcjit.patch @@ -0,0 +1,348 @@ +This is a backport from LLVM 17 that fixes a test failure observed on +ppc64: + +******************** +FAIL: LLVM :: tools/llvm-exegesis/PowerPC/latency-by-opcode-name.s (216 of 47688) +******************** TEST 'LLVM :: tools/llvm-exegesis/PowerPC/latency-by-opcode-name.s' FAILED ******************** +PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. +Stack dump: +0. Program arguments: /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/build/bin/llvm-exegesis -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 --benchmark-phase=assemble-measured-code -mode=latency -opcode-name=ADD8 + #0 0x0000000141a994d0 llvm::sys::RunSignalHandlers() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/Support/Signals.cpp:103:22 + #1 0x0000000141a994d0 SignalHandler(int) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/Support/Unix/Signals.inc:402:31 + #2 0x00003fff89552444 0x444 __register_frame_info_bases + #3 0x00003fff89552444 + #4 0x00003fff89552444 __register_frame_info (+0x444) + #5 0xaaaaaaaaaaaaaaab + #6 0x00003fff8907b700 __register_frame (/usr/lib/libgcc_s.so.1+0x12700) + #7 0x00003fff8907b760 llvm::RTDyldMemoryManager::registerEHFramesInProcess(unsigned char*, unsigned long) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp:119:19 + #8 0x00003fff8907b760 llvm::RTDyldMemoryManager::registerEHFrames(unsigned char*, unsigned long, unsigned long) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp:131:28 + #9 0x00003fff8907b7c0 llvm::RuntimeDyldELF::registerEHFrames() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:227:28 +#10 0x0000000142e9d1b0 llvm::RuntimeDyld::registerEHFrames() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp:1435:27 +#11 0x0000000142eb4258 llvm::MCJIT::finalizeLoadedModules() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp:251:24 +#12 0x0000000142ea2154 __gthread_mutex_unlock /usr/include/c++/13.3.0/powerpc64-foxkit-linux-musl/bits/gthr-default.h:779:43 +#13 0x0000000142ea2154 __gthread_recursive_mutex_unlock /usr/include/c++/13.3.0/powerpc64-foxkit-linux-musl/bits/gthr-default.h:832:33 +#14 0x0000000142ea2154 std::recursive_mutex::unlock() /usr/include/c++/13.3.0/mutex:139:39 +#15 0x0000000142ea2154 llvm::sys::SmartMutex<false>::unlock() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/include/llvm/Support/Mutex.h:47:22 +#16 0x0000000142ea2154 std::lock_guard<llvm::sys::SmartMutex<false>>::~lock_guard() /usr/include/c++/13.3.0/bits/std_mutex.h:255:25 +#17 0x0000000142ea2154 llvm::MCJIT::getFunctionAddress(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp:410:1 +#18 0x0000000142b6f948 llvm::exegesis::ExecutableFunction::ExecutableFunction(std::unique_ptr<llvm::LLVMTargetMachine, std::default_delete<llvm::LLVMTargetMachine>>, llvm::object::OwningBinary<llvm::object::ObjectFile>&&) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/tools/llvm-exegesis/lib/Assembler.cpp:319:66 +#19 0x0000000142b73a18 llvm::exegesis::BenchmarkRunner::getRunnableConfiguration(llvm::exegesis::BenchmarkCode const&, unsigned int, unsigned int, llvm::exegesis::SnippetRepetitor const&) const /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp:181:62 +#20 0x0000000141af099c llvm::exegesis::runBenchmarkConfigurations(llvm::exegesis::LLVMState const&, llvm::ArrayRef<llvm::exegesis::BenchmarkCode>, llvm::ArrayRef<std::unique_ptr<llvm::exegesis::SnippetRepetitor const, std::default_delete<llvm::exegesis::SnippetRepetitor const>>>, llvm::exegesis::BenchmarkRunner const&) /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/tools/llvm-exegesis/llvm-exegesis.cpp:376:58 +#21 0x0000000141aca060 llvm::exegesis::benchmarkMain() /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/tools/llvm-exegesis/llvm-exegesis.cpp:506:30 +#22 0x000000013fbe7144 main /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/tools/llvm-exegesis/llvm-exegesis.cpp:660:1 +#23 0x000000013fbea0a8 libc_start_main_stage2 /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:95:2 +#24 0x000000013fb105ac __libc_start_main /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:86:9 +#25 0x00003fff89494038 _start_c /usr/src/packages/system/musl/src/musl-1.2.3/crt/crt1.c:18:2 +#26 0x00003fff894940b4 _start (/lib/ld-musl-powerpc64.so.1+0x220b4) +Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): +0 llvm-exegesis 0x0000000141a994d0 +1 0x00003fff89552444 __kernel_sigtramp_rt64 + 0 +2 0xaaaaaaaaaaaaaaab __kernel_sigtramp_rt64 + 12297759015719765607 +3 libgcc_s.so.1 0x00003fff8907b700 __register_frame_info_bases + 128 +4 libgcc_s.so.1 0x00003fff8907b760 __register_frame_info + 32 +5 libgcc_s.so.1 0x00003fff8907b7c0 __register_frame + 64 +6 llvm-exegesis 0x0000000142e9d1b0 +7 llvm-exegesis 0x0000000142eb4258 +8 llvm-exegesis 0x0000000142ea2154 +9 llvm-exegesis 0x0000000142b6f948 +10 llvm-exegesis 0x0000000142b73a18 +11 llvm-exegesis 0x0000000141af099c +12 llvm-exegesis 0x0000000141aca060 +13 llvm-exegesis 0x000000013fbe7144 +14 llvm-exegesis 0x000000013fbea0a8 +15 llvm-exegesis 0x000000013fb105ac +16 ld-musl-powerpc64.so.1 0x00003fff89494038 +17 ld-musl-powerpc64.so.1 0x00003fff894940b4 __libc_start_main + 100 +18 llvm-exegesis 0x000000013fbdcf78 +19 llvm-exegesis 0x000000013fbdcf20 +FileCheck error: '<stdin>' is empty. +FileCheck command line: /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/build/bin/FileCheck /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/test/tools/llvm-exegesis/PowerPC/latency-by-opcode-name.s + +Tracing with a debug-build libgcc_s yields: + +Program received signal SIGSEGV, Segmentation fault. +classify_object_over_fdes (ob=0x3ffff7904700, this_fde=0x400007ae4004, range=0x3fffffffd700) at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:732 +732 for (; ! last_fde (ob, this_fde); this_fde = next_fde (this_fde)) +(gdb) bt +#0 classify_object_over_fdes (ob=0x3ffff7904700, this_fde=0x400007ae4004, range=0x3fffffffd700) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:732 +#1 0x00003ffff7b47700 in register_pc_range_for_object (ob=0x3ffff7904700, begin=<optimized out>) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:118 +#2 __register_frame_info_bases (dbase=<optimized out>, tbase=<optimized out>, ob=0x3ffff7904700, begin=<optimized out>) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:144 +#3 __register_frame_info_bases (begin=<optimized out>, ob=0x3ffff7904700, tbase=<optimized out>, dbase=<optimized out>) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:126 +#4 0x00003ffff7b47760 in __register_frame_info (begin=<optimized out>, ob=<optimized out>) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:159 +#5 0x00003ffff7b477c0 in __register_frame (begin=0x3ffff7ae4000) + at /home/awilcox/Code/awilfox/gcc-next/system/gcc/src/gcc-13.3.0/libgcc/unwind-dw2-fde.c:172 +#6 0x00000001038da4f0 in llvm::RTDyldMemoryManager::registerEHFramesInProcess (Size=<optimized out>, Addr=<optimized out>) + at /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp:119 +#7 llvm::RTDyldMemoryManager::registerEHFrames (this=0x3ffff78b1700, Addr=<optimized out>, LoadAddr=<optimized out>, + Size=<optimized out>) + at /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp:131 +#8 0x00000001038f1598 in llvm::RuntimeDyldELF::registerEHFrames (this=0x3ffff7b0e550) + at /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:227 +#9 0x00000001038df494 in llvm::RuntimeDyld::registerEHFrames (this=<optimized out>) + at /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp:1435 +#10 0x00000001035acc88 in llvm::MCJIT::finalizeLoadedModules (this=0x3ffff7aef0b0) + at /home/awilcox/Code/awilfox/rust-next/bootstrap/llvm16/src/llvm-project-16.0.6.src/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp:251 + +The reason is because it is trying to interpret a little-endian FDE as a +native (big-endian) one and failing. This was noted upstream and fixed +in the LLVM 17 branch but it was never backported to a 16 release. + +From 27f37db76a79e746561ad2545ff6ccf0d50cc38c Mon Sep 17 00:00:00 2001 +From: Pavel Kosov <kpdev42@gmail.com> +Date: Thu, 8 Jun 2023 19:14:00 +0300 +Subject: [PATCH] [llvm-exegesis] Use MCJIT only for execution + +Initially, llvm-exegesis was generating the benchmark code for the +host CPU to execute it inside its own process. Thus, MCJIT was reused +for fetching function's bytes to fill the assembled_snippet field in +the benchmark report. + +Later, the --mtriple and --benchmark-phase command line options were +introduced that are handy for testing snippet generation even if +snippet execution is not possible. In that setup, MCJIT is asked to +parse an object file for a foreign CPU or operating system that is +probably not guaranteed to succeed and was actually observed to fail +in https://reviews.llvm.org/D145763. + +This commit implements a much simplified function's code fetching, +assuming the benchmark function is the only function in the object file +and it spans across the entire text section (note that MCJIT-based code +has more or less the same assumption - see TrackingSectionMemoryManager +class). + +~~~ + +Huawei RRI, OS Lab + +Reviewed By: courbet + +Differential Revision: https://reviews.llvm.org/D148921 +--- + .../AArch64/print-assembled-snippet.s | 31 +++++++++++++++++ + .../Mips/print-assembled-snippet.s | 23 +++++++++++++ + .../PowerPC/print-assembled-snippet.s | 15 ++++++++ + .../X86/print-assembled-snippet.s | 32 +++++++++++++++++ + llvm/tools/llvm-exegesis/lib/Assembler.cpp | 34 +++++++++++++++++++ + llvm/tools/llvm-exegesis/lib/Assembler.h | 4 +++ + .../llvm-exegesis/lib/BenchmarkRunner.cpp | 8 ++--- + 7 files changed, 143 insertions(+), 4 deletions(-) + create mode 100644 llvm/test/tools/llvm-exegesis/AArch64/print-assembled-snippet.s + create mode 100644 llvm/test/tools/llvm-exegesis/Mips/print-assembled-snippet.s + create mode 100644 llvm/test/tools/llvm-exegesis/PowerPC/print-assembled-snippet.s + create mode 100644 llvm/test/tools/llvm-exegesis/X86/print-assembled-snippet.s + +diff --git a/llvm/test/tools/llvm-exegesis/AArch64/print-assembled-snippet.s b/llvm/test/tools/llvm-exegesis/AArch64/print-assembled-snippet.s +new file mode 100644 +index 0000000000000..e8b312d7a6ae9 +--- /dev/null ++++ llvm/test/tools/llvm-exegesis/AArch64/print-assembled-snippet.s +@@ -0,0 +1,31 @@ ++# Check that "assembled_snippet" is fetched correctly from object file. ++# Feel free to update the snippet in this test if the code generated by the ++# snippet repetitor was changed intentionally and it is still fetched correctly. ++ ++# RUN: llvm-exegesis --mtriple=aarch64-linux-gnu --mcpu=generic --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-LINUX ++ ++# RUN: llvm-exegesis --mtriple=aarch64-windows-gnu --mcpu=generic --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-WINDOWS-GNU ++ ++# RUN: llvm-exegesis --mtriple=aarch64-windows-msvc --mcpu=generic --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-WINDOWS-MSVC ++ ++# LLVM-EXEGESIS-DEFREG X0 0 ++# LLVM-EXEGESIS-DEFREG X1 0 ++add x0, x0, x1 ++ ++# CHECK-LINUX: cpu_name: generic ++# CHECK-LINUX: llvm_triple: aarch64-unknown-linux-gnu ++# CHECK-LINUX: assembled_snippet: 000080D2010080D20000018B0000018B0000018B0000018BC0035FD6{{$}} ++ ++# CHECK-WINDOWS-GNU: cpu_name: generic ++# CHECK-WINDOWS-GNU: llvm_triple: aarch64-unknown-windows-gnu ++# CHECK-WINDOWS-GNU: assembled_snippet: 000080D2010080D20000018B0000018B0000018B0000018BC0035FD6{{$}} ++ ++# CHECK-WINDOWS-MSVC: cpu_name: generic ++# CHECK-WINDOWS-MSVC: llvm_triple: aarch64-unknown-windows-msvc ++# CHECK-WINDOWS-MSVC: assembled_snippet: 000080D2010080D20000018B0000018B0000018B0000018BC0035FD6{{$}} +diff --git a/llvm/test/tools/llvm-exegesis/Mips/print-assembled-snippet.s b/llvm/test/tools/llvm-exegesis/Mips/print-assembled-snippet.s +new file mode 100644 +index 0000000000000..f0844c4145a2b +--- /dev/null ++++ llvm/test/tools/llvm-exegesis/Mips/print-assembled-snippet.s +@@ -0,0 +1,23 @@ ++# Check that "assembled_snippet" is fetched correctly from object file. ++# Feel free to update the snippet in this test if the code generated by the ++# snippet repetitor was changed intentionally and it is still fetched correctly. ++ ++# RUN: llvm-exegesis --mtriple=mips-linux-gnu --mcpu=generic --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-LINUX ++ ++# RUN: llvm-exegesis --mtriple=mips64-linux-gnu --mcpu=generic --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-LINUX-64 ++ ++# LLVM-EXEGESIS-DEFREG A0 0 ++# LLVM-EXEGESIS-DEFREG A1 0 ++add $2, $5, $4 ++ ++# CHECK-LINUX: cpu_name: generic ++# CHECK-LINUX: llvm_triple: mips-unknown-linux-gnu ++# CHECK-LINUX: assembled_snippet: 340400003405000000A4102000A4102000A4102000A4102003E00008{{$}} ++ ++# CHECK-LINUX-64: cpu_name: generic ++# CHECK-LINUX-64: llvm_triple: mips64-unknown-linux-gnu ++# CHECK-LINUX-64: assembled_snippet: 340400003405000000A4102000A4102000A4102000A4102003E00008{{$}} +diff --git a/llvm/test/tools/llvm-exegesis/PowerPC/print-assembled-snippet.s b/llvm/test/tools/llvm-exegesis/PowerPC/print-assembled-snippet.s +new file mode 100644 +index 0000000000000..75cad37a768eb +--- /dev/null ++++ llvm/test/tools/llvm-exegesis/PowerPC/print-assembled-snippet.s +@@ -0,0 +1,15 @@ ++# Check that "assembled_snippet" is fetched correctly from object file. ++# Feel free to update the snippet in this test if the code generated by the ++# snippet repetitor was changed intentionally and it is still fetched correctly. ++ ++# RUN: llvm-exegesis --mtriple=powerpc64le-linux-gnu --mcpu=pwr8 --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-LINUX-64-LE ++ ++# LLVM-EXEGESIS-DEFREG R3 0 ++# LLVM-EXEGESIS-DEFREG R4 0 ++add 3, 4, 3 ++ ++# CHECK-LINUX-64-LE: cpu_name: pwr8 ++# CHECK-LINUX-64-LE: llvm_triple: powerpc64le-unknown-linux-gnu ++# CHECK-LINUX-64-LE: assembled_snippet: 0000603800008038141A647C141A647C141A647C141A647C2000804E000000000000000000000000{{$}} +diff --git a/llvm/test/tools/llvm-exegesis/X86/print-assembled-snippet.s b/llvm/test/tools/llvm-exegesis/X86/print-assembled-snippet.s +new file mode 100644 +index 0000000000000..532901d0e0430 +--- /dev/null ++++ llvm/test/tools/llvm-exegesis/X86/print-assembled-snippet.s +@@ -0,0 +1,32 @@ ++# Check that "assembled_snippet" is fetched correctly from object file. ++# Feel free to update the snippet in this test if the code generated by the ++# snippet repetitor was changed intentionally and it is still fetched correctly. ++ ++# RUN: llvm-exegesis --mtriple=x86_64-linux-gnu --mcpu=x86-64 --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-LINUX ++ ++# RUN: llvm-exegesis --mtriple=x86_64-windows-gnu --mcpu=x86-64 --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-WINDOWS-GNU ++ ++# RUN: llvm-exegesis --mtriple=x86_64-windows-msvc --mcpu=x86-64 --benchmark-phase=prepare-and-assemble-snippet \ ++# RUN: --snippets-file=%s --mode=latency --repetition-mode=duplicate \ ++# RUN: | FileCheck %s --check-prefix=CHECK-WINDOWS-MSVC ++ ++# LLVM-EXEGESIS-DEFREG RDI 0 ++# LLVM-EXEGESIS-DEFREG RSI 0 ++# LLVM-EXEGESIS-DEFREG RAX 0 ++leaq (%rdi,%rsi), %rax ++ ++# CHECK-LINUX: cpu_name: x86-64 ++# CHECK-LINUX: llvm_triple: x86_64-unknown-linux-gnu ++# CHECK-LINUX: assembled_snippet: 48BF000000000000000048BE000000000000000048B80000000000000000488D0437488D0437488D0437488D0437C3{{$}} ++ ++# CHECK-WINDOWS-GNU: cpu_name: x86-64 ++# CHECK-WINDOWS-GNU: llvm_triple: x86_64-unknown-windows-gnu ++# CHECK-WINDOWS-GNU: assembled_snippet: 565748BF000000000000000048BE000000000000000048B80000000000000000488D0437488D0437488D0437488D04375F5EC3{{$}} ++ ++# CHECK-WINDOWS-MSVC: cpu_name: x86-64 ++# CHECK-WINDOWS-MSVC: llvm_triple: x86_64-unknown-windows-msvc ++# CHECK-WINDOWS-MSVC: assembled_snippet: 565748BF000000000000000048BE000000000000000048B80000000000000000488D0437488D0437488D0437488D04375F5EC3{{$}} +diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp +index 07465c71afc70..8e561f587cc2a 100644 +--- llvm/tools/llvm-exegesis/lib/Assembler.cpp ++++ llvm/tools/llvm-exegesis/lib/Assembler.cpp +@@ -25,6 +25,7 @@ + #include "llvm/MC/MCInstrInfo.h" + #include "llvm/Support/Alignment.h" + #include "llvm/Support/MemoryBuffer.h" ++#include "llvm/Support/raw_ostream.h" + + namespace llvm { + namespace exegesis { +@@ -323,5 +324,38 @@ ExecutableFunction::ExecutableFunction( + StringRef(reinterpret_cast<const char *>(FunctionAddress), CodeSize); + } + ++Error getBenchmarkFunctionBytes(const StringRef InputData, ++ std::vector<uint8_t> &Bytes) { ++ const auto Holder = getObjectFromBuffer(InputData); ++ const auto *Obj = Holder.getBinary(); ++ // See RuntimeDyldImpl::loadObjectImpl(Obj) for much more complete ++ // implementation. ++ ++ // Find the only function in the object file. ++ SmallVector<object::SymbolRef, 1> Functions; ++ for (auto &Sym : Obj->symbols()) { ++ auto SymType = Sym.getType(); ++ if (SymType && *SymType == object::SymbolRef::Type::ST_Function) ++ Functions.push_back(Sym); ++ } ++ if (Functions.size() != 1) ++ return make_error<Failure>("Exactly one function expected"); ++ ++ // Find the containing section - it is assumed to contain only this function. ++ auto SectionOrErr = Functions.front().getSection(); ++ if (!SectionOrErr || *SectionOrErr == Obj->section_end()) ++ return make_error<Failure>("Section not found"); ++ ++ auto Address = Functions.front().getAddress(); ++ if (!Address || *Address != SectionOrErr.get()->getAddress()) ++ return make_error<Failure>("Unexpected layout"); ++ ++ auto ContentsOrErr = SectionOrErr.get()->getContents(); ++ if (!ContentsOrErr) ++ return ContentsOrErr.takeError(); ++ Bytes.assign(ContentsOrErr->begin(), ContentsOrErr->end()); ++ return Error::success(); ++} ++ + } // namespace exegesis + } // namespace llvm +diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.h b/llvm/tools/llvm-exegesis/lib/Assembler.h +index 2a83344b751e5..cd1e398e4a564 100644 +--- llvm/tools/llvm-exegesis/lib/Assembler.h ++++ llvm/tools/llvm-exegesis/lib/Assembler.h +@@ -121,6 +121,10 @@ struct ExecutableFunction { + StringRef FunctionBytes; + }; + ++// Copies benchmark function's bytes from benchmark object. ++Error getBenchmarkFunctionBytes(const StringRef InputData, ++ std::vector<uint8_t> &Bytes); ++ + // Creates a void(int8*) MachineFunction. + MachineFunction &createVoidVoidPtrMachineFunction(StringRef FunctionID, + Module *Module, +diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +index e1df2940a9b7e..f934b8ec4c6cc 100644 +--- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp ++++ llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +@@ -177,10 +177,10 @@ BenchmarkRunner::getRunnableConfiguration( + LoopBodySizeForSnippet); + if (Error E = Snippet.takeError()) + return std::move(E); +- const ExecutableFunction EF(State.createTargetMachine(), +- getObjectFromBuffer(*Snippet)); +- const auto FnBytes = EF.getFunctionBytes(); +- llvm::append_range(InstrBenchmark.AssembledSnippet, FnBytes); ++ ++ if (auto Err = getBenchmarkFunctionBytes(*Snippet, ++ InstrBenchmark.AssembledSnippet)) ++ return std::move(Err); + } + + // Assemble NumRepetitions instructions repetitions of the snippet for diff --git a/bootstrap/llvm16/hexagon.patch b/bootstrap/llvm16/hexagon.patch new file mode 100644 index 000000000..552079b80 --- /dev/null +++ b/bootstrap/llvm16/hexagon.patch @@ -0,0 +1,95 @@ +From 37605662a99bd0815e2f2e452eb6ab1ce53ecffd Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Mon, 30 May 2022 02:51:34 -0500 +Subject: [PATCH] [Hexagon][Tests] Fix tests on Linux/musl + +When running on a host system using musl, the target triple is defined +as hexagon-unknown-linux-musl by default. The Linux ABI differs from +the non-Linux one with varargs, so this causes the tests to fail. + +Closes BZ49592, PR48936. + +Signed-off-by: A. Wilcox <AWilcox@Wilcox-Tech.com> +--- + test/CodeGen/Hexagon/csr-stubs-spill-threshold.ll | 2 +- + test/CodeGen/Hexagon/long-calls.ll | 2 +- + test/CodeGen/Hexagon/mlong-calls.ll | 2 +- + test/CodeGen/Hexagon/pic-regusage.ll | 2 +- + test/CodeGen/Hexagon/runtime-stkchk.ll | 2 +- + test/CodeGen/Hexagon/swp-memrefs-epilog.ll | 2 +- + test/CodeGen/Hexagon/vararg-formal.ll | 2 +- + 7 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/test/CodeGen/Hexagon/csr-stubs-spill-threshold.ll b/test/CodeGen/Hexagon/csr-stubs-spill-threshold.ll +index afbef217911a..d317d7eac800 100644 +--- a/test/CodeGen/Hexagon/csr-stubs-spill-threshold.ll ++++ b/test/CodeGen/Hexagon/csr-stubs-spill-threshold.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -mtriple=hexagon -O2 -spill-func-threshold=2 < %s | FileCheck %s ++; RUN: llc -march=hexagon -mtriple=hexagon-unknown-linux-gnu -O2 -spill-func-threshold=2 < %s | FileCheck %s + + declare i32 @f0(i32, i32, i32, i32, i32, i32) + +diff --git a/test/CodeGen/Hexagon/long-calls.ll b/test/CodeGen/Hexagon/long-calls.ll +index 628362783c9c..886405a2d91a 100644 +--- a/test/CodeGen/Hexagon/long-calls.ll ++++ b/test/CodeGen/Hexagon/long-calls.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -mtriple=hexagon -enable-save-restore-long -hexagon-initial-cfg-cleanup=0 < %s | FileCheck %s ++; RUN: llc -march=hexagon -mtriple=hexagon-unknown-linux-gnu -enable-save-restore-long -hexagon-initial-cfg-cleanup=0 < %s | FileCheck %s + + ; Check that the -long-calls feature is supported by the backend. + +diff --git a/test/CodeGen/Hexagon/mlong-calls.ll b/test/CodeGen/Hexagon/mlong-calls.ll +index d76b87f987fe..383486dfe63d 100644 +--- a/test/CodeGen/Hexagon/mlong-calls.ll ++++ b/test/CodeGen/Hexagon/mlong-calls.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -hexagon-long-calls -mtriple=hexagon -enable-save-restore-long=true < %s | FileCheck %s ++; RUN: llc -hexagon-long-calls -march=hexagon -mtriple=hexagon-unknown-linux-gnu -enable-save-restore-long=true < %s | FileCheck %s + + ; CHECK: call ##f1 + ; CHECK: jump ##__restore +diff --git a/test/CodeGen/Hexagon/pic-regusage.ll b/test/CodeGen/Hexagon/pic-regusage.ll +index 9d3b6cec39e3..077063e36550 100644 +--- a/test/CodeGen/Hexagon/pic-regusage.ll ++++ b/test/CodeGen/Hexagon/pic-regusage.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -mtriple=hexagon -relocation-model=pic < %s | FileCheck %s ++; RUN: llc -march=hexagon -mtriple=hexagon-unknown-linux-gnu -relocation-model=pic < %s | FileCheck %s + + ; Force the use of R14 (by clobbering everything else in the inline asm). + ; Make sure that R14 is not set before the __save call (which will clobber +diff --git a/test/CodeGen/Hexagon/runtime-stkchk.ll b/test/CodeGen/Hexagon/runtime-stkchk.ll +index 66e93d02ef51..2f3f2ad10f6a 100644 +--- a/test/CodeGen/Hexagon/runtime-stkchk.ll ++++ b/test/CodeGen/Hexagon/runtime-stkchk.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -mtriple=hexagon -mcpu=hexagonv55 -enable-stackovf-sanitizer < %s | FileCheck %s ++; RUN: llc -march=hexagon -mcpu=hexagonv55 -mtriple=hexagon-unknown-linux-gnu -enable-stackovf-sanitizer < %s | FileCheck %s + + ; CHECK-LABEL: foo_1 + ; CHECK: __runtime_stack_check +diff --git a/test/CodeGen/Hexagon/swp-memrefs-epilog.ll b/test/CodeGen/Hexagon/swp-memrefs-epilog.ll +index 20e39dd08fd7..b34dfbc31e9d 100644 +--- a/test/CodeGen/Hexagon/swp-memrefs-epilog.ll ++++ b/test/CodeGen/Hexagon/swp-memrefs-epilog.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -march=hexagon -O2 -fp-contract=fast < %s -pipeliner-experimental-cg=true | FileCheck %s ++; RUN: llc -march=hexagon -mtriple=hexagon-unknown-linux-gnu -O2 -fp-contract=fast < %s -pipeliner-experimental-cg=true | FileCheck %s + + ; Test that the memoperands for instructions in the epilog are updated + ; correctly. Previously, the pipeliner updated the offset for the memoperands +diff --git a/test/CodeGen/Hexagon/vararg-formal.ll b/test/CodeGen/Hexagon/vararg-formal.ll +index 6bba65fcab16..fb3132929bcf 100644 +--- a/test/CodeGen/Hexagon/vararg-formal.ll ++++ b/test/CodeGen/Hexagon/vararg-formal.ll +@@ -1,4 +1,4 @@ +-; RUN: llc -march=hexagon < %s | FileCheck %s ++; RUN: llc -march=hexagon -mtriple=hexagon-unknown-linux-gnu < %s | FileCheck %s + + ; Make sure that the first formal argument is not loaded from memory. + ; CHECK-NOT: memw +-- +2.36.0 + diff --git a/bootstrap/llvm16/llvm-fix-build-with-musl-libc.patch b/bootstrap/llvm16/llvm-fix-build-with-musl-libc.patch new file mode 100644 index 000000000..7fad90bd1 --- /dev/null +++ b/bootstrap/llvm16/llvm-fix-build-with-musl-libc.patch @@ -0,0 +1,46 @@ +From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Thu, 18 Feb 2016 10:33:04 +0100 +Subject: [PATCH 2/3] Fix build with musl libc + +On musl libc the fopen64 and fopen are the same thing, but for +compatibility they have a `#define fopen64 fopen`. Same applies for +fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64. +--- + include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h +index 7becdf0..7f14427 100644 +--- a/include/llvm/Analysis/TargetLibraryInfo.h ++++ b/include/llvm/Analysis/TargetLibraryInfo.h +@@ -17,6 +17,26 @@ + #include "llvm/IR/Module.h" + #include "llvm/Pass.h" + ++#undef fopen64 ++#undef fseeko64 ++#undef fstat64 ++#undef fstatvfs64 ++#undef ftello64 ++#undef lstat64 ++#undef stat64 ++#undef tmpfile64 ++#undef F_GETLK64 ++#undef F_SETLK64 ++#undef F_SETLKW64 ++#undef flock64 ++#undef open64 ++#undef openat64 ++#undef creat64 ++#undef lockf64 ++#undef posix_fadvise64 ++#undef posix_fallocate64 ++#undef off64_t ++ + namespace llvm { + /// VecDesc - Describes a possible vectorization of a function. + /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized +-- +2.7.3 + diff --git a/bootstrap/llvm16/macho32.patch b/bootstrap/llvm16/macho32.patch new file mode 100644 index 000000000..31279d502 --- /dev/null +++ b/bootstrap/llvm16/macho32.patch @@ -0,0 +1,17 @@ +Use integer offset math instead of pointer math to determine load +command bounds. + +Upstream-URL: https://github.com/llvm/llvm-project/issues/56746 + +--- llvm-14.0.6.src/lib/Object/MachOObjectFile.cpp.old 2022-06-22 16:46:24.000000000 +0000 ++++ llvm-14.0.6.src/lib/Object/MachOObjectFile.cpp 2022-11-28 04:21:02.730211841 +0000 +@@ -190,7 +190,8 @@ + getLoadCommandInfo(const MachOObjectFile &Obj, const char *Ptr, + uint32_t LoadCommandIndex) { + if (auto CmdOrErr = getStructOrErr<MachO::load_command>(Obj, Ptr)) { +- if (CmdOrErr->cmdsize + Ptr > Obj.getData().end()) ++ uint64_t Offset = Ptr - Obj.getData().begin(); ++ if (CmdOrErr->cmdsize + Offset > Obj.getData().size()) + return malformedError("load command " + Twine(LoadCommandIndex) + + " extends past end of file"); + if (CmdOrErr->cmdsize < 8) diff --git a/bootstrap/llvm16/musl-ppc64-elfv2.patch b/bootstrap/llvm16/musl-ppc64-elfv2.patch new file mode 100644 index 000000000..49f6e5702 --- /dev/null +++ b/bootstrap/llvm16/musl-ppc64-elfv2.patch @@ -0,0 +1,28 @@ +From 750d323a6060ad92c3d247f85d6555041f55b4a5 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Thu, 4 Oct 2018 15:26:59 -0500 +Subject: [PATCH] Add support for powerpc64-*-linux-musl targets + +This patch ensures that 64-bit PowerPC musl targets use ELFv2 ABI on both +endians. It additionally adds a test that big endian PPC64 uses ELFv2 on +musl. +--- + lib/Target/PowerPC/PPCTargetMachine.cpp | 4 ++++ + test/CodeGen/PowerPC/ppc64-elf-abi.ll | 1 + + 2 files changed, 5 insertions(+) + +diff --git a/test/CodeGen/PowerPC/ppc64-elf-abi.ll b/test/CodeGen/PowerPC/ppc64-elf-abi.ll +index 1e17930304b..aa594b37b47 100644 +--- a/test/CodeGen/PowerPC/ppc64-elf-abi.ll ++++ b/test/CodeGen/PowerPC/ppc64-elf-abi.ll +@@ -1,6 +1,7 @@ + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv1 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 ++; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-musl < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 +-- +2.18.0 + diff --git a/bootstrap/llvm16/python3-test.patch b/bootstrap/llvm16/python3-test.patch new file mode 100644 index 000000000..76f13385d --- /dev/null +++ b/bootstrap/llvm16/python3-test.patch @@ -0,0 +1,8 @@ +--- llvm-7.0.1.src/test/BugPoint/compile-custom.ll.py.old 2014-03-13 00:10:37.000000000 +0000 ++++ llvm-7.0.1.src/test/BugPoint/compile-custom.ll.py 2019-03-10 03:48:48.600000000 +0000 +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python ++#!/usr/bin/env python3 + + from __future__ import print_function + diff --git a/bootstrap/llvm16/roundeven.patch b/bootstrap/llvm16/roundeven.patch new file mode 100644 index 000000000..e052e4a86 --- /dev/null +++ b/bootstrap/llvm16/roundeven.patch @@ -0,0 +1,49 @@ +--- llvm-14.0.4.src/lib/Analysis/TargetLibraryInfo.cpp.old 2022-05-24 22:02:58.000000000 +0000 ++++ llvm-14.0.4.src/lib/Analysis/TargetLibraryInfo.cpp 2022-07-06 01:38:22.016862561 +0000 +@@ -616,6 +616,13 @@ + TLI.setUnavailable(LibFunc_statvfs64); + TLI.setUnavailable(LibFunc_tmpfile64); + ++ // These functions are unavailable on musl. ++ if (T.isMusl()) { ++ TLI.setUnavailable(LibFunc_roundeven); ++ TLI.setUnavailable(LibFunc_roundevenf); ++ TLI.setUnavailable(LibFunc_roundevenl); ++ } ++ + // Relaxed math functions are included in math-finite.h on Linux (GLIBC). + // Note that math-finite.h is no longer supported by top-of-tree GLIBC, + // so we keep these functions around just so that they're recognized by +--- llvm-14.0.4.src/test/Transforms/InstCombine/double-float-shrink-2.ll.old 2022-05-24 22:02:58.000000000 +0000 ++++ llvm-14.0.4.src/test/Transforms/InstCombine/double-float-shrink-2.ll 2022-07-06 02:03:20.657791057 +0000 +@@ -1,5 +1,5 @@ + ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +-; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-linux" | FileCheck %s ++; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-linux-gnu" | FileCheck %s + ; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-win32" | FileCheck %s + ; RUN: opt < %s -passes=instcombine -S -mtriple "x86_64-pc-win32" | FileCheck %s + ; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-mingw32" | FileCheck %s +--- llvm-14.0.4.src/test/ExecutionEngine/Interpreter/intrinsics.ll.old 2022-05-24 22:02:58.000000000 +0000 ++++ llvm-14.0.4.src/test/ExecutionEngine/Interpreter/intrinsics.ll 2022-07-23 06:50:59.336665672 +0000 +@@ -13,8 +13,8 @@ + declare double @llvm.trunc.f64(double) + declare float @llvm.round.f32(float) + declare double @llvm.round.f64(double) +-declare float @llvm.roundeven.f32(float) +-declare double @llvm.roundeven.f64(double) ++;declare float @llvm.roundeven.f32(float) ++;declare double @llvm.roundeven.f64(double) + declare float @llvm.copysign.f32(float, float) + declare double @llvm.copysign.f64(double, double) + +@@ -31,8 +31,8 @@ + %trunc64 = call double @llvm.trunc.f64(double 0.000000e+00) + %round32 = call float @llvm.round.f32(float 0.000000e+00) + %round64 = call double @llvm.round.f64(double 0.000000e+00) +- %roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00) +- %roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00) ++ ;%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00) ++ ;%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00) + %copysign32 = call float @llvm.copysign.f32(float 0.000000e+00, float 0.000000e+00) + %copysign64 = call double @llvm.copysign.f64(double 0.000000e+00, double 0.000000e+00) + ret i32 0 |