diff --git a/.gitattributes b/.gitattributes index 6cb319c427c4fb206decb4753e6220dc11bc3fff..58b5017bb5b2bdb05734997a193c2d9e629029cb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ autofdo-0.30.1.tar.xz filter=lfs diff=lfs merge=lfs -text +llvm-project.tar.xz filter=lfs diff=lfs merge=lfs -text +protobuf-25.1.tar.gz filter=lfs diff=lfs merge=lfs -text diff --git a/0003-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch b/0003-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch new file mode 100644 index 0000000000000000000000000000000000000000..e7f0b0dfe90d3b1a545eb49e5e3821ba3d2319e6 --- /dev/null +++ b/0003-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/0004-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch b/0004-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch new file mode 100644 index 0000000000000000000000000000000000000000..ed65b38dd513d7ba55f407eafbf13584e9841438 --- /dev/null +++ b/0004-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/0005-Build-protobuf-from-source-directly.patch b/0005-Build-protobuf-from-source-directly.patch new file mode 100644 index 0000000000000000000000000000000000000000..f6cd0f4686b8d49cba2ac182311597d98e96c44a --- /dev/null +++ b/0005-Build-protobuf-from-source-directly.patch @@ -0,0 +1,59 @@ +From 54607a6b84a6bc47ccac96b392c9af537b0b61a6 Mon Sep 17 00:00:00 2001 +From: xiajingze +Date: Mon, 12 May 2025 19:01:58 +0800 +Subject: [PATCH] Build protobuf from source directly + +--- + CMakeLists.txt | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a38f8c11a..fd977950f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,13 +8,16 @@ if (NOT DEFINED BUILD_SHARED) + set(BUILD_SHARED FALSE) + endif() + +-if (NOT ${BUILD_SHARED}) +- set (Protobuf_USE_STATIC_LIBS TRUE) +-endif() ++set (Protobuf_USE_STATIC_LIBS TRUE) + + function (execute_perf_protobuf) + +- find_package(Protobuf REQUIRED) ++ set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disable protobuf tests") ++ set(protobuf_ABSL_PROVIDER module CACHE STRING "Use bundled abseil") ++ ++ add_subdirectory(third_party/protobuf) ++ include_directories(third_party/protobuf/src) ++ include(${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/cmake/protobuf-generate.cmake) + + add_library(perf_proto + third_party/perf_data_converter/src/quipper/perf_data.proto +@@ -26,7 +29,9 @@ function (execute_perf_protobuf) + endfunction() + + function (build_gcov) +- add_subdirectory(third_party/abseil) ++ if(NOT TARGET absl::strings) ++ add_subdirectory(third_party/abseil) ++ endif() + add_subdirectory(third_party/glog) + + include_directories(${CMAKE_HOME_DIRECTORY} +@@ -183,7 +188,9 @@ function (build_llvm) + set (LLVM_ENABLE_TERMINFO OFF CACHE BOOL "enable terminfo") + ### + +- add_subdirectory(third_party/abseil) ++ if(NOT TARGET absl::strings) ++ add_subdirectory(third_party/abseil) ++ endif() + add_subdirectory(third_party/glog) + add_subdirectory(third_party/googletest) + add_subdirectory(third_party/llvm-project/llvm) +-- +2.33.0 + diff --git a/abseil-cpp-20230802.1.tar.gz b/abseil-cpp-20230802.1.tar.gz deleted file mode 100644 index 397f6515d73a0678bbdb0db3051a451541d783ab..0000000000000000000000000000000000000000 Binary files a/abseil-cpp-20230802.1.tar.gz and /dev/null differ diff --git a/autofdo.spec b/autofdo.spec index 83426a26470e403e675dc2cc28d3f29a25e0d6cc..eee1e89d96e253b1f668d75ebf973cae8bd07fda 100644 --- a/autofdo.spec +++ b/autofdo.spec @@ -1,19 +1,24 @@ -%global abseil_version 20230802.1 +# Sync from llvm, disable LTO. +%define _lto_cflags %{nil} Name: autofdo Version: 0.30.1 -Release: 3 +Release: 4 Summary: A tool to convert perf.data profile to AutoFDO profile License: Apache-2.0 URL: https://github.com/google/autofdo # The package in the original url below contains GIT information which is useless, # 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 +Source1: protobuf-25.1.tar.gz +Source2: llvm-project.tar.xz Patch0: 0001-adjust-the-link-method-of-dependency-libraries.patch Patch1: 0002-DUMP_GCOV-Change-fatal-to-error-when-argc-not-equal-2.patch Patch2: 0002-unscaledcycleclock-remove-RISC-V-support.patch -BuildRequires: gcc gcc-c++ libtool git cmake elfutils-libelf-devel openssl-devel pkg-config ninja-build gtest libunwind-devel protobuf-devel chrpath +Patch3: 0003-Backport-Added-DBUILD_SHARED-On-Off-to-control-whether-to-bui.patch +Patch4: 0004-Rename-LLVM-tools-to-distinguish-them-from-GCOV-tool.patch +Patch5: 0005-Build-protobuf-from-source-directly.patch +BuildRequires: gcc gcc-c++ libtool git cmake elfutils-libelf-devel openssl-devel pkg-config ninja-build gtest libunwind-devel chrpath Requires: glibc openssl-libs elfutils libgcc libstdc++ zlib %description @@ -23,22 +28,31 @@ profile that can be used by GCC and LLVM. %prep %setup -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 +mv third_party/protobuf-25.1 third_party/protobuf %autopatch -p1 %build -cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=. -DENABLE_TOOL=GCOV -DBUILD_SHARED_LIBS=OFF ./ +# In-source builds are not allowed in llvm. +mkdir _build +cd _build +cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=. -DENABLE_TOOL=GCOV -DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED=ON -DABSL_ROOT_DIR=%{_builddir}/%{name}-%{version}/third_party/abseil ../ +%ninja_build +cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=. -DENABLE_TOOL=LLVM -DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED=ON -DABSL_ROOT_DIR=%{_builddir}/%{name}-%{version}/third_party/abseil ../ %ninja_build %install mkdir -p %{buildroot}%{_bindir} cd %{buildroot}%{_bindir} -cp %{_builddir}/%{name}-%{version}/create_gcov ./ -cp %{_builddir}/%{name}-%{version}/dump_gcov ./ -cp %{_builddir}/%{name}-%{version}/profile_merger ./ +cp %{_builddir}/%{name}-%{version}/_build/create_gcov ./ +cp %{_builddir}/%{name}-%{version}/_build/dump_gcov ./ +cp %{_builddir}/%{name}-%{version}/_build/profile_merger ./ +cp %{_builddir}/%{name}-%{version}/_build/llvm_profile_diff ./ +cp %{_builddir}/%{name}-%{version}/_build/llvm_profile_merger ./ +cp %{_builddir}/%{name}-%{version}/_build/llvm_sample_merger ./ +cp %{_builddir}/%{name}-%{version}/_build/create_llvm_prof ./ export QA_CHECK_RAPTH=0 @@ -46,8 +60,18 @@ export QA_CHECK_RAPTH=0 %{_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-4 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC: Add LLVM tools build + * Wed May 7 2025 liyunfei - 0.30.1-3 - Type:update - ID:NA 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 diff --git a/protobuf-25.1.tar.gz b/protobuf-25.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0c09a1c5b8e65517532d9ae7e56abe4d3fd5ae72 --- /dev/null +++ b/protobuf-25.1.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb44749949236b9460e8c79d312e177b672d4b09fd1ff3fc6a927c42a040ed4f +size 7081073