blob: 0ffaddc36f0bb13c9063b47647ffd34f3579e591 [file] [log] [blame]
Rafael Espindola01205f72015-09-22 18:19:46 +00001//===- Target.h -------------------------------------------------*- C++ -*-===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLD_ELF_TARGET_H
11#define LLD_ELF_TARGET_H
12
Simon Atanasyan49829a12015-09-29 05:34:03 +000013#include "llvm/ADT/StringRef.h"
14
Rafael Espindola01205f72015-09-22 18:19:46 +000015#include <memory>
16
17namespace lld {
18namespace elf2 {
19class SymbolBody;
20
21class TargetInfo {
22public:
Hal Finkele3c26262015-10-08 22:23:54 +000023 unsigned getPageSize() const { return PageSize; }
Hal Finkel47290642015-10-08 21:25:04 +000024 uint64_t getVAStart() const { return VAStart; }
Rafael Espindola01205f72015-09-22 18:19:46 +000025 unsigned getPCRelReloc() const { return PCRelReloc; }
Rafael Espindola7f074422015-09-22 21:35:51 +000026 unsigned getGotReloc() const { return GotReloc; }
Rafael Espindolaae244002015-10-05 19:30:12 +000027 unsigned getGotRefReloc() const { return GotRefReloc; }
28 unsigned getRelativeReloc() const { return RelativeReloc; }
Hal Finkel6c2a3b82015-10-08 21:51:31 +000029 unsigned getPltEntrySize() const { return PltEntrySize; }
Rafael Espindola01205f72015-09-22 18:19:46 +000030 virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +000031 uint64_t PltEntryAddr) const = 0;
Rafael Espindolaae244002015-10-05 19:30:12 +000032 virtual bool isRelRelative(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000033 virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000034 virtual bool relocPointsToGot(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000035 virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0;
Hal Finkel87bbd5f2015-10-12 21:19:18 +000036 virtual void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
37 uint32_t Type, uint64_t BaseAddr,
38 uint64_t SymVA) const = 0;
Rafael Espindolac4010882015-09-22 20:54:08 +000039
Rafael Espindola01205f72015-09-22 18:19:46 +000040 virtual ~TargetInfo();
41
42protected:
Hal Finkele3c26262015-10-08 22:23:54 +000043 unsigned PageSize = 4096;
Hal Finkel47290642015-10-08 21:25:04 +000044 uint64_t VAStart;
Rafael Espindola01205f72015-09-22 18:19:46 +000045 unsigned PCRelReloc;
Rafael Espindola8acb95c2015-09-29 14:42:37 +000046 unsigned GotRefReloc;
Rafael Espindola7f074422015-09-22 21:35:51 +000047 unsigned GotReloc;
Rafael Espindolaae244002015-10-05 19:30:12 +000048 unsigned RelativeReloc;
Hal Finkel6c2a3b82015-10-08 21:51:31 +000049 unsigned PltEntrySize = 8;
Rafael Espindola01205f72015-09-22 18:19:46 +000050};
51
52class X86TargetInfo final : public TargetInfo {
53public:
54 X86TargetInfo();
55 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +000056 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000057 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000058 bool relocPointsToGot(uint32_t Type) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000059 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +000060 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
61 uint32_t Type, uint64_t BaseAddr,
62 uint64_t SymVA) const override;
Rafael Espindola01205f72015-09-22 18:19:46 +000063};
64
65class X86_64TargetInfo final : public TargetInfo {
66public:
67 X86_64TargetInfo();
68 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +000069 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000070 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
71 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +000072 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
73 uint32_t Type, uint64_t BaseAddr,
74 uint64_t SymVA) const override;
Rafael Espindolaae244002015-10-05 19:30:12 +000075 bool isRelRelative(uint32_t Type) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000076};
77
78class PPC64TargetInfo final : public TargetInfo {
79public:
80 PPC64TargetInfo();
81 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +000082 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000083 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
84 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +000085 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
86 uint32_t Type, uint64_t BaseAddr,
87 uint64_t SymVA) const override;
Hal Finkelbe0823d2015-10-12 20:58:52 +000088 bool isRelRelative(uint32_t Type) const override;
Rafael Espindola01205f72015-09-22 18:19:46 +000089};
90
Rafael Espindola1d6063e2015-09-22 21:24:52 +000091class PPCTargetInfo final : public TargetInfo {
92public:
93 PPCTargetInfo();
94 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +000095 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000096 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
97 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +000098 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
99 uint32_t Type, uint64_t BaseAddr,
100 uint64_t SymVA) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000101};
102
Davide Italianocde93362015-09-26 00:32:04 +0000103class AArch64TargetInfo final : public TargetInfo {
104public:
105 AArch64TargetInfo();
106 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +0000107 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000108 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
109 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +0000110 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
111 uint32_t Type, uint64_t BaseAddr,
112 uint64_t SymVA) const override;
Davide Italianocde93362015-09-26 00:32:04 +0000113};
114
Simon Atanasyan49829a12015-09-29 05:34:03 +0000115class MipsTargetInfo final : public TargetInfo {
116public:
117 MipsTargetInfo();
118 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
Rui Ueyamac58656c2015-10-13 16:59:30 +0000119 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000120 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
121 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Hal Finkel87bbd5f2015-10-12 21:19:18 +0000122 void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,
123 uint32_t Type, uint64_t BaseAddr,
124 uint64_t SymVA) const override;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000125};
126
Rafael Espindola01205f72015-09-22 18:19:46 +0000127extern std::unique_ptr<TargetInfo> Target;
Rui Ueyama91004392015-10-13 16:08:15 +0000128TargetInfo *createTarget();
Rafael Espindola01205f72015-09-22 18:19:46 +0000129}
130}
131
132#endif