diff options
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h | 36 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp | 29 |
2 files changed, 37 insertions, 28 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h index d7831533aee..6af43d88afb 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h @@ -6,6 +6,25 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/ErrorHandling.h" + +namespace lld { +namespace elf { + +/// \brief Applying fixup on Hexagon requires the relocator to fetch the fixup +/// mask from the instruction. To fetch the fixup encoding, the linker uses a +/// static array that contains the instruction mask, the compare mask and the +/// relocation mask. +typedef struct { + uint32_t insnMask; // Instruction mask. + uint32_t insnCmpMask; // Compare mask. + uint32_t insnBitMask; // Relocation mask. + bool isDuplex; // Indicates if the instruction is a duplex instruction. +} Instruction; + Instruction insn_encodings[] = { // InsnMask CompareMask BitMask IsDuplexInstruction { 0xffe00004, 0x40000000, 0x20f8, 0x0 }, @@ -600,3 +619,20 @@ Instruction insn_encodings[] = { { 0xff602060, 0x3f000060, 0x1f80, 0x0 }, { 0xf7c02000, 0x11000000, 0x3000fe, 0x0 }, }; + +/// \brief finds the scatter Bits that need to be used to apply relocations +inline uint32_t findv4bitmask(uint8_t *location) { + uint32_t insn = llvm::support::endian::read32le(location); + for (int32_t i = 0, e = llvm::array_lengthof(insn_encodings); i < e; i++) { + if ((insn & 0xc000) == 0 && !insn_encodings[i].isDuplex) + continue; + if ((insn & 0xc000) != 0 && insn_encodings[i].isDuplex) + continue; + if ((insn_encodings[i].insnMask & insn) == insn_encodings[i].insnCmpMask) + return insn_encodings[i].insnBitMask; + } + llvm_unreachable("found unknown Hexagon instruction"); +} + +} // namespace elf +} // namespace lld diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp index fc7ab1ebb77..0a201b32b5f 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// +#include "HexagonEncodings.h" #include "HexagonLinkingContext.h" #include "HexagonRelocationHandler.h" #include "HexagonTargetHandler.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Endian.h" using namespace lld; @@ -18,33 +18,6 @@ using namespace lld::elf; using namespace llvm::ELF; using namespace llvm::support::endian; -/// \brief Applying fixup on Hexagon requires the relocator to fetch the fixup -/// mask from the instruction. To fetch the fixup encoding, the linker uses a -/// static array that contains the instruction mask, the compare mask and the -/// relocation mask. -typedef struct { - uint32_t insnMask; // Instruction mask. - uint32_t insnCmpMask; // Compare mask. - uint32_t insnBitMask; // Relocation mask. - bool isDuplex; // Indicates if the instruction is a duplex instruction. -} Instruction; - -#include "HexagonEncodings.h" - -/// \brief finds the scatter Bits that need to be used to apply relocations -inline uint32_t findv4bitmask(uint8_t *location) { - uint32_t insn = llvm::support::endian::read32le(location); - for (int32_t i = 0, e = llvm::array_lengthof(insn_encodings); i < e; i++) { - if ((insn & 0xc000) == 0 && !insn_encodings[i].isDuplex) - continue; - if ((insn & 0xc000) != 0 && insn_encodings[i].isDuplex) - continue; - if ((insn_encodings[i].insnMask & insn) == insn_encodings[i].insnCmpMask) - return insn_encodings[i].insnBitMask; - } - llvm_unreachable("found unknown Hexagon instruction"); -} - // Scatter val's bits as specified by the mask. Example: // // Val: 0bABCDEFG |

