Compare commits

..

No commits in common. "b8e810229cf8ea4a992a056a893d1a3f64785fe7" and "cf08a58b300e7ad74ba3839248f0f70cd4d22fee" have entirely different histories.

8 changed files with 137 additions and 82 deletions

View File

@ -0,0 +1,109 @@
From 963d19d86cca708957055f3072cbe8473c8e52e3 Mon Sep 17 00:00:00 2001
From: xiongzhou4 <xiongzhou4@huawei.com>
Date: Thu, 15 Jun 2023 20:34:42 +0800
Subject: [PATCH] [Backport] [BOLT] [AArch64] Handle data at the beginning of a
function when disassembling and building CFG.
---
bolt/src/BinaryFunction.cpp | 11 +++++++----
bolt/src/BinaryFunction.h | 9 +++++++++
bolt/src/Exceptions.cpp | 2 +-
bolt/test/AArch64/data-at-0-offset.c | 17 +++++++++++++++++
4 files changed, 34 insertions(+), 5 deletions(-)
create mode 100644 bolt/test/AArch64/data-at-0-offset.c
diff --git a/bolt/src/BinaryFunction.cpp b/bolt/src/BinaryFunction.cpp
index 9414b83ad..93de63d3f 100644
--- a/bolt/src/BinaryFunction.cpp
+++ b/bolt/src/BinaryFunction.cpp
@@ -1445,6 +1445,9 @@ add_instruction:
addInstruction(Offset, std::move(Instruction));
}
+ if (uint64_t Offset = getFirstInstructionOffset())
+ Labels[Offset] = BC.Ctx->createNamedTempSymbol();
+
clearList(Relocations);
if (!IsSimple) {
@@ -1987,7 +1990,7 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
return false;
assert(BasicBlocks.empty() && "basic block list should be empty");
- assert((Labels.find(0) != Labels.end()) &&
+ assert((Labels.find(getFirstInstructionOffset()) != Labels.end()) &&
"first instruction should always have a label");
// Create basic blocks in the original layout order:
@@ -2087,9 +2090,9 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
updateOffset(LastInstrOffset);
}
}
- if (Offset == 0) {
- // Add associated CFI pseudos in the first offset (0)
- addCFIPlaceholders(0, InsertBB);
+ if (Offset == getFirstInstructionOffset()) {
+ // Add associated CFI pseudos in the first offset.
+ addCFIPlaceholders(Offset, InsertBB);
}
const bool IsBlockEnd = MIB->isTerminator(Instr);
diff --git a/bolt/src/BinaryFunction.h b/bolt/src/BinaryFunction.h
index a824f3d58..3b435cfb3 100644
--- a/bolt/src/BinaryFunction.h
+++ b/bolt/src/BinaryFunction.h
@@ -967,6 +967,15 @@ public:
return const_cast<BinaryFunction *>(this)->getInstructionAtOffset(Offset);
}
+ /// Return offset for the first instruction. If there is data at the
+ /// beginning of a function then offset of the first instruction could
+ /// be different from 0.
+ uint64_t getFirstInstructionOffset() const {
+ if (Instructions.empty())
+ return 0;
+ return Instructions.begin()->first;
+ }
+
/// Return jump table that covers a given \p Address in memory.
JumpTable *getJumpTableContainingAddress(uint64_t Address) {
auto JTI = JumpTables.upper_bound(Address);
diff --git a/bolt/src/Exceptions.cpp b/bolt/src/Exceptions.cpp
index f73054aa8..0a64e3fca 100644
--- a/bolt/src/Exceptions.cpp
+++ b/bolt/src/Exceptions.cpp
@@ -499,7 +499,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
Optional<uint64_t> LSDA = CurFDE.getLSDAAddress();
Function.setLSDAAddress(LSDA ? *LSDA : 0);
- uint64_t Offset = 0;
+ uint64_t Offset = Function.getFirstInstructionOffset();
uint64_t CodeAlignment = CurFDE.getLinkedCIE()->getCodeAlignmentFactor();
uint64_t DataAlignment = CurFDE.getLinkedCIE()->getDataAlignmentFactor();
if (CurFDE.getLinkedCIE()->getPersonalityAddress()) {
diff --git a/bolt/test/AArch64/data-at-0-offset.c b/bolt/test/AArch64/data-at-0-offset.c
new file mode 100644
index 000000000..e0c689a19
--- /dev/null
+++ b/bolt/test/AArch64/data-at-0-offset.c
@@ -0,0 +1,17 @@
+// RUN: %clang %cflags -O2 -fPIE -Wl,-q -pie %s -o %t.exe
+// RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+// CHECK-NOT: BOLT-WARNING: unable to disassemble instruction at offset
+
+void extra_space() {
+ asm volatile(".rept 256\n"
+ " .byte 0xff\n"
+ ".endr\n");
+ return;
+}
+
+int main(int argc, char **argv) {
+ void (*fn)(void);
+ fn = extra_space + 256;
+ fn();
+ return 0;
+}
--
2.33.0

View File

@ -1,22 +1,9 @@
# llvm-bolt-latest
# llvm-bolt
#### Description
llvm-bolt is a post-link optimizer developed to speed up large applications
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
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.
#### Contribution

View File

@ -1,23 +1,9 @@
# llvm-bolt-latest
# llvm-bolt
#### 介绍
llvm-bolt is a post-link optimizer developed to speed up large applications
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
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.
#### 参与贡献

View File

@ -1,31 +1,28 @@
%bcond_without sys_llvm
%bcond_with check
%bcond_without toolchain_clang
%if %{with toolchain_clang}
%global toolchain clang
%endif
%global maj_ver 18
%global min_ver 1
%global patch_ver 8
%global maj_ver 17
%global min_ver 0
%global patch_ver 6
%global bolt_version %{maj_ver}.%{min_ver}.%{patch_ver}
%global bolt_srcdir llvm-project-%{bolt_version}.src
%global _scl_prefix /opt/openEuler
%{?scl:%scl_package %scl}
%{!?scl:%global scl_prefix llvm-toolset-%{maj_ver}-}
%{!?scl:%global pkg_name %{name}}
%global install_prefix %{!?scl:%{_scl_prefix}/llvm-toolset-%{maj_ver}/root}%{_prefix}
%global install_datadir %{!?scl:%{_scl_prefix}/llvm-toolset-%{maj_ver}/root}%{_datadir}
%if %{with sys_llvm}
%global pkg_name llvm-bolt
%global install_prefix %{_prefix}
%else
%global pkg_name llvm-bolt%{maj_ver}
%global install_prefix %{_libdir}/llvm%{maj_ver}
%endif
%global install_bindir %{install_prefix}/bin
%global install_libdir %{install_prefix}/lib
%global install_docdir %{install_prefix}/share/doc
%global max_link_jobs 2
Name: %{?scl_prefix}llvm-bolt
Name: %{pkg_name}
Version: %{bolt_version}
Release: 2
Release: 1
Summary: BOLT is a post-link optimizer developed to speed up large applications
License: Apache 2.0
URL: https://github.com/llvm/llvm-project/tree/main/bolt
@ -46,11 +43,6 @@ BuildRequires: zlib-devel
BuildRequires: python3-lit
BuildRequires: python3-psutil
BuildRequires: doxygen
%if %{with toolchain_clang}
BuildRequires: clang
%endif
%{?scl:Requires: %scl_runtime}
%description
BOLT is a post-link optimizer developed to speed up large applications.
@ -60,8 +52,8 @@ on execution profile gathered by sampling profiler, such as Linux perf tool.
%package doc
Summary: Documentation for BOLT
BuildArch: noarch
Requires: %{pkg_name} = %{version}-%{release}
Requires: %{name} = %{version}-%{release}
%description doc
Documentation for the BOLT optimizer
@ -85,10 +77,6 @@ Documentation for the BOLT optimizer
-DLLVM_EXTERNAL_LIT=%{_bindir}/lit \
-DLLVM_ENABLE_PROJECTS="bolt" \
-DLLVM_PARALLEL_LINK_JOBS=%{max_link_jobs} \
%if "%{toolchain}" == "clang"
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
%endif
%ifarch %ix86 x86_64
-DLLVM_TARGETS_TO_BUILD="X86"
%endif
@ -147,30 +135,19 @@ rm -f %{buildroot}/%{_builddir}/%{bolt_srcdir}/%{_vpath_builddir}/%{_lib}/lib*.a
%{install_bindir}/merge-fdata
%{install_bindir}/perf2bolt
%{install_bindir}/llvm-bolt-heatmap
%ifnarch riscv64
%ifarch x86_64
%{install_libdir}/libbolt_rt_hugify.a
%{install_libdir}/libbolt_rt_instr.a
%endif
%exclude %{_builddir}/%{bolt_srcdir}/lib/*
%files doc
%doc %{install_docdir}
%changelog
* Mon Dec 23 2024 laokz <zhangkai@iscas.ac.cn> - 18.1.8-2
- riscv64: not package non-exist .a files
* Fri Dec 6 2024 liyunfei <liyunfei33@huawei.com> - 18.1.8-1
- init for Multi-Version LLVM-18.1.8
* Tue Nov 12 2024 Funda Wang <fundawang@yeah.net> - 17.0.6-3
- adopt to new cmake macro
- build with gcc now, as llvm/clang will produce linking error
against libLLVMTableGen.a now
* Fri Jul 5 2024 liyunfei <liyunfei33@huawei.com> - 17.0.6-2
- Add toolchain_clang build support
* Mon Dec 4 2023 zhoujing <zhoujing106@huawei.com> 17.0.6-1
- Update to 17.0.6
@ -190,4 +167,4 @@ rm -f %{buildroot}/%{_builddir}/%{bolt_srcdir}/%{_vpath_builddir}/%{_lib}/lib*.a
- Type:Init
- ID:NA
- SUG:NA
- DESC:Init llvm-bolt repository
- DESC:Init llvm-bolt repository

View File

@ -1,4 +0,0 @@
version_control: github
src_repo: llvm/llvm-project
tag_prefix: ^llvmorg-
separator: .

Binary file not shown.

Binary file not shown.