[PATCH] D122097: [BOLT] AArch64: Emit text objects
Vladislav Khmelevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 20 05:34:19 PDT 2022
yota9 created this revision.
yota9 added reviewers: maksfb, rafauler, Amir.
Herald added subscribers: ayermolo, kristof.beyls.
Herald added a project: All.
yota9 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
BOLT treats aarch64 objects located in text as empty functions with
contant islands. Emit them with at least 8-byte alignment to the new
text section.
Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122097
Files:
bolt/lib/Core/BinaryEmitter.cpp
bolt/lib/Passes/Aligner.cpp
bolt/test/runtime/AArch64/text_data.c
Index: bolt/test/runtime/AArch64/text_data.c
===================================================================
--- /dev/null
+++ bolt/test/runtime/AArch64/text_data.c
@@ -0,0 +1,23 @@
+// This test checks that the data object located in text section
+// is properly emitted in the new section.
+
+// RUN: %clang %cflags %s -o %t.exe -Wl,-q
+// RUN: llvm-bolt %t.exe -o %t.bolt -lite=0 -use-old-text=0
+// RUN: %t.bolt
+// RUN: llvm-objdump -j .text -d --disassemble-symbols=arr %t.bolt | \
+// RUN: FileCheck %s
+
+// CHECK: {{.*}} <arr>:
+
+#include <stdlib.h>
+
+typedef void (*FooPtr)();
+
+void exitOk() { exit(0); }
+
+__attribute__((section(".text"))) const FooPtr arr[] = {exitOk, NULL};
+
+int main() {
+ arr[0]();
+ return -1;
+}
Index: bolt/lib/Passes/Aligner.cpp
===================================================================
--- bolt/lib/Passes/Aligner.cpp
+++ bolt/lib/Passes/Aligner.cpp
@@ -172,6 +172,19 @@
else
alignMaxBytes(BF);
+ // Align objects that contains constant islands and no code
+ // to at least 8 bytes.
+ if (!BF.size() && BF.hasIslandsInfo()) {
+ if (BF.getAlignment() < sizeof(uint64_t))
+ BF.setAlignment(sizeof(uint64_t));
+
+ if (BF.getMaxAlignmentBytes() < sizeof(uint64_t))
+ BF.setMaxAlignmentBytes(sizeof(uint64_t));
+
+ if (BF.getMaxColdAlignmentBytes() < sizeof(uint64_t))
+ BF.setMaxColdAlignmentBytes(sizeof(uint64_t));
+ }
+
if (opts::AlignBlocks && !opts::PreserveBlocksAlignment)
alignBlocks(BF, Emitter.MCE.get());
};
Index: bolt/lib/Core/BinaryEmitter.cpp
===================================================================
--- bolt/lib/Core/BinaryEmitter.cpp
+++ bolt/lib/Core/BinaryEmitter.cpp
@@ -277,7 +277,7 @@
}
bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
- if (Function.size() == 0)
+ if (Function.size() == 0 && !Function.hasIslandsInfo())
return false;
if (Function.getState() == BinaryFunction::State::Empty)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122097.416771.patch
Type: text/x-patch
Size: 2008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220320/97b8ccab/attachment.bin>
More information about the llvm-commits
mailing list