diff options
author | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-20 15:31:16 +0300 |
---|---|---|
committer | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-31 22:28:50 +0300 |
commit | fed958c6cc596e53971fca0e884b33483a85c12e (patch) | |
tree | dc21703adfa2a91df883bcc7f7855b760e24247e /bolt | |
parent | 1c5663458bbbee05e3312e9682f18e526b4750d1 (diff) |
[BOLT] AArch64: Emit text objects
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
Differential Revision: https://reviews.llvm.org/D122097
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/lib/Core/BinaryEmitter.cpp | 2 | ||||
-rw-r--r-- | bolt/lib/Passes/Aligner.cpp | 14 | ||||
-rw-r--r-- | bolt/test/AArch64/text-data.c | 22 |
3 files changed, 37 insertions, 1 deletions
diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp index 914549651fe7..f923f6f28ade 100644 --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -277,7 +277,7 @@ void BinaryEmitter::emitFunctions() { } 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) diff --git a/bolt/lib/Passes/Aligner.cpp b/bolt/lib/Passes/Aligner.cpp index cae0570a2922..89e787737866 100644 --- a/bolt/lib/Passes/Aligner.cpp +++ b/bolt/lib/Passes/Aligner.cpp @@ -172,6 +172,20 @@ void AlignerPass::runOnFunctions(BinaryContext &BC) { else alignMaxBytes(BF); + // Align objects that contains constant islands and no code + // to at least 8 bytes. + if (!BF.size() && BF.hasIslandsInfo()) { + const uint16_t Alignment = BF.getConstantIslandAlignment(); + if (BF.getAlignment() < Alignment) + BF.setAlignment(Alignment); + + if (BF.getMaxAlignmentBytes() < Alignment) + BF.setMaxAlignmentBytes(Alignment); + + if (BF.getMaxColdAlignmentBytes() < Alignment) + BF.setMaxColdAlignmentBytes(Alignment); + } + if (opts::AlignBlocks && !opts::PreserveBlocksAlignment) alignBlocks(BF, Emitter.MCE.get()); }; diff --git a/bolt/test/AArch64/text-data.c b/bolt/test/AArch64/text-data.c new file mode 100644 index 000000000000..bd633d0dc34f --- /dev/null +++ b/bolt/test/AArch64/text-data.c @@ -0,0 +1,22 @@ +// 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: 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; +} |