]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Arch/PPC.cpp
Set the default image base on arm64 and i386 to a superpage-aligned
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / 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() { GotBaseSymOff = 0x8000; }
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 RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,
32                         const uint8_t *Loc) const {
33   switch (Type) {
34   case R_PPC_REL24:
35   case R_PPC_REL32:
36     return R_PC;
37   case R_PPC_PLTREL24:
38     return R_PLT_PC;
39   default:
40     return R_ABS;
41   }
42 }
43
44 void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
45   switch (Type) {
46   case R_PPC_ADDR16_HA:
47     write16be(Loc, (Val + 0x8000) >> 16);
48     break;
49   case R_PPC_ADDR16_HI:
50     write16be(Loc, Val >> 16);
51     break;
52   case R_PPC_ADDR16_LO:
53     write16be(Loc, Val);
54     break;
55   case R_PPC_ADDR32:
56   case R_PPC_REL32:
57     write32be(Loc, Val);
58     break;
59   case R_PPC_PLTREL24:
60   case R_PPC_REL24:
61     write32be(Loc, read32be(Loc) | (Val & 0x3FFFFFC));
62     break;
63   default:
64     error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
65   }
66 }
67
68 TargetInfo *elf::getPPCTargetInfo() {
69   static PPC Target;
70   return &Target;
71 }