blob: 6c8d2ba29d0a196951e4215e4ce9169da4f497f3 [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:
Simon Atanasyan49829a12015-09-29 05:34:03 +000023 llvm::StringRef getDefaultEntry() const { return DefaultEntry; }
Hal Finkele3c26262015-10-08 22:23:54 +000024 unsigned getPageSize() const { return PageSize; }
Hal Finkel47290642015-10-08 21:25:04 +000025 uint64_t getVAStart() const { return VAStart; }
Rafael Espindola01205f72015-09-22 18:19:46 +000026 unsigned getPCRelReloc() const { return PCRelReloc; }
Rafael Espindola7f074422015-09-22 21:35:51 +000027 unsigned getGotReloc() const { return GotReloc; }
Rafael Espindolaae244002015-10-05 19:30:12 +000028 unsigned getGotRefReloc() const { return GotRefReloc; }
29 unsigned getRelativeReloc() const { return RelativeReloc; }
Hal Finkel6c2a3b82015-10-08 21:51:31 +000030 unsigned getPltEntrySize() const { return PltEntrySize; }
Rafael Espindola01205f72015-09-22 18:19:46 +000031 virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
32 uint64_t PltEntryAddr) const = 0;
Rafael Espindolaae244002015-10-05 19:30:12 +000033 virtual bool isRelRelative(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000034 virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000035 virtual bool relocPointsToGot(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000036 virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0;
Rafael Espindolac4010882015-09-22 20:54:08 +000037 virtual void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000038 uint64_t BaseAddr, 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;
Simon Atanasyan49829a12015-09-29 05:34:03 +000050 llvm::StringRef DefaultEntry = "_start";
Rafael Espindola01205f72015-09-22 18:19:46 +000051};
52
53class X86TargetInfo final : public TargetInfo {
54public:
55 X86TargetInfo();
56 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
57 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000058 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000059 bool relocPointsToGot(uint32_t Type) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000060 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000061 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000062 uint64_t BaseAddr, 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,
69 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;
Rafael Espindolac4010882015-09-22 20:54:08 +000072 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000073 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindolaae244002015-10-05 19:30:12 +000074 bool isRelRelative(uint32_t Type) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000075};
76
77class PPC64TargetInfo final : public TargetInfo {
78public:
79 PPC64TargetInfo();
80 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
81 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000082 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
83 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000084 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000085 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola01205f72015-09-22 18:19:46 +000086};
87
Rafael Espindola1d6063e2015-09-22 21:24:52 +000088class PPCTargetInfo final : public TargetInfo {
89public:
90 PPCTargetInfo();
91 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
92 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000093 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
94 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +000095 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000096 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +000097};
98
99class ARMTargetInfo final : public TargetInfo {
100public:
101 ARMTargetInfo();
102 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
103 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000104 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
105 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000106 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000107 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000108};
109
Davide Italianocde93362015-09-26 00:32:04 +0000110class AArch64TargetInfo final : public TargetInfo {
111public:
112 AArch64TargetInfo();
113 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
114 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000115 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
116 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Davide Italianocde93362015-09-26 00:32:04 +0000117 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000118 uint64_t BaseAddr, uint64_t SymVA) const override;
Davide Italianocde93362015-09-26 00:32:04 +0000119};
120
Simon Atanasyan49829a12015-09-29 05:34:03 +0000121class MipsTargetInfo final : public TargetInfo {
122public:
123 MipsTargetInfo();
124 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
125 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000126 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
127 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000128 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000129 uint64_t BaseAddr, uint64_t SymVA) const override;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000130};
131
Rafael Espindola01205f72015-09-22 18:19:46 +0000132extern std::unique_ptr<TargetInfo> Target;
133}
134}
135
136#endif