2018-06-14 02:45:25 +08:00
|
|
|
//===-- Hexagon.cpp -------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2018-06-14 02:45:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "Symbols.h"
|
2018-09-28 22:09:16 +08:00
|
|
|
#include "SyntheticSections.h"
|
2018-06-14 02:45:25 +08:00
|
|
|
#include "Target.h"
|
|
|
|
#include "lld/Common/ErrorHandler.h"
|
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
using namespace llvm::support::endian;
|
|
|
|
using namespace llvm::ELF;
|
2019-10-07 16:31:18 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2018-06-14 02:45:25 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
class Hexagon final : public TargetInfo {
|
|
|
|
public:
|
2018-09-21 00:32:19 +08:00
|
|
|
Hexagon();
|
2018-06-14 02:45:25 +08:00
|
|
|
uint32_t calcEFlags() const override;
|
|
|
|
RelExpr getRelExpr(RelType type, const Symbol &s,
|
|
|
|
const uint8_t *loc) const override;
|
2019-08-16 23:35:02 +08:00
|
|
|
RelType getDynRel(RelType type) const override;
|
2020-01-23 13:39:16 +08:00
|
|
|
void relocate(uint8_t *loc, const Relocation &rel,
|
|
|
|
uint64_t val) const override;
|
2018-09-28 22:09:16 +08:00
|
|
|
void writePltHeader(uint8_t *buf) const override;
|
2019-12-18 05:43:04 +08:00
|
|
|
void writePlt(uint8_t *buf, const Symbol &sym,
|
|
|
|
uint64_t pltEntryAddr) const override;
|
2018-06-14 02:45:25 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2018-09-21 00:32:19 +08:00
|
|
|
Hexagon::Hexagon() {
|
2018-09-28 22:09:16 +08:00
|
|
|
pltRel = R_HEX_JMP_SLOT;
|
|
|
|
relativeRel = R_HEX_RELATIVE;
|
2018-10-04 22:54:17 +08:00
|
|
|
gotRel = R_HEX_GLOB_DAT;
|
2019-06-11 20:59:30 +08:00
|
|
|
symbolicRel = R_HEX_32;
|
2019-05-31 18:35:45 +08:00
|
|
|
|
2018-10-04 22:54:17 +08:00
|
|
|
// The zero'th GOT entry is reserved for the address of _DYNAMIC. The
|
|
|
|
// next 3 are reserved for the dynamic loader.
|
|
|
|
gotPltHeaderEntriesNum = 4;
|
|
|
|
|
2018-09-28 22:09:16 +08:00
|
|
|
pltEntrySize = 16;
|
|
|
|
pltHeaderSize = 32;
|
|
|
|
|
2018-09-21 00:32:19 +08:00
|
|
|
// Hexagon Linux uses 64K pages by default.
|
|
|
|
defaultMaxPageSize = 0x10000;
|
2018-09-26 16:11:34 +08:00
|
|
|
noneRel = R_HEX_NONE;
|
2020-01-03 02:54:59 +08:00
|
|
|
tlsGotRel = R_HEX_TPREL_32;
|
2020-01-11 01:58:21 +08:00
|
|
|
tlsModuleIndexRel = R_HEX_DTPMOD_32;
|
|
|
|
tlsOffsetRel = R_HEX_DTPREL_32;
|
2018-09-21 00:32:19 +08:00
|
|
|
}
|
|
|
|
|
2018-10-15 22:44:52 +08:00
|
|
|
uint32_t Hexagon::calcEFlags() const {
|
|
|
|
assert(!objectFiles.empty());
|
|
|
|
|
|
|
|
// The architecture revision must always be equal to or greater than
|
|
|
|
// greatest revision in the list of inputs.
|
|
|
|
uint32_t ret = 0;
|
|
|
|
for (InputFile *f : objectFiles) {
|
|
|
|
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader()->e_flags;
|
|
|
|
if (eflags > ret)
|
|
|
|
ret = eflags;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2018-06-14 02:45:25 +08:00
|
|
|
|
2018-06-14 03:50:10 +08:00
|
|
|
static uint32_t applyMask(uint32_t mask, uint32_t data) {
|
2018-06-14 02:45:25 +08:00
|
|
|
uint32_t result = 0;
|
|
|
|
size_t off = 0;
|
|
|
|
|
|
|
|
for (size_t bit = 0; bit != 32; ++bit) {
|
|
|
|
uint32_t valBit = (data >> off) & 1;
|
|
|
|
uint32_t maskBit = (mask >> bit) & 1;
|
|
|
|
if (maskBit) {
|
|
|
|
result |= (valBit << bit);
|
|
|
|
++off;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,
|
2018-06-14 03:49:58 +08:00
|
|
|
const uint8_t *loc) const {
|
2018-06-14 02:45:25 +08:00
|
|
|
switch (type) {
|
2019-08-19 22:07:14 +08:00
|
|
|
case R_HEX_NONE:
|
|
|
|
return R_NONE;
|
|
|
|
case R_HEX_6_X:
|
|
|
|
case R_HEX_8_X:
|
|
|
|
case R_HEX_9_X:
|
|
|
|
case R_HEX_10_X:
|
|
|
|
case R_HEX_11_X:
|
|
|
|
case R_HEX_12_X:
|
|
|
|
case R_HEX_16_X:
|
|
|
|
case R_HEX_32:
|
|
|
|
case R_HEX_32_6_X:
|
|
|
|
case R_HEX_HI16:
|
|
|
|
case R_HEX_LO16:
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_DTPREL_32:
|
2019-08-19 22:07:14 +08:00
|
|
|
return R_ABS;
|
2018-08-26 05:25:35 +08:00
|
|
|
case R_HEX_B9_PCREL:
|
2018-08-26 07:16:37 +08:00
|
|
|
case R_HEX_B13_PCREL:
|
2018-07-20 04:27:43 +08:00
|
|
|
case R_HEX_B15_PCREL:
|
2018-09-28 22:09:16 +08:00
|
|
|
case R_HEX_6_PCREL_X:
|
2018-10-02 02:27:26 +08:00
|
|
|
case R_HEX_32_PCREL:
|
2018-09-28 22:09:16 +08:00
|
|
|
return R_PC;
|
2019-10-08 22:23:49 +08:00
|
|
|
case R_HEX_B9_PCREL_X:
|
|
|
|
case R_HEX_B15_PCREL_X:
|
2018-06-14 02:45:25 +08:00
|
|
|
case R_HEX_B22_PCREL:
|
2018-10-02 02:27:26 +08:00
|
|
|
case R_HEX_PLT_B22_PCREL:
|
2018-07-20 03:10:56 +08:00
|
|
|
case R_HEX_B22_PCREL_X:
|
|
|
|
case R_HEX_B32_PCREL_X:
|
2018-09-28 22:09:16 +08:00
|
|
|
return R_PLT_PC;
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_32_6_X:
|
|
|
|
case R_HEX_IE_16_X:
|
|
|
|
case R_HEX_IE_HI16:
|
|
|
|
case R_HEX_IE_LO16:
|
|
|
|
return R_GOT;
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_GD_GOT_11_X:
|
|
|
|
case R_HEX_GD_GOT_16_X:
|
|
|
|
case R_HEX_GD_GOT_32_6_X:
|
|
|
|
return R_TLSGD_GOTPLT;
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_11_X:
|
|
|
|
case R_HEX_GOTREL_16_X:
|
|
|
|
case R_HEX_GOTREL_32_6_X:
|
|
|
|
case R_HEX_GOTREL_HI16:
|
|
|
|
case R_HEX_GOTREL_LO16:
|
|
|
|
return R_GOTPLTREL;
|
2018-10-04 22:54:17 +08:00
|
|
|
case R_HEX_GOT_11_X:
|
2018-10-08 23:32:46 +08:00
|
|
|
case R_HEX_GOT_16_X:
|
2018-10-04 22:54:17 +08:00
|
|
|
case R_HEX_GOT_32_6_X:
|
2019-08-17 01:01:56 +08:00
|
|
|
return R_GOTPLT;
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_GOT_11_X:
|
|
|
|
case R_HEX_IE_GOT_16_X:
|
|
|
|
case R_HEX_IE_GOT_32_6_X:
|
|
|
|
case R_HEX_IE_GOT_HI16:
|
|
|
|
case R_HEX_IE_GOT_LO16:
|
|
|
|
config->hasStaticTlsModel = true;
|
|
|
|
return R_GOTPLT;
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_11_X:
|
|
|
|
case R_HEX_TPREL_16:
|
|
|
|
case R_HEX_TPREL_16_X:
|
|
|
|
case R_HEX_TPREL_32_6_X:
|
|
|
|
case R_HEX_TPREL_HI16:
|
|
|
|
case R_HEX_TPREL_LO16:
|
|
|
|
return R_TLS;
|
2018-06-14 02:45:25 +08:00
|
|
|
default:
|
2019-08-19 22:07:14 +08:00
|
|
|
error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
|
|
|
|
") against symbol " + toString(s));
|
|
|
|
return R_NONE;
|
2018-06-14 02:45:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 20:00:10 +08:00
|
|
|
static uint32_t findMaskR6(uint32_t insn) {
|
|
|
|
// There are (arguably too) many relocation masks for the DSP's
|
|
|
|
// R_HEX_6_X type. The table below is used to select the correct mask
|
|
|
|
// for the given instruction.
|
|
|
|
struct InstructionMask {
|
|
|
|
uint32_t cmpMask;
|
|
|
|
uint32_t relocMask;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const InstructionMask r6[] = {
|
|
|
|
{0x38000000, 0x0000201f}, {0x39000000, 0x0000201f},
|
|
|
|
{0x3e000000, 0x00001f80}, {0x3f000000, 0x00001f80},
|
|
|
|
{0x40000000, 0x000020f8}, {0x41000000, 0x000007e0},
|
|
|
|
{0x42000000, 0x000020f8}, {0x43000000, 0x000007e0},
|
|
|
|
{0x44000000, 0x000020f8}, {0x45000000, 0x000007e0},
|
|
|
|
{0x46000000, 0x000020f8}, {0x47000000, 0x000007e0},
|
|
|
|
{0x6a000000, 0x00001f80}, {0x7c000000, 0x001f2000},
|
|
|
|
{0x9a000000, 0x00000f60}, {0x9b000000, 0x00000f60},
|
|
|
|
{0x9c000000, 0x00000f60}, {0x9d000000, 0x00000f60},
|
|
|
|
{0x9f000000, 0x001f0100}, {0xab000000, 0x0000003f},
|
|
|
|
{0xad000000, 0x0000003f}, {0xaf000000, 0x00030078},
|
|
|
|
{0xd7000000, 0x006020e0}, {0xd8000000, 0x006020e0},
|
|
|
|
{0xdb000000, 0x006020e0}, {0xdf000000, 0x006020e0}};
|
|
|
|
|
|
|
|
// Duplex forms have a fixed mask and parse bits 15:14 are always
|
|
|
|
// zero. Non-duplex insns will always have at least one bit set in the
|
|
|
|
// parse field.
|
|
|
|
if ((0xC000 & insn) == 0x0)
|
|
|
|
return 0x03f00000;
|
|
|
|
|
|
|
|
for (InstructionMask i : r6)
|
|
|
|
if ((0xff000000 & insn) == i.cmpMask)
|
|
|
|
return i.relocMask;
|
|
|
|
|
|
|
|
error("unrecognized instruction for R_HEX_6 relocation: 0x" +
|
|
|
|
utohexstr(insn));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:48:40 +08:00
|
|
|
static uint32_t findMaskR8(uint32_t insn) {
|
|
|
|
if ((0xff000000 & insn) == 0xde000000)
|
|
|
|
return 0x00e020e8;
|
|
|
|
if ((0xff000000 & insn) == 0x3c000000)
|
|
|
|
return 0x0000207f;
|
|
|
|
return 0x00001fe0;
|
|
|
|
}
|
|
|
|
|
2018-08-27 20:55:28 +08:00
|
|
|
static uint32_t findMaskR11(uint32_t insn) {
|
|
|
|
if ((0xff000000 & insn) == 0xa1000000)
|
|
|
|
return 0x060020ff;
|
|
|
|
return 0x06003fe0;
|
|
|
|
}
|
|
|
|
|
2018-08-22 23:25:15 +08:00
|
|
|
static uint32_t findMaskR16(uint32_t insn) {
|
|
|
|
if ((0xff000000 & insn) == 0x48000000)
|
|
|
|
return 0x061f20ff;
|
|
|
|
if ((0xff000000 & insn) == 0x49000000)
|
|
|
|
return 0x061f3fe0;
|
|
|
|
if ((0xff000000 & insn) == 0x78000000)
|
|
|
|
return 0x00df3fe0;
|
|
|
|
if ((0xff000000 & insn) == 0xb0000000)
|
|
|
|
return 0x0fe03fe0;
|
|
|
|
|
|
|
|
error("unrecognized instruction for R_HEX_16_X relocation: 0x" +
|
|
|
|
utohexstr(insn));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:45:25 +08:00
|
|
|
static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }
|
|
|
|
|
2020-01-23 13:39:16 +08:00
|
|
|
void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
|
|
|
|
uint64_t val) const {
|
|
|
|
switch (rel.type) {
|
2018-06-14 02:45:25 +08:00
|
|
|
case R_HEX_NONE:
|
|
|
|
break;
|
2018-08-09 20:00:10 +08:00
|
|
|
case R_HEX_6_PCREL_X:
|
|
|
|
case R_HEX_6_X:
|
|
|
|
or32le(loc, applyMask(findMaskR6(read32le(loc)), val));
|
|
|
|
break;
|
2018-08-11 05:48:40 +08:00
|
|
|
case R_HEX_8_X:
|
|
|
|
or32le(loc, applyMask(findMaskR8(read32le(loc)), val));
|
|
|
|
break;
|
2018-08-27 20:55:28 +08:00
|
|
|
case R_HEX_9_X:
|
|
|
|
or32le(loc, applyMask(0x00003fe0, val & 0x3f));
|
|
|
|
break;
|
|
|
|
case R_HEX_10_X:
|
|
|
|
or32le(loc, applyMask(0x00203fe0, val & 0x3f));
|
|
|
|
break;
|
|
|
|
case R_HEX_11_X:
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_GD_GOT_11_X:
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_GOT_11_X:
|
2018-10-04 22:54:17 +08:00
|
|
|
case R_HEX_GOT_11_X:
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_11_X:
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_11_X:
|
2018-08-27 20:55:28 +08:00
|
|
|
or32le(loc, applyMask(findMaskR11(read32le(loc)), val & 0x3f));
|
|
|
|
break;
|
2018-07-29 19:59:38 +08:00
|
|
|
case R_HEX_12_X:
|
|
|
|
or32le(loc, applyMask(0x000007e0, val));
|
|
|
|
break;
|
2018-10-08 23:32:46 +08:00
|
|
|
case R_HEX_16_X: // These relocs only have 6 effective bits.
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_16_X:
|
|
|
|
case R_HEX_IE_GOT_16_X:
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_GD_GOT_16_X:
|
2018-10-08 23:32:46 +08:00
|
|
|
case R_HEX_GOT_16_X:
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_16_X:
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_16_X:
|
2018-08-22 23:25:15 +08:00
|
|
|
or32le(loc, applyMask(findMaskR16(read32le(loc)), val & 0x3f));
|
|
|
|
break;
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_16:
|
|
|
|
or32le(loc, applyMask(findMaskR16(read32le(loc)), val & 0xffff));
|
|
|
|
break;
|
2018-08-14 21:52:38 +08:00
|
|
|
case R_HEX_32:
|
2018-10-02 02:27:26 +08:00
|
|
|
case R_HEX_32_PCREL:
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_DTPREL_32:
|
2018-08-20 14:33:29 +08:00
|
|
|
or32le(loc, val);
|
2018-08-14 21:52:38 +08:00
|
|
|
break;
|
2018-07-29 19:59:38 +08:00
|
|
|
case R_HEX_32_6_X:
|
2020-01-11 01:58:21 +08:00
|
|
|
case R_HEX_GD_GOT_32_6_X:
|
2018-10-04 22:54:17 +08:00
|
|
|
case R_HEX_GOT_32_6_X:
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_32_6_X:
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_GOT_32_6_X:
|
|
|
|
case R_HEX_IE_32_6_X:
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_32_6_X:
|
2018-07-29 19:59:38 +08:00
|
|
|
or32le(loc, applyMask(0x0fff3fff, val >> 6));
|
|
|
|
break;
|
2018-08-26 05:25:35 +08:00
|
|
|
case R_HEX_B9_PCREL:
|
2020-01-23 13:39:16 +08:00
|
|
|
checkInt(loc, val, 11, rel);
|
2018-08-26 05:25:35 +08:00
|
|
|
or32le(loc, applyMask(0x003000fe, val >> 2));
|
|
|
|
break;
|
|
|
|
case R_HEX_B9_PCREL_X:
|
|
|
|
or32le(loc, applyMask(0x003000fe, val & 0x3f));
|
|
|
|
break;
|
2018-08-26 07:16:37 +08:00
|
|
|
case R_HEX_B13_PCREL:
|
2020-01-23 13:39:16 +08:00
|
|
|
checkInt(loc, val, 15, rel);
|
2018-08-26 07:16:37 +08:00
|
|
|
or32le(loc, applyMask(0x00202ffe, val >> 2));
|
|
|
|
break;
|
2018-07-20 04:27:43 +08:00
|
|
|
case R_HEX_B15_PCREL:
|
2020-01-23 13:39:16 +08:00
|
|
|
checkInt(loc, val, 17, rel);
|
2018-07-20 04:27:43 +08:00
|
|
|
or32le(loc, applyMask(0x00df20fe, val >> 2));
|
|
|
|
break;
|
2018-07-24 23:08:13 +08:00
|
|
|
case R_HEX_B15_PCREL_X:
|
|
|
|
or32le(loc, applyMask(0x00df20fe, val & 0x3f));
|
|
|
|
break;
|
2018-06-14 02:45:25 +08:00
|
|
|
case R_HEX_B22_PCREL:
|
2018-10-02 02:27:26 +08:00
|
|
|
case R_HEX_PLT_B22_PCREL:
|
2020-01-23 13:39:16 +08:00
|
|
|
checkInt(loc, val, 22, rel);
|
2018-06-14 03:58:33 +08:00
|
|
|
or32le(loc, applyMask(0x1ff3ffe, val >> 2));
|
2018-06-14 02:45:25 +08:00
|
|
|
break;
|
2018-07-20 03:10:56 +08:00
|
|
|
case R_HEX_B22_PCREL_X:
|
|
|
|
or32le(loc, applyMask(0x1ff3ffe, val & 0x3f));
|
|
|
|
break;
|
|
|
|
case R_HEX_B32_PCREL_X:
|
|
|
|
or32le(loc, applyMask(0x0fff3fff, val >> 6));
|
|
|
|
break;
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_HI16:
|
2018-08-10 04:04:53 +08:00
|
|
|
case R_HEX_HI16:
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_GOT_HI16:
|
|
|
|
case R_HEX_IE_HI16:
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_HI16:
|
2018-08-10 04:04:53 +08:00
|
|
|
or32le(loc, applyMask(0x00c03fff, val >> 16));
|
|
|
|
break;
|
2019-08-19 21:32:32 +08:00
|
|
|
case R_HEX_GOTREL_LO16:
|
2018-08-10 04:04:53 +08:00
|
|
|
case R_HEX_LO16:
|
2020-01-03 02:54:59 +08:00
|
|
|
case R_HEX_IE_GOT_LO16:
|
|
|
|
case R_HEX_IE_LO16:
|
2020-01-03 00:27:05 +08:00
|
|
|
case R_HEX_TPREL_LO16:
|
2018-08-10 04:04:53 +08:00
|
|
|
or32le(loc, applyMask(0x00c03fff, val));
|
|
|
|
break;
|
2018-06-14 02:45:25 +08:00
|
|
|
default:
|
2019-08-19 22:07:14 +08:00
|
|
|
llvm_unreachable("unknown relocation");
|
2018-06-14 02:45:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:09:16 +08:00
|
|
|
void Hexagon::writePltHeader(uint8_t *buf) const {
|
|
|
|
const uint8_t pltData[] = {
|
|
|
|
0x00, 0x40, 0x00, 0x00, // { immext (#0)
|
|
|
|
0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # @GOT0
|
|
|
|
0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn
|
|
|
|
0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2
|
|
|
|
0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) }# dynamic link at GOT1
|
|
|
|
0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn
|
|
|
|
0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker
|
|
|
|
0x0c, 0xdb, 0x00, 0x54, // trap0(#0xdb) # bring plt0 into 16byte alignment
|
|
|
|
};
|
|
|
|
memcpy(buf, pltData, sizeof(pltData));
|
|
|
|
|
2018-10-10 04:29:24 +08:00
|
|
|
// Offset from PLT0 to the GOT.
|
|
|
|
uint64_t off = in.gotPlt->getVA() - in.plt->getVA();
|
2020-01-23 13:39:16 +08:00
|
|
|
relocateNoSym(buf, R_HEX_B32_PCREL_X, off);
|
|
|
|
relocateNoSym(buf + 4, R_HEX_6_PCREL_X, off);
|
2018-09-28 22:09:16 +08:00
|
|
|
}
|
2018-10-10 04:29:24 +08:00
|
|
|
|
2019-12-18 05:43:04 +08:00
|
|
|
void Hexagon::writePlt(uint8_t *buf, const Symbol &sym,
|
|
|
|
uint64_t pltEntryAddr) const {
|
2018-09-28 22:09:16 +08:00
|
|
|
const uint8_t inst[] = {
|
|
|
|
0x00, 0x40, 0x00, 0x00, // { immext (#0)
|
|
|
|
0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) }
|
|
|
|
0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14)
|
|
|
|
0x00, 0xc0, 0x9c, 0x52, // jumpr r28
|
|
|
|
};
|
|
|
|
memcpy(buf, inst, sizeof(inst));
|
|
|
|
|
2019-12-18 05:43:04 +08:00
|
|
|
uint64_t gotPltEntryAddr = sym.getGotPltVA();
|
2020-01-23 13:39:16 +08:00
|
|
|
relocateNoSym(buf, R_HEX_B32_PCREL_X, gotPltEntryAddr - pltEntryAddr);
|
|
|
|
relocateNoSym(buf + 4, R_HEX_6_PCREL_X, gotPltEntryAddr - pltEntryAddr);
|
2018-09-28 22:09:16 +08:00
|
|
|
}
|
|
|
|
|
2019-08-16 23:35:02 +08:00
|
|
|
RelType Hexagon::getDynRel(RelType type) const {
|
|
|
|
if (type == R_HEX_32)
|
|
|
|
return type;
|
|
|
|
return R_HEX_NONE;
|
|
|
|
}
|
|
|
|
|
2019-10-07 16:31:18 +08:00
|
|
|
TargetInfo *getHexagonTargetInfo() {
|
2018-06-14 02:45:25 +08:00
|
|
|
static Hexagon target;
|
|
|
|
return ⌖
|
|
|
|
}
|
2019-10-07 16:31:18 +08:00
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|