-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[BOLT][AArch64] Add symbolizer for AArch64 disassembler. NFCI #127969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //===- bolt/Target/AArch64/AArch64MCSymbolizer.cpp ------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "AArch64MCSymbolizer.h" | ||
| #include "bolt/Core/BinaryContext.h" | ||
| #include "bolt/Core/BinaryFunction.h" | ||
| #include "bolt/Core/MCPlusBuilder.h" | ||
| #include "bolt/Core/Relocation.h" | ||
| #include "llvm/MC/MCInst.h" | ||
| #include "llvm/MC/MCRegisterInfo.h" | ||
| #include "llvm/Support/Debug.h" | ||
|
|
||
| #define DEBUG_TYPE "bolt-symbolizer" | ||
|
|
||
| namespace llvm { | ||
| namespace bolt { | ||
|
|
||
| AArch64MCSymbolizer::~AArch64MCSymbolizer() {} | ||
|
|
||
| bool AArch64MCSymbolizer::tryAddingSymbolicOperand( | ||
| MCInst &Inst, raw_ostream &CStream, int64_t Value, uint64_t InstAddress, | ||
| bool IsBranch, uint64_t ImmOffset, uint64_t ImmSize, uint64_t InstSize) { | ||
| BinaryContext &BC = Function.getBinaryContext(); | ||
| MCContext *Ctx = BC.Ctx.get(); | ||
|
|
||
| // NOTE: the callee may incorrectly set IsBranch. | ||
| if (BC.MIB->isBranch(Inst) || BC.MIB->isCall(Inst)) | ||
| return false; | ||
|
|
||
| // TODO: add handling for linker "relaxation". At the moment, relocations | ||
| // corresponding to "relaxed" instructions are excluded from BinaryFunction | ||
| // relocation list. | ||
|
|
||
| const uint64_t InstOffset = InstAddress - Function.getAddress(); | ||
| const Relocation *Relocation = Function.getRelocationAt(InstOffset); | ||
|
|
||
| /// Add symbolic operand to the instruction with an optional addend. | ||
| auto addOperand = [&](const MCSymbol *Symbol, uint64_t Addend, | ||
| uint64_t RelType) { | ||
| const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, *Ctx); | ||
| if (Addend) | ||
| Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Addend, *Ctx), | ||
| *Ctx); | ||
| Inst.addOperand(MCOperand::createExpr( | ||
| BC.MIB->getTargetExprFor(Inst, Expr, *Ctx, RelType))); | ||
| }; | ||
|
|
||
| if (Relocation) { | ||
| addOperand(Relocation->Symbol, Relocation->Addend, Relocation->Type); | ||
| return true; | ||
| } | ||
|
|
||
| if (!BC.MIB->hasPCRelOperand(Inst)) | ||
| return false; | ||
|
|
||
| Value += InstAddress; | ||
| const MCSymbol *TargetSymbol; | ||
| uint64_t TargetOffset; | ||
| if (!CreateNewSymbols) { | ||
| if (BinaryData *BD = BC.getBinaryDataContainingAddress(Value)) { | ||
| TargetSymbol = BD->getSymbol(); | ||
| TargetOffset = Value - BD->getAddress(); | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| std::tie(TargetSymbol, TargetOffset) = | ||
| BC.handleAddressRef(Value, Function, /*IsPCRel*/ true); | ||
| } | ||
|
|
||
| addOperand(TargetSymbol, TargetOffset, 0); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void AArch64MCSymbolizer::tryAddingPcLoadReferenceComment(raw_ostream &CStream, | ||
| int64_t Value, | ||
| uint64_t Address) {} | ||
|
|
||
| } // namespace bolt | ||
| } // namespace llvm | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //===- bolt/Target/AArch64/AArch64MCSymbolizer.cpp --------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef BOLT_TARGET_AARCH64_AARCH64MCSYMBOLIZER_H | ||
| #define BOLT_TARGET_AARCH64_AARCH64MCSYMBOLIZER_H | ||
|
|
||
| #include "bolt/Core/BinaryFunction.h" | ||
| #include "llvm/MC/MCDisassembler/MCSymbolizer.h" | ||
|
|
||
| namespace llvm { | ||
| namespace bolt { | ||
|
|
||
| class AArch64MCSymbolizer : public MCSymbolizer { | ||
| protected: | ||
| BinaryFunction &Function; | ||
| bool CreateNewSymbols{true}; | ||
|
|
||
| public: | ||
| AArch64MCSymbolizer(BinaryFunction &Function, bool CreateNewSymbols = true) | ||
| : MCSymbolizer(*Function.getBinaryContext().Ctx.get(), nullptr), | ||
| Function(Function), CreateNewSymbols(CreateNewSymbols) {} | ||
|
|
||
| AArch64MCSymbolizer(const AArch64MCSymbolizer &) = delete; | ||
| AArch64MCSymbolizer &operator=(const AArch64MCSymbolizer &) = delete; | ||
| virtual ~AArch64MCSymbolizer(); | ||
|
|
||
| bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &CStream, | ||
| int64_t Value, uint64_t Address, bool IsBranch, | ||
| uint64_t Offset, uint64_t OpSize, | ||
| uint64_t InstSize) override; | ||
|
|
||
| void tryAddingPcLoadReferenceComment(raw_ostream &CStream, int64_t Value, | ||
| uint64_t Address) override; | ||
| }; | ||
|
|
||
| } // namespace bolt | ||
| } // namespace llvm | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ endif() | |
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On AArch64 I get linking errors. I believe on |
||
| add_llvm_library(LLVMBOLTTargetAArch64 | ||
| AArch64MCPlusBuilder.cpp | ||
| AArch64MCSymbolizer.cpp | ||
|
|
||
| NO_EXPORT | ||
| DISABLE_LLVM_LINK_LLVM_DYLIB | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE warns that this 'is not used directly'