]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - ELF/Arch/PPC.cpp
Vendor import of lld trunk r338150:
[FreeBSD/FreeBSD.git] / ELF / Arch / PPC.cpp
1 //===- PPC.cpp ------------------------------------------------------------===//
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 #include "Symbols.h"
11 #include "Target.h"
12 #include "lld/Common/ErrorHandler.h"
13 #include "llvm/Support/Endian.h"
14
15 using namespace llvm;
16 using namespace llvm::support::endian;
17 using namespace llvm::ELF;
18 using namespace lld;
19 using namespace lld::elf;
20
21 namespace {
22 class PPC final : public TargetInfo {
23 public:
24   PPC();
25   void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
26   RelExpr getRelExpr(RelType Type, const Symbol &S,
27                      const uint8_t *Loc) const override;
28 };
29 } // namespace
30
31 PPC::PPC() {
32   GotBaseSymOff = 0x8000;
33   GotBaseSymInGotPlt = false;
34 }
35
36 RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,
37                         const uint8_t *Loc) const {
38   switch (Type) {
39   case R_PPC_REL24:
40   case R_PPC_REL32:
41     return R_PC;
42   case R_PPC_PLTREL24:
43     return R_PLT_PC;
44   default:
45     return R_ABS;
46   }
47 }
48
49 void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
50   switch (Type) {
51   case R_PPC_ADDR16_HA:
52     write16be(Loc, (Val + 0x8000) >> 16);
53     break;
54   case R_PPC_ADDR16_HI:
55     write16be(Loc, Val >> 16);
56     break;
57   case R_PPC_ADDR16_LO:
58     write16be(Loc, Val);
59     break;
60   case R_PPC_ADDR32:
61   case R_PPC_REL32:
62     write32be(Loc, Val);
63     break;
64   case R_PPC_PLTREL24:
65   case R_PPC_REL24:
66     write32be(Loc, read32be(Loc) | (Val & 0x3FFFFFC));
67     break;
68   default:
69     error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
70   }
71 }
72
73 TargetInfo *elf::getPPCTargetInfo() {
74   static PPC Target;
75   return &Target;
76 }