[PATCH] D158910: [BOLT] Local hidden should be global syms
Rafael Auler via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 25 16:29:11 PDT 2023
rafauler created this revision.
rafauler added a reviewer: bolt.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
rafauler requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
Register all hidden local symbols as globals, since they are
still unique in the context of the input binary BOLT is
processing. This is used to fetch a single definition of
_GLOBAL_OFFSET_TABLE_.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158910
Files:
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/AArch64/array_end.c
Index: bolt/test/AArch64/array_end.c
===================================================================
--- bolt/test/AArch64/array_end.c
+++ bolt/test/AArch64/array_end.c
@@ -8,7 +8,7 @@
// RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm \
// RUN: --print-only="callFini" | FileCheck %s
-// CHECK: adr [[REG:x[0-28]+]], "__fini_array_end/1"
+// CHECK: adr [[REG:x[0-28]+]], __fini_array_end
__attribute__((destructor)) void destr() {}
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -766,6 +766,15 @@
}
};
std::unordered_map<SymbolRef, StringRef, SymbolRefHash> SymbolToFileName;
+ auto isSymbolGlobal = [](const ELFSymbolRef &Sym) {
+ if (cantFail(Sym.getFlags()) & SymbolRef::SF_Global)
+ return true;
+ // Hidden symbols are globals that were demoted to local at link-time.
+ // They should still be unique names at DSO-level.
+ if (cantFail(Sym.getFlags()) & SymbolRef::SF_Hidden)
+ return true;
+ return false;
+ };
for (const ELFSymbolRef &Symbol : InputFile->symbols()) {
Expected<StringRef> NameOrError = Symbol.getName();
if (NameOrError && NameOrError->startswith("__asan_init")) {
@@ -793,8 +802,7 @@
SeenFileName = true;
continue;
}
- if (!FileSymbolName.empty() &&
- !(cantFail(Symbol.getFlags()) & SymbolRef::SF_Global))
+ if (!FileSymbolName.empty() && !(isSymbolGlobal(Symbol)))
SymbolToFileName[Symbol] = FileSymbolName;
}
@@ -951,7 +959,7 @@
std::string AlternativeName;
if (Name.empty()) {
UniqueName = "ANONYMOUS." + std::to_string(AnonymousId++);
- } else if (cantFail(Symbol.getFlags()) & SymbolRef::SF_Global) {
+ } else if (isSymbolGlobal(Symbol)) {
if (const BinaryData *BD = BC->getBinaryDataByName(Name)) {
if (BD->getSize() == ELFSymbolRef(Symbol).getSize() &&
BD->getAddress() == Address) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158910.553665.patch
Type: text/x-patch
Size: 2028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230825/b673a422/attachment.bin>
More information about the llvm-commits
mailing list