Index: lib/ReaderWriter/ELF/Hexagon/HexagonRelocationFunctions.h =================================================================== --- lib/ReaderWriter/ELF/Hexagon/HexagonRelocationFunctions.h +++ lib/ReaderWriter/ELF/Hexagon/HexagonRelocationFunctions.h @@ -6,9 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + #ifndef LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_RELOCATION_FUNCTIONS_H #define LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_RELOCATION_FUNCTIONS_H +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Endian.h" + namespace lld { namespace elf { @@ -22,23 +26,16 @@ #include "HexagonEncodings.h" -#define FINDV4BITMASK(INSN) \ - findBitMask((uint32_t) * ((llvm::support::ulittle32_t *) INSN), \ - insn_encodings, \ - sizeof(insn_encodings) / sizeof(Instruction)) - /// \brief finds the scatter Bits that need to be used to apply relocations -inline uint32_t -findBitMask(uint32_t insn, Instruction *encodings, int32_t numInsns) { - for (int32_t i = 0; i < numInsns; i++) { - if (((insn & 0xc000) == 0) && !(encodings[i].isDuplex)) +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) && (encodings[i].isDuplex)) + if (((insn & 0xc000) != 0) && (insn_encodings[i].isDuplex)) continue; - - if (((encodings[i].insnMask) & insn) == encodings[i].insnCmpMask) - return encodings[i].insnBitMask; + if (((insn_encodings[i].insnMask) & insn) == insn_encodings[i].insnCmpMask) + return insn_encodings[i].insnBitMask; } llvm_unreachable("found unknown instruction"); } Index: lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp =================================================================== --- lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp +++ lib/ReaderWriter/ELF/Hexagon/HexagonRelocationHandler.cpp @@ -26,7 +26,7 @@ int32_t result = (uint32_t)(((S + A) - P) >> 2); int32_t range = 1 << nBits; if (result < range && result > -range) { - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -81,7 +81,7 @@ int32_t result = ((S + A - P) & 0x3f); int32_t range = 1 << nbits; if (result < range && result > -range) { - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -92,7 +92,7 @@ static int relocHex6PCRELX(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { int32_t result = (S + A - P); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -100,7 +100,7 @@ // R_HEX_N_X : Word32_U6 : (S + A) : Unsigned Truncate static int relocHex_N_X(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) { uint32_t result = (S + A); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -111,7 +111,7 @@ int32_t result = (int64_t)((S + A - GP) >> nShiftBits); int32_t range = 1L << 16; if (result <= range) { - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -146,7 +146,7 @@ int32_t result = (int32_t)(GOT-A); int32_t range = 1L << 16; if (result <= range) { - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -155,7 +155,7 @@ static int relocHexGOT32_6_X(uint8_t *location, uint64_t A, uint64_t GOT) { int32_t result = (int32_t)((A-GOT) >> 6); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -164,7 +164,7 @@ int32_t result = (int32_t)(A-GOT); int32_t range = 1L << 6; if (result <= range) { - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -173,7 +173,7 @@ static int relocHexGOT11_X(uint8_t *location, uint64_t A, uint64_t GOT) { uint32_t result = (uint32_t)(A-GOT); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -181,7 +181,7 @@ static int relocHexGOTRELSigned(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, uint64_t GOT, int shiftBits = 0) { int32_t result = (int32_t)((S + A - GOT) >> shiftBits); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; } @@ -189,7 +189,7 @@ static int relocHexGOTRELUnsigned(uint8_t *location, uint64_t P, uint64_t S, uint64_t A, uint64_t GOT, int shiftBits = 0) { uint32_t result = (uint32_t)((S + A - GOT) >> shiftBits); - result = lld::scatterBits(result, FINDV4BITMASK(location)); + result = lld::scatterBits(result, findv4bitmask(location)); APPLY_RELOC(result); return 0; }