[PATCH] D135121: [BOLT] Properly set _end symbol
Maksim Panchenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 7 11:19:31 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc683e281cdc9: [BOLT] Properly set _end symbol (authored by maksfb).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135121/new/
https://reviews.llvm.org/D135121
Files:
bolt/lib/Core/BinaryEmitter.cpp
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/X86/end-symbol.test
Index: bolt/test/X86/end-symbol.test
===================================================================
--- /dev/null
+++ bolt/test/X86/end-symbol.test
@@ -0,0 +1,9 @@
+# RUN: yaml2obj %p/Inputs/plt-sec.yaml &> %t.exe
+# RUN: llvm-bolt %t.exe -o %t.out
+# RUN: (llvm-readelf --program-headers %t.out | tac ; llvm-nm %t.out) \
+# RUN: | FileCheck %s
+
+## Check that llvm-bolt correctly updates _end symbol to match the end of the
+## last loadable segment.
+CHECK: LOAD 0x[[#%x,OFFSET:]] 0x[[#%x,VMA:]] 0x[[#%x,PA:]] 0x[[#%x,FILESIZE:]] 0x[[#%x,MEMSIZE:]]
+CHECK: [[#%.16x, VMA + MEMSIZE]] {{.}} _end
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -4730,27 +4730,29 @@
Expected<StringRef> SymbolName = Symbol.getName(StringSection);
assert(SymbolName && "cannot get symbol name");
- auto updateSymbolValue = [&](const StringRef Name, unsigned &IsUpdated) {
- NewSymbol.st_value = getNewValueForSymbol(Name);
+ auto updateSymbolValue = [&](const StringRef Name,
+ Optional<uint64_t> Value = NoneType()) {
+ NewSymbol.st_value = Value ? *Value : getNewValueForSymbol(Name);
NewSymbol.st_shndx = ELF::SHN_ABS;
outs() << "BOLT-INFO: setting " << Name << " to 0x"
<< Twine::utohexstr(NewSymbol.st_value) << '\n';
- ++IsUpdated;
};
if (opts::HotText &&
- (*SymbolName == "__hot_start" || *SymbolName == "__hot_end"))
- updateSymbolValue(*SymbolName, NumHotTextSymsUpdated);
-
- if (opts::HotData &&
- (*SymbolName == "__hot_data_start" || *SymbolName == "__hot_data_end"))
- updateSymbolValue(*SymbolName, NumHotDataSymsUpdated);
+ (*SymbolName == "__hot_start" || *SymbolName == "__hot_end")) {
+ updateSymbolValue(*SymbolName);
+ ++NumHotTextSymsUpdated;
+ }
- if (*SymbolName == "_end") {
- unsigned Ignored;
- updateSymbolValue(*SymbolName, Ignored);
+ if (opts::HotData && (*SymbolName == "__hot_data_start" ||
+ *SymbolName == "__hot_data_end")) {
+ updateSymbolValue(*SymbolName);
+ ++NumHotDataSymsUpdated;
}
+ if (*SymbolName == "_end")
+ updateSymbolValue(*SymbolName, NextAvailableAddress);
+
if (IsDynSym)
Write((&Symbol - cantFail(Obj.symbols(&SymTabSection)).begin()) *
sizeof(ELFSymTy),
Index: bolt/lib/Core/BinaryEmitter.cpp
===================================================================
--- bolt/lib/Core/BinaryEmitter.cpp
+++ bolt/lib/Core/BinaryEmitter.cpp
@@ -211,8 +211,6 @@
}
emitDataSections(OrgSecPrefix);
-
- Streamer.emitLabel(BC.Ctx->getOrCreateSymbol("_end"));
}
void BinaryEmitter::emitFunctions() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135121.466128.patch
Type: text/x-patch
Size: 2843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/ea2231ee/attachment.bin>
More information about the llvm-commits
mailing list