aboutsummaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Profile/DataAggregator.h3
-rw-r--r--bolt/lib/Core/Relocation.cpp8
-rw-r--r--bolt/lib/Profile/DataAggregator.cpp39
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp14
-rw-r--r--bolt/test/AArch64/missing-code-marker.s26
-rw-r--r--bolt/test/X86/debug-fission-single-convert.s5
-rw-r--r--bolt/test/X86/debug-fission-single.s5
-rw-r--r--bolt/test/X86/inlined-function-mixed.test6
8 files changed, 77 insertions, 29 deletions
diff --git a/bolt/include/bolt/Profile/DataAggregator.h b/bolt/include/bolt/Profile/DataAggregator.h
index db0f690..cb1b87f 100644
--- a/bolt/include/bolt/Profile/DataAggregator.h
+++ b/bolt/include/bolt/Profile/DataAggregator.h
@@ -502,6 +502,9 @@ private:
/// entries).
void imputeFallThroughs();
+ /// Register profiled functions for lite mode.
+ void registerProfiledFunctions();
+
/// Debugging dump methods
void dump() const;
void dump(const PerfBranchSample &Sample) const;
diff --git a/bolt/lib/Core/Relocation.cpp b/bolt/lib/Core/Relocation.cpp
index f099dfa..f882627 100644
--- a/bolt/lib/Core/Relocation.cpp
+++ b/bolt/lib/Core/Relocation.cpp
@@ -1018,7 +1018,7 @@ void Relocation::print(raw_ostream &OS) const {
OS << "RType:" << Twine::utohexstr(Type);
break;
- case Triple::aarch64:
+ case Triple::aarch64: {
static const char *const AArch64RelocNames[] = {
#define ELF_RELOC(name, value) #name,
#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
@@ -1026,7 +1026,7 @@ void Relocation::print(raw_ostream &OS) const {
};
assert(Type < ArrayRef(AArch64RelocNames).size());
OS << AArch64RelocNames[Type];
- break;
+ } break;
case Triple::riscv64:
// RISC-V relocations are not sequentially numbered so we cannot use an
@@ -1043,7 +1043,7 @@ void Relocation::print(raw_ostream &OS) const {
}
break;
- case Triple::x86_64:
+ case Triple::x86_64: {
static const char *const X86RelocNames[] = {
#define ELF_RELOC(name, value) #name,
#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
@@ -1051,7 +1051,7 @@ void Relocation::print(raw_ostream &OS) const {
};
assert(Type < ArrayRef(X86RelocNames).size());
OS << X86RelocNames[Type];
- break;
+ } break;
}
OS << ", 0x" << Twine::utohexstr(Offset);
if (Symbol) {
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 3604fdd..c13fa6d 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -581,6 +581,26 @@ void DataAggregator::imputeFallThroughs() {
outs() << "BOLT-INFO: imputed " << InferredTraces << " traces\n";
}
+void DataAggregator::registerProfiledFunctions() {
+ DenseSet<uint64_t> Addrs;
+ for (const auto &Trace : llvm::make_first_range(Traces)) {
+ if (Trace.Branch != Trace::FT_ONLY &&
+ Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)
+ Addrs.insert(Trace.Branch);
+ Addrs.insert(Trace.From);
+ }
+
+ for (const auto [PC, _] : BasicSamples)
+ Addrs.insert(PC);
+
+ for (const PerfMemSample &MemSample : MemSamples)
+ Addrs.insert(MemSample.PC);
+
+ for (const uint64_t Addr : Addrs)
+ if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr))
+ Func->setHasProfileAvailable();
+}
+
Error DataAggregator::preprocessProfile(BinaryContext &BC) {
this->BC = &BC;
@@ -603,6 +623,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
exit(0);
}
+ registerProfiledFunctions();
return Error::success();
}
@@ -1347,10 +1368,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
}
const uint64_t FromOffset = Addr[0]->Offset;
- BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(FromOffset);
- if (FromFunc)
- FromFunc->setHasProfileAvailable();
-
int64_t Count = Counters[0];
int64_t Mispreds = Counters[1];
@@ -1361,11 +1378,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
return std::error_code();
}
- const uint64_t ToOffset = Addr[1]->Offset;
- BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(ToOffset);
- if (ToFunc)
- ToFunc->setHasProfileAvailable();
-
/// For fall-through types, adjust locations to match Trace container.
if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
Addr[2] = Location(Addr[1]->Offset); // Trace To
@@ -1613,9 +1625,6 @@ std::error_code DataAggregator::parseBranchEvents() {
Traces.reserve(TraceMap.size());
for (const auto &[Trace, Info] : TraceMap) {
Traces.emplace_back(Trace, Info);
- for (const uint64_t Addr : {Trace.Branch, Trace.From})
- if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
- BF->setHasProfileAvailable();
}
clear(TraceMap);
@@ -1676,9 +1685,6 @@ std::error_code DataAggregator::parseBasicEvents() {
continue;
++NumTotalSamples;
- if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
- BF->setHasProfileAvailable();
-
++BasicSamples[Sample->PC];
EventNames.insert(Sample->EventName);
}
@@ -1716,9 +1722,6 @@ std::error_code DataAggregator::parseMemEvents() {
if (std::error_code EC = Sample.getError())
return EC;
- if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
- BF->setHasProfileAvailable();
-
MemSamples.emplace_back(std::move(Sample.get()));
}
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 9f243a1..fe4a23c 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -896,6 +896,20 @@ void RewriteInstance::discoverFileObjects() {
continue;
MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
+
+ // Treat ST_Function as code.
+ Expected<object::SymbolRef::Type> TypeOrError = SymInfo.Symbol.getType();
+ consumeError(TypeOrError.takeError());
+ if (TypeOrError && *TypeOrError == SymbolRef::ST_Function) {
+ if (IsData) {
+ Expected<StringRef> NameOrError = SymInfo.Symbol.getName();
+ consumeError(NameOrError.takeError());
+ BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
+ << " lacks code marker\n";
+ }
+ MarkerType = MarkerSymType::CODE;
+ }
+
if (MarkerType != MarkerSymType::NONE) {
SortedMarkerSymbols.push_back(MarkerSym{SymInfo.Address, MarkerType});
LastAddr = SymInfo.Address;
diff --git a/bolt/test/AArch64/missing-code-marker.s b/bolt/test/AArch64/missing-code-marker.s
new file mode 100644
index 0000000..591c9ab
--- /dev/null
+++ b/bolt/test/AArch64/missing-code-marker.s
@@ -0,0 +1,26 @@
+## Check that llvm-bolt is able to recover a missing code marker.
+
+# RUN: %clang %cflags %s -o %t.exe -nostdlib -fuse-ld=lld -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+
+# CHECK: BOLT-WARNING: function symbol foo lacks code marker
+
+.text
+.balign 4
+
+.word 0
+
+## Function foo starts immediately after a data object and does not have
+## a matching "$x" symbol to indicate the start of code.
+.global foo
+.type foo, %function
+foo:
+ .word 0xd65f03c0
+.size foo, .-foo
+
+.global _start
+.type _start, %function
+_start:
+ bl foo
+ ret
+.size _start, .-_start
diff --git a/bolt/test/X86/debug-fission-single-convert.s b/bolt/test/X86/debug-fission-single-convert.s
index 02c92902..ea05ccd 100644
--- a/bolt/test/X86/debug-fission-single-convert.s
+++ b/bolt/test/X86/debug-fission-single-convert.s
@@ -14,14 +14,15 @@
# RUN: -nostartfiles \
# RUN: -Wl,--script=%p/Inputs/debug-fission-script.txt \
# RUN: %t.o -o %t.exe
+# RUN: mkdir -p %t.dwarf-output
# RUN: llvm-bolt %t.exe \
# RUN: --reorder-blocks=reverse \
# RUN: --update-debug-sections \
-# RUN: --dwarf-output-path=%T \
+# RUN: --dwarf-output-path=%t.dwarf-output \
# RUN: --always-convert-to-ranges=true \
# RUN: -o %t.bolt.1.exe 2>&1 | FileCheck %s
# RUN: llvm-dwarfdump --show-form --verbose --debug-ranges %t.bolt.1.exe &> %tAddrIndexTest
-# RUN: not llvm-dwarfdump --show-form --verbose --debug-info %T/debug-fission-simple-convert.dwo0.dwo >> %tAddrIndexTest
+# RUN: not llvm-dwarfdump --show-form --verbose --debug-info %t.dwarf-output/debug-fission-simple-convert.dwo0.dwo >> %tAddrIndexTest
# RUN: cat %tAddrIndexTest | FileCheck %s --check-prefix=CHECK-DWO-DWO
# RUN: llvm-dwarfdump --show-form --verbose --debug-addr %t.bolt.1.exe | FileCheck %s --check-prefix=CHECK-ADDR-SEC
diff --git a/bolt/test/X86/debug-fission-single.s b/bolt/test/X86/debug-fission-single.s
index 1aa502f..7ff53df 100644
--- a/bolt/test/X86/debug-fission-single.s
+++ b/bolt/test/X86/debug-fission-single.s
@@ -14,13 +14,14 @@
# RUN: -nostartfiles \
# RUN: -Wl,--script=%p/Inputs/debug-fission-script.txt \
# RUN: %t.o -o %t.exe
+# RUN: mkdir -p %t.dwarf-output
# RUN: llvm-bolt %t.exe \
# RUN: --reorder-blocks=reverse \
# RUN: --update-debug-sections \
-# RUN: --dwarf-output-path=%T \
+# RUN: --dwarf-output-path=%t.dwarf-output \
# RUN: -o %t.bolt.1.exe 2>&1 | FileCheck %s
# RUN: llvm-dwarfdump --show-form --verbose --debug-ranges %t.bolt.1.exe &> %tAddrIndexTest
-# RUN: llvm-dwarfdump --show-form --verbose --debug-info %T/debug-fission-simple.dwo0.dwo >> %tAddrIndexTest
+# RUN: llvm-dwarfdump --show-form --verbose --debug-info %t.dwarf-output/debug-fission-simple.dwo0.dwo >> %tAddrIndexTest
# RUN: cat %tAddrIndexTest | FileCheck %s --check-prefix=CHECK-DWO-DWO
# RUN: llvm-dwarfdump --show-form --verbose --debug-addr %t.bolt.1.exe | FileCheck %s --check-prefix=CHECK-ADDR-SEC
diff --git a/bolt/test/X86/inlined-function-mixed.test b/bolt/test/X86/inlined-function-mixed.test
index 9f6ef39..4fc1594 100644
--- a/bolt/test/X86/inlined-function-mixed.test
+++ b/bolt/test/X86/inlined-function-mixed.test
@@ -1,9 +1,9 @@
## Make sure inlining from a unit with debug info into unit without
## debug info does not cause a crash.
-RUN: %clangxx %cxxflags %S/Inputs/inlined.cpp -c -o %T/inlined.o
-RUN: %clangxx %cxxflags %S/Inputs/inlinee.cpp -c -o %T/inlinee.o -g
-RUN: %clangxx %cxxflags %T/inlined.o %T/inlinee.o -o %t
+RUN: %clangxx %cxxflags %S/Inputs/inlined.cpp -c -o %t.inlined.o
+RUN: %clangxx %cxxflags %S/Inputs/inlinee.cpp -c -o %t.inlinee.o -g
+RUN: %clangxx %cxxflags %t.inlined.o %t.inlinee.o -o %t
RUN: llvm-bolt %t -o %t.bolt --update-debug-sections --reorder-blocks=reverse \
RUN: --inline-small-functions --force-inline=main | FileCheck %s