blob: 4a70615353c3d2e8a11f5c407be9b50f1aac9c45 [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 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; }
Rafael Espindola01205f72015-09-22 18:19:46 +000029 virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
30 uint64_t PltEntryAddr) const = 0;
Rafael Espindolaae244002015-10-05 19:30:12 +000031 virtual bool isRelRelative(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000032 virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000033 virtual bool relocPointsToGot(uint32_t Type) const;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000034 virtual bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const = 0;
Rafael Espindolac4010882015-09-22 20:54:08 +000035 virtual void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000036 uint64_t BaseAddr, uint64_t SymVA) const = 0;
Rafael Espindolac4010882015-09-22 20:54:08 +000037
Rafael Espindola01205f72015-09-22 18:19:46 +000038 virtual ~TargetInfo();
39
40protected:
Hal Finkel47290642015-10-08 21:25:04 +000041 uint64_t VAStart;
Rafael Espindola01205f72015-09-22 18:19:46 +000042 unsigned PCRelReloc;
Rafael Espindola8acb95c2015-09-29 14:42:37 +000043 unsigned GotRefReloc;
Rafael Espindola7f074422015-09-22 21:35:51 +000044 unsigned GotReloc;
Rafael Espindolaae244002015-10-05 19:30:12 +000045 unsigned RelativeReloc;
Simon Atanasyan49829a12015-09-29 05:34:03 +000046 llvm::StringRef DefaultEntry = "_start";
Rafael Espindola01205f72015-09-22 18:19:46 +000047};
48
49class X86TargetInfo final : public TargetInfo {
50public:
51 X86TargetInfo();
52 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
53 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000054 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000055 bool relocPointsToGot(uint32_t Type) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000056 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000057 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000058 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola01205f72015-09-22 18:19:46 +000059};
60
61class X86_64TargetInfo final : public TargetInfo {
62public:
63 X86_64TargetInfo();
64 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
65 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000066 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
67 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000068 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000069 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindolaae244002015-10-05 19:30:12 +000070 bool isRelRelative(uint32_t Type) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000071};
72
73class PPC64TargetInfo final : public TargetInfo {
74public:
75 PPC64TargetInfo();
76 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
77 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000078 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
79 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindolac4010882015-09-22 20:54:08 +000080 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000081 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola01205f72015-09-22 18:19:46 +000082};
83
Rafael Espindola1d6063e2015-09-22 21:24:52 +000084class PPCTargetInfo final : public TargetInfo {
85public:
86 PPCTargetInfo();
87 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
88 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000089 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
90 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +000091 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000092 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +000093};
94
95class ARMTargetInfo final : public TargetInfo {
96public:
97 ARMTargetInfo();
98 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
99 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000100 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
101 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000102 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000103 uint64_t BaseAddr, uint64_t SymVA) const override;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000104};
105
Davide Italianocde93362015-09-26 00:32:04 +0000106class AArch64TargetInfo final : public TargetInfo {
107public:
108 AArch64TargetInfo();
109 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
110 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000111 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
112 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Davide Italianocde93362015-09-26 00:32:04 +0000113 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000114 uint64_t BaseAddr, uint64_t SymVA) const override;
Davide Italianocde93362015-09-26 00:32:04 +0000115};
116
Simon Atanasyan49829a12015-09-29 05:34:03 +0000117class MipsTargetInfo final : public TargetInfo {
118public:
119 MipsTargetInfo();
120 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
121 uint64_t PltEntryAddr) const override;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000122 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
123 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000124 void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000125 uint64_t BaseAddr, uint64_t SymVA) const override;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000126};
127
Rafael Espindola01205f72015-09-22 18:19:46 +0000128extern std::unique_ptr<TargetInfo> Target;
129}
130}
131
132#endif