[PATCH] D122039: [BOLT] Fix plt relocations symbol match

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 13:57:41 PDT 2022


yota9 created this revision.
yota9 added reviewers: maksfb, rafauler, Amir.
Herald added a subscriber: ayermolo.
Herald added a project: All.
yota9 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The BFD linkeradds the symbol versioning string to the symbol name in symbtab.
Skip the versioning part in order to find the registered PLT function.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122039

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/runtime/AArch64/plt.c


Index: bolt/test/runtime/AArch64/plt.c
===================================================================
--- bolt/test/runtime/AArch64/plt.c
+++ bolt/test/runtime/AArch64/plt.c
@@ -1,6 +1,8 @@
 // This test checks that the pointers to PLT are properly updated.
+// Use bfd linker since it may add versioning string to the symbol
+// names in symbtab.
 
-// RUN: %clang %cflags %s -fuse-ld=lld \
+// RUN: %clang %cflags %s -fuse-ld=bfd \
 // RUN:    -o %t.exe -Wl,-q
 // RUN: llvm-bolt %t.exe -o %t.bolt.exe -use-old-text=0 -lite=0
 // RUN: %t.bolt.exe
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1885,6 +1885,13 @@
     // Check for PLT entry registered with symbol name
     if (!SymbolAddress && IsAArch64) {
       BinaryData *BD = BC->getBinaryDataByName(SymbolName + "@PLT");
+      size_t End;
+      if ((!BD) && ((End = SymbolName.find("@")) != std::string::npos)) {
+        // The symbol might contain its versioning in name
+        SymbolName = SymbolName.substr(0, End);
+        BD = BC->getBinaryDataByName(SymbolName + "@PLT");
+      }
+
       SymbolAddress = BD ? BD->getAddress() : 0;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122039.416602.patch
Type: text/x-patch
Size: 1273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220318/13dc60d1/attachment.bin>


More information about the llvm-commits mailing list