diff --git a/0006-Propeller-bugfix-for-MachineBasicBlock-hash-set.patch b/0006-Propeller-bugfix-for-MachineBasicBlock-hash-set.patch new file mode 100644 index 0000000000000000000000000000000000000000..e91b8c404a7e25ca4652e25850c16194218cd0f3 --- /dev/null +++ b/0006-Propeller-bugfix-for-MachineBasicBlock-hash-set.patch @@ -0,0 +1,15 @@ +diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp +index 9b985f9f0aff..6e58c8fb2946 100644 +--- a/llvm/lib/CodeGen/BasicBlockSections.cpp ++++ b/llvm/lib/CodeGen/BasicBlockSections.cpp +@@ -319,7 +319,8 @@ void computeBBHash(MachineFunction &MF) { + } + } + } +- MBB.setHash(Hash); ++ if (MBB.getBBID()) ++ MBB.setHash(Hash); + } + } + +-- \ No newline at end of file diff --git a/0007-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch b/0007-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch new file mode 100644 index 0000000000000000000000000000000000000000..db4d8f8e8c7830b2d46c17db56ff66c8db6c33fe --- /dev/null +++ b/0007-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch @@ -0,0 +1,186 @@ +From ee0f56cff40b324bb06e034e247ec85ae9a846bf Mon Sep 17 00:00:00 2001 +From: Nikita Popov +Date: Wed, 8 Jan 2025 08:28:18 +0100 +Subject: [PATCH] [PATCH] [Bolt][CMake] Don't export bolt libraries in + LLVMExports.cmake + +Bolt makes use of add_llvm_library and as such ends up exporting +its libraries from LLVMExports.cmake, which is not correct. + +Bolt doesn't have its own exports file, and I assume that there +is no desire to have one either -- Bolt libraries are not intended +to be consumed as a cmake module, right? + +As such, this PR adds a NO_EXPORT option to simplify exclude these +libraries from the exports file. + +--- +This patch originates from this PR: + +https://patch-diff.githubusercontent.com/raw/llvm/llvm-project/pull/121936. + +The commit was: + +https://github.com/nikic/llvm-project/commit/4333a4dd270b5c046c5469b97846e3dae58fb221.patch + +And then it was rebased onto llvmorg-19.1.6. +--- + bolt/lib/Core/CMakeLists.txt | 1 + + bolt/lib/Passes/CMakeLists.txt | 1 + + bolt/lib/Profile/CMakeLists.txt | 1 + + bolt/lib/Rewrite/CMakeLists.txt | 1 + + bolt/lib/RuntimeLibs/CMakeLists.txt | 1 + + bolt/lib/Target/AArch64/CMakeLists.txt | 1 + + bolt/lib/Target/RISCV/CMakeLists.txt | 1 + + bolt/lib/Target/X86/CMakeLists.txt | 1 + + bolt/lib/Utils/CMakeLists.txt | 1 + + llvm/cmake/modules/AddLLVM.cmake | 12 +++++++++--- + 10 files changed, 18 insertions(+), 3 deletions(-) + +diff --git a/bolt/lib/Core/CMakeLists.txt b/bolt/lib/Core/CMakeLists.txt +index c913179ebcc5..f45ce15afaac 100644 +--- a/bolt/lib/Core/CMakeLists.txt ++++ b/bolt/lib/Core/CMakeLists.txt +@@ -30,6 +30,7 @@ add_llvm_library(LLVMBOLTCore + ParallelUtilities.cpp + Relocation.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + LINK_LIBS + ${LLVM_PTHREAD_LIB} +diff --git a/bolt/lib/Passes/CMakeLists.txt b/bolt/lib/Passes/CMakeLists.txt +index b8bbe59a6448..80fce073d0f7 100644 +--- a/bolt/lib/Passes/CMakeLists.txt ++++ b/bolt/lib/Passes/CMakeLists.txt +@@ -49,6 +49,7 @@ add_llvm_library(LLVMBOLTPasses + VeneerElimination.cpp + RetpolineInsertion.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/bolt/lib/Profile/CMakeLists.txt b/bolt/lib/Profile/CMakeLists.txt +index 3a31a9cc1919..9bbd9f39b7bb 100644 +--- a/bolt/lib/Profile/CMakeLists.txt ++++ b/bolt/lib/Profile/CMakeLists.txt +@@ -8,6 +8,7 @@ add_llvm_library(LLVMBOLTProfile + YAMLProfileReader.cpp + YAMLProfileWriter.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_COMPONENTS +diff --git a/bolt/lib/Rewrite/CMakeLists.txt b/bolt/lib/Rewrite/CMakeLists.txt +index b0e2b7f46bef..676c41a3b691 100644 +--- a/bolt/lib/Rewrite/CMakeLists.txt ++++ b/bolt/lib/Rewrite/CMakeLists.txt +@@ -23,6 +23,7 @@ add_llvm_library(LLVMBOLTRewrite + RewriteInstance.cpp + SDTRewriter.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/bolt/lib/RuntimeLibs/CMakeLists.txt b/bolt/lib/RuntimeLibs/CMakeLists.txt +index d3ac71d3e797..b8db7e4a1553 100644 +--- a/bolt/lib/RuntimeLibs/CMakeLists.txt ++++ b/bolt/lib/RuntimeLibs/CMakeLists.txt +@@ -11,6 +11,7 @@ add_llvm_library(LLVMBOLTRuntimeLibs + HugifyRuntimeLibrary.cpp + InstrumentationRuntimeLibrary.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + ) + +diff --git a/bolt/lib/Target/AArch64/CMakeLists.txt b/bolt/lib/Target/AArch64/CMakeLists.txt +index be03e247aa96..526a9645cb54 100644 +--- a/bolt/lib/Target/AArch64/CMakeLists.txt ++++ b/bolt/lib/Target/AArch64/CMakeLists.txt +@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS + add_llvm_library(LLVMBOLTTargetAArch64 + AArch64MCPlusBuilder.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Target/RISCV/CMakeLists.txt b/bolt/lib/Target/RISCV/CMakeLists.txt +index 7f9557606320..3955cfc0f089 100644 +--- a/bolt/lib/Target/RISCV/CMakeLists.txt ++++ b/bolt/lib/Target/RISCV/CMakeLists.txt +@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS + add_llvm_library(LLVMBOLTTargetRISCV + RISCVMCPlusBuilder.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Target/X86/CMakeLists.txt b/bolt/lib/Target/X86/CMakeLists.txt +index 2b769bc7e7f5..00100e9b84c9 100644 +--- a/bolt/lib/Target/X86/CMakeLists.txt ++++ b/bolt/lib/Target/X86/CMakeLists.txt +@@ -9,6 +9,7 @@ add_llvm_library(LLVMBOLTTargetX86 + X86MCPlusBuilder.cpp + X86MCSymbolizer.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Utils/CMakeLists.txt b/bolt/lib/Utils/CMakeLists.txt +index d1403314274b..ceddcfc8f57a 100644 +--- a/bolt/lib/Utils/CMakeLists.txt ++++ b/bolt/lib/Utils/CMakeLists.txt +@@ -2,6 +2,7 @@ add_llvm_library(LLVMBOLTUtils + CommandLineOpts.cpp + Utils.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake +index 6d74e58aea6a..88225593ff3f 100644 +--- a/llvm/cmake/modules/AddLLVM.cmake ++++ b/llvm/cmake/modules/AddLLVM.cmake +@@ -838,7 +838,7 @@ endfunction() + + macro(add_llvm_library name) + cmake_parse_arguments(ARG +- "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN" ++ "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN;NO_EXPORT" + "" + "" + ${ARGN}) +@@ -873,7 +873,11 @@ macro(add_llvm_library name) + set(umbrella) + endif() + +- get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) ++ if(ARG_NO_EXPORT) ++ set(export_to_llvmexports) ++ else() ++ get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) ++ endif() + install(TARGETS ${name} + ${export_to_llvmexports} + LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +@@ -886,7 +890,9 @@ macro(add_llvm_library name) + COMPONENT ${name}) + endif() + endif() +- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) ++ if(NOT ARG_NO_EXPORT) ++ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) ++ endif() + endif() + if (ARG_MODULE) + set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") +-- +2.47.1 diff --git a/llvm-for-oE-17.0.6-2506.0.4.tar.gz b/llvm-for-oE-17.0.6-2509.0.2.tar.gz similarity index 32% rename from llvm-for-oE-17.0.6-2506.0.4.tar.gz rename to llvm-for-oE-17.0.6-2509.0.2.tar.gz index 171f896de39b0f6dac45da2dda89362360f79b53..d5697597bf528ed2c63f842912561ab7fae2de18 100644 --- a/llvm-for-oE-17.0.6-2506.0.4.tar.gz +++ b/llvm-for-oE-17.0.6-2509.0.2.tar.gz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:db05405706279885e543dd562d7f2887fd433eb10dae819811df7d588e8548b3 -size 212541296 +oid sha256:717518c4ddf31b5d141fce1bdac7ede96a59de292f09f72482277ca0a49f489b +size 212666397 diff --git a/llvm.spec b/llvm.spec index 20a131143a86e1a53999e306111b634b1e49d940..ce29556e2587812648e3fa2495f56b3064087a17 100644 --- a/llvm.spec +++ b/llvm.spec @@ -4,7 +4,11 @@ %global min_ver 0 %global patch_ver 6 -%global os_version %{lua: print(tonumber(rpm.expand("%{dist}"):match("oe(%d+)") or 9999))} +%global os_version %{lua: print(tonumber(rpm.expand("%{dist}"):match("oe(%d+)") or 2403))} + +%if %{os_version} == 1 +%global os_version 9999 +%endif # Build sys_llvm packages or compat packages %bcond_without sys_llvm @@ -21,13 +25,20 @@ %endif %bcond_without lldb %bcond_without libcxx + +%ifarch aarch64 x86_64 +%bcond_without bolt +%else +%bcond_with bolt +%endif + %if %{with toolchain_clang} %global toolchain clang %endif %undefine __cmake_in_source_build -%global src_tarball llvm-for-oE-17.0.6-2506.0.4 +%global src_tarball llvm-for-oE-17.0.6-2509.0.2 %global src_tarball_dir llvm-project-%{src_tarball} #region LLVM globals @@ -99,8 +110,6 @@ %global pkg_name_compiler_rt %{?scl_prefix}compiler-rt -%global optflags %(echo %{optflags} | sed 's/-fgcc-compatible//') -%global optflags %(echo %{optflags} | sed 's/-specs=\/usr\/lib\/rpm\/generic-hardened-cc1//') %ifnarch x86_64 %global optflags %(echo %{optflags} | sed 's/-fstack-clash-protection//') # may affect cmake check for fpic @@ -143,6 +152,10 @@ %global pkg_name_llvm_libunwind %{?scl_prefix}llvm-libunwind #endregion libcxx globals +#region BOLT globals +%global pkg_name_bolt %{?scl_prefix}llvm-bolt +#endregion BOLT globals + #region packages #region main package %if %{with sys_llvm} @@ -151,7 +164,7 @@ Name: llvm Name: llvm-toolset-%{maj_ver} %endif Version: %{maj_ver}.%{min_ver}.%{patch_ver} -Release: 45 +Release: 53 Summary: The Low Level Virtual Machine License: NCSA @@ -173,6 +186,8 @@ Patch0004: 0004-remove-cmake_minimum_required.patch %if %{with bisheng_autotuner} Patch0005: 0005-Fix-for-building-autotuner-with-mlir.patch %endif +Patch0006: 0006-Propeller-bugfix-for-MachineBasicBlock-hash-set.patch +Patch0007: 0007-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch BuildRequires: gcc BuildRequires: gcc-c++ @@ -748,6 +763,24 @@ Documentation for LLVM libunwind %endif #endregion libcxx packages +#region BOLT packages +%if %{with bolt} +%package -n %{pkg_name_bolt} +Summary: A post-link optimizer developed to speed up large applications +License: Apache-2.0 WITH LLVM-exception +URL: https://github.com/llvm/llvm-project/tree/main/bolt + +# As hinted by bolt documentation +Recommends: gperftools-devel + +%description -n %{pkg_name_bolt} + +BOLT is a post-link optimizer developed to speed up large applications. +It achieves the improvements by optimizing application's code layout based on +execution profile gathered by sampling profiler, such as Linux `perf` tool. +%endif +#endregion BOLT packages + #endregion packages #region prep @@ -769,6 +802,11 @@ Documentation for LLVM libunwind # shebang_fix part removed +# update Gnu target triples, make it friendly to all openEuler based distribution +%if "%{_vendor}" != "openEuler" +sed -i 's/"\([a-zA-Z0-9_-]\+\)-openEuler-linux"/"\1-openEuler-linux", "\1-%{_vendor}-linux"/g' %{build_src_dir}/clang/lib/Driver/ToolChains/Gnu.cpp +%endif + #endregion prep #region build @@ -790,6 +828,9 @@ Documentation for LLVM libunwind %if %{with mlir} %global projects %{projects};mlir %endif +%if %{with bolt} +%global projects %{projects};bolt +%endif %global runtimes compiler-rt;openmp @@ -797,9 +838,6 @@ Documentation for LLVM libunwind %global runtimes %{runtimes};libcxx;libcxxabi;libunwind %endif -# Copy CFLAGS into ASMFLAGS, so -fcf-protection is used when compiling assembly files. -export ASMFLAGS="%{build_cflags}" - # We set CLANG_DEFAULT_PIE_ON_LINUX=OFF and PPC_LINUX_DEFAULT_IEEELONGDOUBLE=ON to match the # defaults used by Fedora's GCC. @@ -834,7 +872,7 @@ export ASMFLAGS="%{build_cflags}" %global cmake_config_args %{cmake_config_args} \\\ -DCLANG_BUILD_EXAMPLES:BOOL=OFF \\\ -DCLANG_CONFIG_FILE_SYSTEM_DIR=%{_sysconfdir}/%{pkg_name_clang}/ \\\ - -DCLANG_DEFAULT_PIE_ON_LINUX=OFF \\\ + -DCLANG_DEFAULT_PIE_ON_LINUX=ON \\\ -DCLANG_DEFAULT_UNWINDLIB=libgcc \\\ -DCLANG_ENABLE_ARCMT:BOOL=ON \\\ -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=ON \\\ @@ -1015,6 +1053,11 @@ export ASMFLAGS="%{build_cflags}" extra_cmake_args='' #endregion cmake options +# set flags for build +export CFLAGS="%{build_cflags}" +export CXXFLAGS="%{build_cxxflags}" +export ASMFLAGS="%{build_cflags}" + %if %{with ACPO} echo "enable ACPO" export CFLAGS="-Wp,-DENABLE_ACPO ${CFLAGS}" @@ -1215,6 +1258,15 @@ cd %{build_src_dir} mkdir -p %{buildroot}/%{_bindir} +# Remove rpath for openmp library +%ifnarch %{ix86} %{arm} riscv64 loongarch64 +%global openmp_library libomptarget.rtl.cuda.so.17 libomptarget.rtl.%{_arch}.so.17 libomptarget.so.17 +for f in %{openmp_library} +do + chrpath --delete %{buildroot}%{install_libdir}/$f +done +%endif + # Install binaries needed for lit tests %global test_binaries llvm-isel-fuzzer llvm-opt-fuzzer @@ -1480,6 +1532,11 @@ popd %endif #endregion libcxx installation +#region BOLT installation +# We don't ship libLLVMBOLT*.a +rm -f %{buildroot}%{_libdir}/libLLVMBOLT*.a +#endregion BOLT installation + %if %{without sys_llvm} && %{os_version} < 2403 # Add version suffix to binaries. Do this at the end so it includes any # additional binaries that may be been added by other steps. @@ -1949,6 +2006,54 @@ export LD_LIBRARY_PATH=%{buildroot}/%{install_libdir}:%{buildroot}/%{python3_sit %endif #endregion Test MLIR +#region BOLT tests +%if %{with bolt} +%if %{maj_ver} < 20 +export LIT_XFAIL="$LIT_XFAIL;AArch64/build_id.c" +export LIT_XFAIL="$LIT_XFAIL;AArch64/plt-call.test" +export LIT_XFAIL="$LIT_XFAIL;X86/linux-static-keys.s" +export LIT_XFAIL="$LIT_XFAIL;X86/plt-call.test" +%endif + +# Beginning with LLVM 20 this test has the "non-root-user" requirement +# and then the test should pass. But now it is flaky, hence we can only +# filter it out. +test_list_filter_out+=("BOLT :: unreadable-profile.test") + +%ifarch aarch64 +# Failing test cases on aarch64 +# TODO(kkleine): The following used to fail on aarch64 but passed today. +#export LIT_XFAIL="$LIT_XFAIL;cache+-deprecated.test" +#export LIT_XFAIL="$LIT_XFAIL;bolt-icf.test" +#export LIT_XFAIL="$LIT_XFAIL;R_ABS.pic.lld.cpp" + +# The following tests require LSE in order to run. +# More info at: https://github.com/llvm/llvm-project/issues/86485 +if ! grep -q atomics /proc/cpuinfo; then + test_list_filter_out+=("BOLT :: runtime/AArch64/basic-instrumentation.test") + test_list_filter_out+=("BOLT :: runtime/AArch64/hook-fini.test") + test_list_filter_out+=("BOLT :: runtime/AArch64/instrumentation-ind-call.c") + test_list_filter_out+=("BOLT :: runtime/exceptions-instrumentation.test") + test_list_filter_out+=("BOLT :: runtime/instrumentation-indirect-2.c") + test_list_filter_out+=("BOLT :: runtime/pie-exceptions-split.test") +fi +%endif + +%if %{maj_ver} < 20 +%ifarch x86_64 +# BOLT-ERROR: instrumentation of static binary currently does not support profile output on binary +# finalization, so it requires -instrumentation-sleep-time=N (N>0) usage +# export LIT_XFAIL="$LIT_XFAIL;X86/internal-call-instrument.s" +%endif +%endif + +# Failing test cases for RISCV +export LIT_XFAIL="$LIT_XFAIL;RISCV/mapping-syms.s" + +%cmake_build --target check-bolt +%endif +#endregion BOLT tests + %endif #endregion check @@ -2875,9 +2980,65 @@ fi %doc %{_pkgdocdir}/html #endregion libcxx files +#region BOLT files +%if %{with bolt} +%files -n %{pkg_name_bolt} +%license bolt/LICENSE.TXT +%{install_bindir}/llvm-bolt +%if %{maj_ver} >= 20 +%{install_bindir}/llvm-bolt-binary-analysis +%endif +%{install_bindir}/llvm-boltdiff +%{install_bindir}/llvm-bolt-heatmap +%{install_bindir}/merge-fdata +%{install_bindir}/perf2bolt + +%{install_libdir}/libbolt_rt_hugify.a +%{install_libdir}/libbolt_rt_instr.a + +%if %{without sys_llvm} +%{_bindir}/llvm-bolt-%{maj_ver} +%if %{maj_ver} >= 20 +%{_bindir}/llvm-bolt-binary-analysis-%{maj_ver} +%endif +%{_bindir}/llvm-boltdiff-%{maj_ver} +%{_bindir}/llvm-bolt-heatmap-%{maj_ver} +%{_bindir}/merge-fdata-%{maj_ver} +%{_bindir}/perf2bolt-%{maj_ver} +%endif + +%endif +#endregion BOLT files + #endregion files %changelog +* Fri Oct 17 2025 liyunfei - 17.0.6-53 +- update target triples for all openEuler based distribution. + +* Thu Oct 09 2025 liyunfei - 17.0.6-52 +- Backport cmake fix for bolt libraries + +* Tue Sep 23 2025 liyunfei - 17.0.6-51 +- Add bolt + +* Tue Sep 09 2025 liyunfei - 17.0.6-50 +- update to llvm-for-oe-17.0.6-2509.0.2 +- release-note https://gitee.com/openeuler/llvm-project/releases/tag/llvm-for-oE-17.0.6-2509.0.2 + +* Tue Sep 02 2025 Xu Jin - 17.0.6-49 +- remove rpath for openmp library + +* Tue Sep 02 2025 liyunfei - 17.0.6-48 +- add fix for pie hardening + +* Wed Aug 27 2025 liyunfei - 17.0.6-47 +- update to llvm-for-oe-17.0.6-2509.0.1 +- release-note https://gitee.com/openeuler/llvm-project/releases/tag/llvm-for-oE-17.0.6-2509.0.1 + +* Wed Aug 20 2025 liyunfei - 17.0.6-46 +- fix missing hardening compiler options + * Wed Jun 18 2025 liyunfei - 17.0.6-45 - update to llvm-for-oe-17.0.6-2506.0.4 - release-note https://gitee.com/openeuler/llvm-project/releases/tag/llvm-for-oE-17.0.6-2506.0.4