Skip to content

Commit 04d1617

Browse files
author
git apple-llvm automerger
committed
Merge commit 'bb627b0a0c05' from llvm.org/main into next
2 parents a837fcf + bb627b0 commit 04d1617

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,6 +4808,40 @@ void RewriteInstance::updateELFSymbolTable(
48084808
// Create a new symbol based on the existing symbol.
48094809
ELFSymTy NewSymbol = Symbol;
48104810

4811+
// Handle special symbols based on their name.
4812+
Expected<StringRef> SymbolName = Symbol.getName(StringSection);
4813+
assert(SymbolName && "cannot get symbol name");
4814+
4815+
auto updateSymbolValue = [&](const StringRef Name,
4816+
std::optional<uint64_t> Value = std::nullopt) {
4817+
NewSymbol.st_value = Value ? *Value : getNewValueForSymbol(Name);
4818+
NewSymbol.st_shndx = ELF::SHN_ABS;
4819+
BC->outs() << "BOLT-INFO: setting " << Name << " to 0x"
4820+
<< Twine::utohexstr(NewSymbol.st_value) << '\n';
4821+
};
4822+
4823+
if (*SymbolName == "__hot_start" || *SymbolName == "__hot_end") {
4824+
if (opts::HotText) {
4825+
updateSymbolValue(*SymbolName);
4826+
++NumHotTextSymsUpdated;
4827+
}
4828+
goto registerSymbol;
4829+
}
4830+
4831+
if (*SymbolName == "__hot_data_start" || *SymbolName == "__hot_data_end") {
4832+
if (opts::HotData) {
4833+
updateSymbolValue(*SymbolName);
4834+
++NumHotDataSymsUpdated;
4835+
}
4836+
goto registerSymbol;
4837+
}
4838+
4839+
if (*SymbolName == "_end") {
4840+
if (NextAvailableAddress > Symbol.st_value)
4841+
updateSymbolValue(*SymbolName, NextAvailableAddress);
4842+
goto registerSymbol;
4843+
}
4844+
48114845
if (Function) {
48124846
// If the symbol matched a function that was not emitted, update the
48134847
// corresponding section index but otherwise leave it unchanged.
@@ -4904,33 +4938,7 @@ void RewriteInstance::updateELFSymbolTable(
49044938
}
49054939
}
49064940

4907-
// Handle special symbols based on their name.
4908-
Expected<StringRef> SymbolName = Symbol.getName(StringSection);
4909-
assert(SymbolName && "cannot get symbol name");
4910-
4911-
auto updateSymbolValue = [&](const StringRef Name,
4912-
std::optional<uint64_t> Value = std::nullopt) {
4913-
NewSymbol.st_value = Value ? *Value : getNewValueForSymbol(Name);
4914-
NewSymbol.st_shndx = ELF::SHN_ABS;
4915-
BC->outs() << "BOLT-INFO: setting " << Name << " to 0x"
4916-
<< Twine::utohexstr(NewSymbol.st_value) << '\n';
4917-
};
4918-
4919-
if (opts::HotText &&
4920-
(*SymbolName == "__hot_start" || *SymbolName == "__hot_end")) {
4921-
updateSymbolValue(*SymbolName);
4922-
++NumHotTextSymsUpdated;
4923-
}
4924-
4925-
if (opts::HotData && (*SymbolName == "__hot_data_start" ||
4926-
*SymbolName == "__hot_data_end")) {
4927-
updateSymbolValue(*SymbolName);
4928-
++NumHotDataSymsUpdated;
4929-
}
4930-
4931-
if (*SymbolName == "_end" && NextAvailableAddress > Symbol.st_value)
4932-
updateSymbolValue(*SymbolName, NextAvailableAddress);
4933-
4941+
registerSymbol:
49344942
if (IsDynSym)
49354943
Write((&Symbol - cantFail(Obj.symbols(&SymTabSection)).begin()) *
49364944
sizeof(ELFSymTy),

bolt/test/runtime/X86/hot-end-symbol.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q
1313

1414
# RUN: llvm-bolt %t.exe --relocs=1 --hot-text --reorder-functions=hfsort \
15+
# RUN: --split-functions --split-strategy=all \
1516
# RUN: --data %t.fdata -o %t.out | FileCheck %s
1617

1718
# RUN: %t.out 1
@@ -30,12 +31,12 @@
3031
# CHECK-OUTPUT: __hot_start
3132
# CHECK-OUTPUT-NEXT: main
3233
# CHECK-OUTPUT-NEXT: __hot_end
34+
# CHECK-OUTPUT-NOT: __hot_start.cold
3335

3436
.text
3537
.globl main
3638
.type main, %function
3739
.globl __hot_start
38-
.type __hot_start, %object
3940
.p2align 4
4041
main:
4142
__hot_start:

0 commit comments

Comments
 (0)