[PATCH] D120850: [BOLT] Handle ifuncs trampolines for aarch64
Vladislav Khmelevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 8 15:02:32 PST 2022
This revision was automatically updated to reflect the committed changes.
yota9 marked an inline comment as done.
Closed by commit rG8bdbcfe7d8b0: [BOLT] Handle ifuncs trampolines for aarch64 (authored by yota9).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120850/new/
https://reviews.llvm.org/D120850
Files:
bolt/include/bolt/Rewrite/RewriteInstance.h
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/runtime/AArch64/iplt.c
Index: bolt/test/runtime/AArch64/iplt.c
===================================================================
--- /dev/null
+++ bolt/test/runtime/AArch64/iplt.c
@@ -0,0 +1,29 @@
+// This test checks that the ifuncs works after bolt.
+
+// RUN: %clang %cflags %s -fuse-ld=lld \
+// 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 | FileCheck %s
+
+// CHECK: foo
+
+#include <stdio.h>
+#include <string.h>
+
+static void foo() { printf("foo\n"); }
+
+static void *resolver_foo(void) { return foo; }
+
+__attribute__((ifunc("resolver_foo"))) void ifoo();
+
+static void *resolver_memcpy(void) { return memcpy; }
+
+__attribute__((ifunc("resolver_memcpy"))) void *
+imemcpy(void *dest, const void *src, size_t n);
+
+int main() {
+ int a = 0xdeadbeef, b = 0;
+ ifoo();
+ imemcpy(&b, &a, sizeof(b));
+ return a != b;
+}
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1251,19 +1251,30 @@
if (!TargetAddress)
return;
+ auto setPLTSymbol = [&](BinaryFunction *BF, StringRef Name) {
+ const unsigned PtrSize = BC->AsmInfo->getCodePointerSize();
+ MCSymbol *TargetSymbol = BC->registerNameAtAddress(
+ Name.str() + "@GOT", TargetAddress, PtrSize, PtrSize);
+ BF->setPLTSymbol(TargetSymbol);
+ };
+
+ BinaryFunction *BF = BC->getBinaryFunctionAtAddress(EntryAddress);
+ if (BF && BC->isAArch64()) {
+ // Handle IFUNC trampoline
+ setPLTSymbol(BF, BF->getOneName());
+ return;
+ }
+
const Relocation *Rel = BC->getDynamicRelocationAt(TargetAddress);
if (!Rel || !Rel->Symbol)
return;
- const unsigned PtrSize = BC->AsmInfo->getCodePointerSize();
ErrorOr<BinarySection &> Section = BC->getSectionForAddress(EntryAddress);
assert(Section && "cannot get section for address");
- BinaryFunction *BF = BC->createBinaryFunction(
- Rel->Symbol->getName().str() + "@PLT", *Section, EntryAddress, 0,
- EntrySize, Section->getAlignment());
- MCSymbol *TargetSymbol = BC->registerNameAtAddress(
- Rel->Symbol->getName().str() + "@GOT", TargetAddress, PtrSize, PtrSize);
- BF->setPLTSymbol(TargetSymbol);
+ BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT", *Section,
+ EntryAddress, 0, EntrySize,
+ Section->getAlignment());
+ setPLTSymbol(BF, Rel->Symbol->getName());
}
void RewriteInstance::disassemblePLTSectionAArch64(BinarySection &Section) {
Index: bolt/include/bolt/Rewrite/RewriteInstance.h
===================================================================
--- bolt/include/bolt/Rewrite/RewriteInstance.h
+++ bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -498,7 +498,8 @@
};
/// AArch64 PLT sections.
- const PLTSectionInfo AArch64_PLTSections[2] = {{".plt"}, {nullptr}};
+ const PLTSectionInfo AArch64_PLTSections[3] = {
+ {".plt"}, {".iplt"}, {nullptr}};
/// Return PLT information for a section with \p SectionName or nullptr
/// if the section is not PLT.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120850.413945.patch
Type: text/x-patch
Size: 3152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220308/0a5b98a9/attachment.bin>
More information about the llvm-commits
mailing list