diff --git a/0004-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch b/0004-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch new file mode 100644 index 0000000000000000000000000000000000000000..e7f0b0dfe90d3b1a545eb49e5e3821ba3d2319e6 --- /dev/null +++ b/0004-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch @@ -0,0 +1,121 @@ +From 3dafe34db0eb53af146cf782124f788ceaf6a9aa Mon Sep 17 00:00:00 2001 +From: Han Shen +Date: Fri, 6 Sep 2024 10:21:21 -0700 +Subject: [PATCH] Added -DBUILD_SHARED=On/Off to control whether to build + static linked or dynamic linked binaries. (#229) + +CentOS 9 (Fedora) does not contain in its repositories some of the required static libraries. -DBUILD_SHARED=On is required to build on CentOS 9. + +Also added notes on how to install prerequisites and build on CentOS 9. +--- + CMakeLists.txt | 27 ++++++++++++++++++++------- + README.md | 22 +++++++++++++++++----- + 2 files changed, 37 insertions(+), 12 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b300f00..5b030c4 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -3,7 +3,14 @@ set(CMAKE_CXX_STANDARD 17) + set(ABSL_PROPAGATE_CXX_STD on) + + project(autofdo) +-set (Protobuf_USE_STATIC_LIBS FALSE) ++ ++if (NOT DEFINED BUILD_SHARED) ++ set(BUILD_SHARED FALSE) ++endif() ++ ++if (NOT ${BUILD_SHARED}) ++ set (Protobuf_USE_STATIC_LIBS TRUE) ++endif() + + function (execute_perf_protobuf) + +@@ -201,7 +208,9 @@ function (build_llvm) + set (LLVM_TARGETS_TO_BUILD X86 AArch64 CACHE STRING + "Semicolon-separated list of LLVM targets to build, or \"all\".") + set (LLVM_ENABLE_ZSTD FORCE_ON) +- set (LLVM_USE_STATIC_ZSTD TRUE CACHE BOOL "use static zstd") ++ if (NOT ${BUILD_SHARED}) ++ set (LLVM_USE_STATIC_ZSTD TRUE CACHE BOOL "use static zstd") ++ endif() + # terminfo is not needed by create_llvm_prof + set (LLVM_ENABLE_TERMINFO OFF CACHE BOOL "enable terminfo") + ### +@@ -452,6 +461,8 @@ function (build_llvm) + llvm_propeller_mock_program_cfg_builder.cc) + target_include_directories(llvm_propeller_test_objects + PUBLIC ${PROTOBUF_INCLUDE_DIR}) ++ target_link_libraries(llvm_propeller_test_objects ++ llvm_propeller_cfg_proto) + + add_library(llvm_propeller_objects OBJECT + addr2cu.cc +@@ -845,11 +856,13 @@ if (${enable_tool} STREQUAL gcov) + elseif (${enable_tool} STREQUAL llvm) + message(STATUS "Building tool \"LLVM\" ...") + +- # Build static binaries. +- set (BUILD_SHARED_LIBS OFF) +- set (CMAKE_FIND_LIBRARY_SUFFIXES ".a") +- # Link static executables. +- set (CMAKE_EXE_LINKER_FLAGS "-static") ++ if (NOT ${BUILD_SHARED}) ++ # Build static binaries. ++ set (BUILD_SHARED_LIBS OFF) ++ set (CMAKE_FIND_LIBRARY_SUFFIXES ".a") ++ # Link static executables. ++ set (CMAKE_EXE_LINKER_FLAGS "-static") ++ endif() + + build_llvm() + else () +diff --git a/README.md b/README.md +index bd6c14f..2869d67 100644 +--- a/README.md ++++ b/README.md +@@ -1,5 +1,6 @@ ++AutoFDO tools can be built on Ubuntu 20.04, 22.04 or CentOS 9, choose 1a or 1b to install prerequisites. + +-# 1. Install prerequisites on Ubuntu 20.04 and 22.04 ++# 1a. Install prerequisites on Ubuntu 20.04 and 22.04 + + ``` + $ sudo apt install libunwind-dev libgflags-dev libssl-dev libelf-dev protobuf-compiler cmake libzstd-dev clang g++ +@@ -16,17 +17,28 @@ The cmake version (3.16.3) on Ubuntu 20.04 LTS is too old to build third_party/l + $ sudo apt update && sudo apt install cmake + ``` + ++# 1b. Install prerequisites on CentOS 9 ++ ++``` ++ dnf config-manager --set-enabled crb ++ dnf install epel-release epel-next-release ++ dnf install git cmake ninja-build elfutils-libelf libunwind-devel clang clang-devel clang-libs protobuf-devel protobuf-compiler elfutils-libelf-devel gcc gcc-c++ openssl-devel ++``` ++ ++ + ## 2 Build autofdo tools + ++Note, "-DBUILD_SHARED=On" is required for CentOS 9, this will build the tools linked with shared libraries. For Ubuntu 20.04 and Ubuntu 22.04, "-DBUILD_SHARED" is optional, when it is not given, this will build the tools linked statically. ++ + ``` + $ git clone --recursive --depth 1 https://github.com/google/autofdo.git + $ cd autofdo + $ mkdir build +- $ cd build +- $ # Build LLVM tools for AUtoFDO and Propeller +- $ cmake -DENABLE_TOOL=LLVM -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ../ ++ $ cd build ++ $ # Build LLVM tools for AutoFDO and Propeller ++ $ cmake -DENABLE_TOOL=LLVM -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED=On ../ + $ # Build autofdo tools +- $ cmake -DENABLE_TOOL=GCOV -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ../ ++ $ cmake -DENABLE_TOOL=GCOV -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED=On ../ + $ make -j 4 + ``` + +-- +2.45.0.windows.1 + diff --git a/0005-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch b/0005-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch new file mode 100644 index 0000000000000000000000000000000000000000..ed65b38dd513d7ba55f407eafbf13584e9841438 --- /dev/null +++ b/0005-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch @@ -0,0 +1,47 @@ +From dab7bfe8dbca1d75043407a63f9c93a4da3a8b08 Mon Sep 17 00:00:00 2001 +From: xiajingze +Date: Tue, 29 Apr 2025 10:55:51 +0800 +Subject: [PATCH] Rename LLVM tools to distinguish them from GCOV tools + +--- + CMakeLists.txt | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dc10c28..f534684 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -294,15 +294,15 @@ function (build_llvm) + llvm_profile_writer + sample_reader) + +- add_executable(profile_diff profile_diff.cc) +- target_link_libraries(profile_diff ++ add_executable(llvm_profile_diff profile_diff.cc) ++ target_link_libraries(llvm_profile_diff + absl::flags_parse + llvm_profile_reader + symbol_map + LLVMSupport) + +- add_executable(profile_merger profile_merger.cc) +- target_link_libraries(profile_merger ++ add_executable(llvm_profile_merger profile_merger.cc) ++ target_link_libraries(llvm_profile_merger + absl::flags_parse + llvm_profile_reader + llvm_profile_writer +@@ -319,8 +319,8 @@ function (build_llvm) + LLVMDebugInfoDWARF + LLVMSupport) + +- add_executable(sample_merger sample_merger.cc) +- target_link_libraries(sample_merger ++ add_executable(llvm_sample_merger sample_merger.cc) ++ target_link_libraries(llvm_sample_merger + absl::flags_parse + llvm_profile_reader + llvm_profile_writer +-- +2.45.0.windows.1 + diff --git a/autofdo.spec b/autofdo.spec index c4757618135cefafc668a5317100fa7d4faf677d..8019156c1a81c98d3ea888d59f5cd018231aee6a 100644 --- a/autofdo.spec +++ b/autofdo.spec @@ -1,8 +1,10 @@ %global abseil_version 20250127.0 +# Sync from llvm, disable LTO. +%define _lto_cflags %{nil} Name: autofdo Version: 0.30.1 -Release: 5 +Release: 6 Summary: A tool to convert perf.data profile to AutoFDO profile License: Apache-2.0 URL: https://github.com/google/autofdo @@ -10,9 +12,12 @@ URL: https://github.com/google/autofdo # so remove the GIT information and repackage it. Source0: %{name}-%{version}.tar.xz Source1: https://github.com/abseil/abseil-cpp/archive/abseil-cpp/abseil-cpp-%{abseil_version}.tar.gz +Source2: llvm-project.tar.xz Patch1: 0001-adjust-the-link-method-of-dependency-libraries.patch Patch2: 0002-unscaledcycleclock-remove-RISC-V-support.patch Patch3: backport-autofdo-third_party-glog-eliminate-deprecation-warning.patch +Patch4: 0004-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch +Patch5: 0005-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch BuildRequires: gcc gcc-c++ cmake elfutils-libelf-devel openssl-devel pkg-config ninja-build libunwind-devel protobuf-devel %description @@ -24,9 +29,12 @@ profile that can be used by GCC and LLVM. rm -fr third_party/abseil tar -xvf %{SOURCE1} -C ./third_party mv third_party/abseil-cpp-%{abseil_version} third_party/abseil +tar -xvf %{SOURCE2} -C ./third_party %build -%cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_TOOL=GCOV -DBUILD_SHARED_LIBS=OFF +%cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_TOOL=GCOV -DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED=ON +%cmake_build +%cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_TOOL=LLVM -DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED=ON %cmake_build %install @@ -34,13 +42,27 @@ mkdir -p %{buildroot}%{_bindir} install -m0755 %{__cmake_builddir}/create_gcov %{buildroot}%{_bindir} install -m0755 %{__cmake_builddir}/dump_gcov %{buildroot}%{_bindir} install -m0755 %{__cmake_builddir}/profile_merger %{buildroot}%{_bindir} +install -m0755 %{__cmake_builddir}/llvm_profile_diff %{buildroot}%{_bindir} +install -m0755 %{__cmake_builddir}/llvm_profile_merger %{buildroot}%{_bindir} +install -m0755 %{__cmake_builddir}/llvm_sample_merger %{buildroot}%{_bindir} +install -m0755 %{__cmake_builddir}/create_llvm_prof %{buildroot}%{_bindir} %files %{_bindir}/create_gcov %{_bindir}/dump_gcov %{_bindir}/profile_merger +%{_bindir}/llvm_profile_diff +%{_bindir}/llvm_profile_merger +%{_bindir}/llvm_sample_merger +%{_bindir}/create_llvm_prof %changelog +* Tue Apr 29 2025 xiajingze - 0.30.1-6 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC: Add LLVM tools build + * Wed Mar 12 2025 Funda Wang - 0.30.1-5 - sync abseil-cpp tarball with abseil-cpp package diff --git a/llvm-project.tar.xz b/llvm-project.tar.xz new file mode 100644 index 0000000000000000000000000000000000000000..eee05e3569e284ee8a0318f276f37bc962c1a0cf --- /dev/null +++ b/llvm-project.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3fcbf99103a940e7f0ac8a2aa7a6c1c0bb158c127a1901a2c31b41b10ae7e28 +size 137185064