Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 1 | //===-- PPCELFObjectWriter.cpp - PPC ELF Writer ---------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 11 | #include "MCTargetDesc/PPCFixupKinds.h" |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 12 | #include "MCTargetDesc/PPCMCExpr.h" |
Bill Schmidt | a4f8984 | 2012-12-14 20:28:38 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/STLExtras.h" |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCELFObjectWriter.h" |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCExpr.h" |
| 16 | #include "llvm/MC/MCValue.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ErrorHandling.h" |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | class PPCELFObjectWriter : public MCELFObjectTargetWriter { |
| 23 | public: |
| 24 | PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI); |
| 25 | |
| 26 | virtual ~PPCELFObjectWriter(); |
| 27 | protected: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 28 | virtual unsigned getRelocTypeInner(const MCValue &Target, |
| 29 | const MCFixup &Fixup, |
| 30 | bool IsPCRel) const; |
Rafael Espindola | 9ab3801 | 2014-03-27 20:41:17 +0000 | [diff] [blame] | 31 | unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, |
Rafael Espindola | c03f44c | 2014-03-27 20:49:35 +0000 | [diff] [blame] | 32 | bool IsPCRel) const override; |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame^] | 33 | |
| 34 | bool needsRelocateWithSymbol(unsigned Type) const override; |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 35 | }; |
| 36 | } |
| 37 | |
| 38 | PPCELFObjectWriter::PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI) |
| 39 | : MCELFObjectTargetWriter(Is64Bit, OSABI, |
| 40 | Is64Bit ? ELF::EM_PPC64 : ELF::EM_PPC, |
Rafael Espindola | 2500962 | 2011-12-22 18:38:06 +0000 | [diff] [blame] | 41 | /*HasRelocationAddend*/ true) {} |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 42 | |
| 43 | PPCELFObjectWriter::~PPCELFObjectWriter() { |
| 44 | } |
| 45 | |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 46 | static MCSymbolRefExpr::VariantKind getAccessVariant(const MCValue &Target, |
| 47 | const MCFixup &Fixup) { |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 48 | const MCExpr *Expr = Fixup.getValue(); |
| 49 | |
| 50 | if (Expr->getKind() != MCExpr::Target) |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 51 | return Target.getAccessVariant(); |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 52 | |
| 53 | switch (cast<PPCMCExpr>(Expr)->getKind()) { |
| 54 | case PPCMCExpr::VK_PPC_None: |
| 55 | return MCSymbolRefExpr::VK_None; |
| 56 | case PPCMCExpr::VK_PPC_LO: |
| 57 | return MCSymbolRefExpr::VK_PPC_LO; |
| 58 | case PPCMCExpr::VK_PPC_HI: |
| 59 | return MCSymbolRefExpr::VK_PPC_HI; |
| 60 | case PPCMCExpr::VK_PPC_HA: |
| 61 | return MCSymbolRefExpr::VK_PPC_HA; |
| 62 | case PPCMCExpr::VK_PPC_HIGHERA: |
| 63 | return MCSymbolRefExpr::VK_PPC_HIGHERA; |
| 64 | case PPCMCExpr::VK_PPC_HIGHER: |
| 65 | return MCSymbolRefExpr::VK_PPC_HIGHER; |
| 66 | case PPCMCExpr::VK_PPC_HIGHEST: |
| 67 | return MCSymbolRefExpr::VK_PPC_HIGHEST; |
| 68 | case PPCMCExpr::VK_PPC_HIGHESTA: |
| 69 | return MCSymbolRefExpr::VK_PPC_HIGHESTA; |
| 70 | } |
Alexey Samsonov | 94bc422 | 2014-03-20 07:30:40 +0000 | [diff] [blame] | 71 | llvm_unreachable("unknown PPCMCExpr kind"); |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 74 | unsigned PPCELFObjectWriter::getRelocTypeInner(const MCValue &Target, |
| 75 | const MCFixup &Fixup, |
| 76 | bool IsPCRel) const |
| 77 | { |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 78 | MCSymbolRefExpr::VariantKind Modifier = getAccessVariant(Target, Fixup); |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 79 | |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 80 | // determine the type of the relocation |
| 81 | unsigned Type; |
| 82 | if (IsPCRel) { |
| 83 | switch ((unsigned)Fixup.getKind()) { |
| 84 | default: |
| 85 | llvm_unreachable("Unimplemented"); |
| 86 | case PPC::fixup_ppc_br24: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 87 | case PPC::fixup_ppc_br24abs: |
Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 88 | switch (Modifier) { |
| 89 | default: llvm_unreachable("Unsupported Modifier"); |
| 90 | case MCSymbolRefExpr::VK_None: |
| 91 | Type = ELF::R_PPC_REL24; |
| 92 | break; |
| 93 | case MCSymbolRefExpr::VK_PLT: |
| 94 | Type = ELF::R_PPC_PLTREL24; |
| 95 | break; |
| 96 | } |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 97 | break; |
Ulrich Weigand | 72a7dc0 | 2013-04-26 15:38:30 +0000 | [diff] [blame] | 98 | case PPC::fixup_ppc_brcond14: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 99 | case PPC::fixup_ppc_brcond14abs: |
Ulrich Weigand | 72a7dc0 | 2013-04-26 15:38:30 +0000 | [diff] [blame] | 100 | Type = ELF::R_PPC_REL14; |
| 101 | break; |
Ulrich Weigand | 91add7d | 2013-06-21 14:44:37 +0000 | [diff] [blame] | 102 | case PPC::fixup_ppc_half16: |
| 103 | switch (Modifier) { |
| 104 | default: llvm_unreachable("Unsupported Modifier"); |
| 105 | case MCSymbolRefExpr::VK_None: |
| 106 | Type = ELF::R_PPC_REL16; |
| 107 | break; |
| 108 | case MCSymbolRefExpr::VK_PPC_LO: |
| 109 | Type = ELF::R_PPC_REL16_LO; |
| 110 | break; |
| 111 | case MCSymbolRefExpr::VK_PPC_HI: |
| 112 | Type = ELF::R_PPC_REL16_HI; |
| 113 | break; |
| 114 | case MCSymbolRefExpr::VK_PPC_HA: |
| 115 | Type = ELF::R_PPC_REL16_HA; |
| 116 | break; |
| 117 | } |
| 118 | break; |
Adhemerval Zanella | 9b0b781 | 2013-01-04 19:08:13 +0000 | [diff] [blame] | 119 | case FK_Data_4: |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 120 | case FK_PCRel_4: |
| 121 | Type = ELF::R_PPC_REL32; |
| 122 | break; |
Adhemerval Zanella | 9b0b781 | 2013-01-04 19:08:13 +0000 | [diff] [blame] | 123 | case FK_Data_8: |
| 124 | case FK_PCRel_8: |
| 125 | Type = ELF::R_PPC64_REL64; |
| 126 | break; |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 127 | } |
| 128 | } else { |
| 129 | switch ((unsigned)Fixup.getKind()) { |
| 130 | default: llvm_unreachable("invalid fixup kind!"); |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 131 | case PPC::fixup_ppc_br24abs: |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 132 | Type = ELF::R_PPC_ADDR24; |
| 133 | break; |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 134 | case PPC::fixup_ppc_brcond14abs: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 135 | Type = ELF::R_PPC_ADDR14; // XXX: or BRNTAKEN?_ |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 136 | break; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 137 | case PPC::fixup_ppc_half16: |
Ulrich Weigand | 8557850 | 2012-11-13 19:24:36 +0000 | [diff] [blame] | 138 | switch (Modifier) { |
| 139 | default: llvm_unreachable("Unsupported Modifier"); |
Ulrich Weigand | 8557850 | 2012-11-13 19:24:36 +0000 | [diff] [blame] | 140 | case MCSymbolRefExpr::VK_None: |
Ulrich Weigand | e462053 | 2013-05-08 17:50:07 +0000 | [diff] [blame] | 141 | Type = ELF::R_PPC_ADDR16; |
| 142 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 143 | case MCSymbolRefExpr::VK_PPC_LO: |
Ulrich Weigand | 8557850 | 2012-11-13 19:24:36 +0000 | [diff] [blame] | 144 | Type = ELF::R_PPC_ADDR16_LO; |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 145 | break; |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 146 | case MCSymbolRefExpr::VK_PPC_HI: |
| 147 | Type = ELF::R_PPC_ADDR16_HI; |
| 148 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 149 | case MCSymbolRefExpr::VK_PPC_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 150 | Type = ELF::R_PPC_ADDR16_HA; |
| 151 | break; |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 152 | case MCSymbolRefExpr::VK_PPC_HIGHER: |
| 153 | Type = ELF::R_PPC64_ADDR16_HIGHER; |
| 154 | break; |
| 155 | case MCSymbolRefExpr::VK_PPC_HIGHERA: |
| 156 | Type = ELF::R_PPC64_ADDR16_HIGHERA; |
| 157 | break; |
| 158 | case MCSymbolRefExpr::VK_PPC_HIGHEST: |
| 159 | Type = ELF::R_PPC64_ADDR16_HIGHEST; |
| 160 | break; |
| 161 | case MCSymbolRefExpr::VK_PPC_HIGHESTA: |
| 162 | Type = ELF::R_PPC64_ADDR16_HIGHESTA; |
| 163 | break; |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 164 | case MCSymbolRefExpr::VK_GOT: |
| 165 | Type = ELF::R_PPC_GOT16; |
| 166 | break; |
| 167 | case MCSymbolRefExpr::VK_PPC_GOT_LO: |
| 168 | Type = ELF::R_PPC_GOT16_LO; |
| 169 | break; |
| 170 | case MCSymbolRefExpr::VK_PPC_GOT_HI: |
| 171 | Type = ELF::R_PPC_GOT16_HI; |
| 172 | break; |
| 173 | case MCSymbolRefExpr::VK_PPC_GOT_HA: |
| 174 | Type = ELF::R_PPC_GOT16_HA; |
| 175 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 176 | case MCSymbolRefExpr::VK_PPC_TOC: |
Ulrich Weigand | 3e18601 | 2013-03-26 10:56:47 +0000 | [diff] [blame] | 177 | Type = ELF::R_PPC64_TOC16; |
| 178 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 179 | case MCSymbolRefExpr::VK_PPC_TOC_LO: |
Bill Schmidt | 34627e3 | 2012-11-27 17:35:46 +0000 | [diff] [blame] | 180 | Type = ELF::R_PPC64_TOC16_LO; |
| 181 | break; |
Ulrich Weigand | 72ddbd6 | 2013-06-21 14:43:10 +0000 | [diff] [blame] | 182 | case MCSymbolRefExpr::VK_PPC_TOC_HI: |
| 183 | Type = ELF::R_PPC64_TOC16_HI; |
| 184 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 185 | case MCSymbolRefExpr::VK_PPC_TOC_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 186 | Type = ELF::R_PPC64_TOC16_HA; |
| 187 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 188 | case MCSymbolRefExpr::VK_PPC_TPREL: |
| 189 | Type = ELF::R_PPC_TPREL16; |
| 190 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 191 | case MCSymbolRefExpr::VK_PPC_TPREL_LO: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 192 | Type = ELF::R_PPC_TPREL16_LO; |
| 193 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 194 | case MCSymbolRefExpr::VK_PPC_TPREL_HI: |
| 195 | Type = ELF::R_PPC_TPREL16_HI; |
| 196 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 197 | case MCSymbolRefExpr::VK_PPC_TPREL_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 198 | Type = ELF::R_PPC_TPREL16_HA; |
| 199 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 200 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER: |
| 201 | Type = ELF::R_PPC64_TPREL16_HIGHER; |
| 202 | break; |
| 203 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA: |
| 204 | Type = ELF::R_PPC64_TPREL16_HIGHERA; |
| 205 | break; |
| 206 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST: |
| 207 | Type = ELF::R_PPC64_TPREL16_HIGHEST; |
| 208 | break; |
| 209 | case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA: |
| 210 | Type = ELF::R_PPC64_TPREL16_HIGHESTA; |
| 211 | break; |
| 212 | case MCSymbolRefExpr::VK_PPC_DTPREL: |
| 213 | Type = ELF::R_PPC64_DTPREL16; |
| 214 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 215 | case MCSymbolRefExpr::VK_PPC_DTPREL_LO: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 216 | Type = ELF::R_PPC64_DTPREL16_LO; |
| 217 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 218 | case MCSymbolRefExpr::VK_PPC_DTPREL_HI: |
| 219 | Type = ELF::R_PPC64_DTPREL16_HI; |
| 220 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 221 | case MCSymbolRefExpr::VK_PPC_DTPREL_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 222 | Type = ELF::R_PPC64_DTPREL16_HA; |
| 223 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 224 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER: |
| 225 | Type = ELF::R_PPC64_DTPREL16_HIGHER; |
| 226 | break; |
| 227 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA: |
| 228 | Type = ELF::R_PPC64_DTPREL16_HIGHERA; |
| 229 | break; |
| 230 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST: |
| 231 | Type = ELF::R_PPC64_DTPREL16_HIGHEST; |
| 232 | break; |
| 233 | case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA: |
| 234 | Type = ELF::R_PPC64_DTPREL16_HIGHESTA; |
| 235 | break; |
| 236 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD: |
| 237 | Type = ELF::R_PPC64_GOT_TLSGD16; |
| 238 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 239 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO: |
Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 240 | Type = ELF::R_PPC64_GOT_TLSGD16_LO; |
| 241 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 242 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI: |
| 243 | Type = ELF::R_PPC64_GOT_TLSGD16_HI; |
| 244 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 245 | case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 246 | Type = ELF::R_PPC64_GOT_TLSGD16_HA; |
| 247 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 248 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD: |
| 249 | Type = ELF::R_PPC64_GOT_TLSLD16; |
| 250 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 251 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO: |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 252 | Type = ELF::R_PPC64_GOT_TLSLD16_LO; |
| 253 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 254 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI: |
| 255 | Type = ELF::R_PPC64_GOT_TLSLD16_HI; |
| 256 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 257 | case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 258 | Type = ELF::R_PPC64_GOT_TLSLD16_HA; |
| 259 | break; |
Ulrich Weigand | b204431 | 2013-07-05 13:49:46 +0000 | [diff] [blame] | 260 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL: |
| 261 | /* We don't have R_PPC64_GOT_TPREL16, but since GOT offsets |
| 262 | are always 4-aligned, we can use R_PPC64_GOT_TPREL16_DS. */ |
| 263 | Type = ELF::R_PPC64_GOT_TPREL16_DS; |
| 264 | break; |
| 265 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO: |
| 266 | /* We don't have R_PPC64_GOT_TPREL16_LO, but since GOT offsets |
| 267 | are always 4-aligned, we can use R_PPC64_GOT_TPREL16_LO_DS. */ |
| 268 | Type = ELF::R_PPC64_GOT_TPREL16_LO_DS; |
| 269 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 270 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI: |
| 271 | Type = ELF::R_PPC64_GOT_TPREL16_HI; |
| 272 | break; |
Ulrich Weigand | b204431 | 2013-07-05 13:49:46 +0000 | [diff] [blame] | 273 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL: |
| 274 | /* We don't have R_PPC64_GOT_DTPREL16, but since GOT offsets |
| 275 | are always 4-aligned, we can use R_PPC64_GOT_DTPREL16_DS. */ |
| 276 | Type = ELF::R_PPC64_GOT_DTPREL16_DS; |
| 277 | break; |
| 278 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO: |
| 279 | /* We don't have R_PPC64_GOT_DTPREL16_LO, but since GOT offsets |
| 280 | are always 4-aligned, we can use R_PPC64_GOT_DTPREL16_LO_DS. */ |
| 281 | Type = ELF::R_PPC64_GOT_DTPREL16_LO_DS; |
| 282 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 283 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA: |
Ulrich Weigand | 9e90b3c | 2013-06-20 22:04:40 +0000 | [diff] [blame] | 284 | Type = ELF::R_PPC64_GOT_TPREL16_HA; |
| 285 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 286 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI: |
| 287 | Type = ELF::R_PPC64_GOT_DTPREL16_HI; |
| 288 | break; |
| 289 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA: |
| 290 | Type = ELF::R_PPC64_GOT_DTPREL16_HA; |
| 291 | break; |
Ulrich Weigand | 8557850 | 2012-11-13 19:24:36 +0000 | [diff] [blame] | 292 | } |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 293 | break; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 294 | case PPC::fixup_ppc_half16ds: |
Bill Schmidt | 3822ef2 | 2013-02-21 00:05:29 +0000 | [diff] [blame] | 295 | switch (Modifier) { |
| 296 | default: llvm_unreachable("Unsupported Modifier"); |
Bill Schmidt | 3822ef2 | 2013-02-21 00:05:29 +0000 | [diff] [blame] | 297 | case MCSymbolRefExpr::VK_None: |
Ulrich Weigand | 3e18601 | 2013-03-26 10:56:47 +0000 | [diff] [blame] | 298 | Type = ELF::R_PPC64_ADDR16_DS; |
Bill Schmidt | 3822ef2 | 2013-02-21 00:05:29 +0000 | [diff] [blame] | 299 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 300 | case MCSymbolRefExpr::VK_PPC_LO: |
Ulrich Weigand | e462053 | 2013-05-08 17:50:07 +0000 | [diff] [blame] | 301 | Type = ELF::R_PPC64_ADDR16_LO_DS; |
| 302 | break; |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 303 | case MCSymbolRefExpr::VK_GOT: |
| 304 | Type = ELF::R_PPC64_GOT16_DS; |
| 305 | break; |
| 306 | case MCSymbolRefExpr::VK_PPC_GOT_LO: |
| 307 | Type = ELF::R_PPC64_GOT16_LO_DS; |
| 308 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 309 | case MCSymbolRefExpr::VK_PPC_TOC: |
Bill Schmidt | 34627e3 | 2012-11-27 17:35:46 +0000 | [diff] [blame] | 310 | Type = ELF::R_PPC64_TOC16_DS; |
| 311 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 312 | case MCSymbolRefExpr::VK_PPC_TOC_LO: |
Bill Schmidt | 34627e3 | 2012-11-27 17:35:46 +0000 | [diff] [blame] | 313 | Type = ELF::R_PPC64_TOC16_LO_DS; |
| 314 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 315 | case MCSymbolRefExpr::VK_PPC_TPREL: |
| 316 | Type = ELF::R_PPC64_TPREL16_DS; |
| 317 | break; |
| 318 | case MCSymbolRefExpr::VK_PPC_TPREL_LO: |
| 319 | Type = ELF::R_PPC64_TPREL16_LO_DS; |
| 320 | break; |
| 321 | case MCSymbolRefExpr::VK_PPC_DTPREL: |
| 322 | Type = ELF::R_PPC64_DTPREL16_DS; |
| 323 | break; |
| 324 | case MCSymbolRefExpr::VK_PPC_DTPREL_LO: |
| 325 | Type = ELF::R_PPC64_DTPREL16_LO_DS; |
| 326 | break; |
| 327 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL: |
| 328 | Type = ELF::R_PPC64_GOT_TPREL16_DS; |
| 329 | break; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 330 | case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO: |
Bill Schmidt | 9f0b4ec | 2012-12-14 17:02:38 +0000 | [diff] [blame] | 331 | Type = ELF::R_PPC64_GOT_TPREL16_LO_DS; |
Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 332 | break; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 333 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL: |
| 334 | Type = ELF::R_PPC64_GOT_DTPREL16_DS; |
| 335 | break; |
| 336 | case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO: |
| 337 | Type = ELF::R_PPC64_GOT_DTPREL16_LO_DS; |
| 338 | break; |
Bill Schmidt | 34627e3 | 2012-11-27 17:35:46 +0000 | [diff] [blame] | 339 | } |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 340 | break; |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 341 | case PPC::fixup_ppc_nofixup: |
| 342 | switch (Modifier) { |
| 343 | default: llvm_unreachable("Unsupported Modifier"); |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 344 | case MCSymbolRefExpr::VK_PPC_TLSGD: |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 345 | Type = ELF::R_PPC64_TLSGD; |
| 346 | break; |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 347 | case MCSymbolRefExpr::VK_PPC_TLSLD: |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 348 | Type = ELF::R_PPC64_TLSLD; |
| 349 | break; |
Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 350 | case MCSymbolRefExpr::VK_PPC_TLS: |
| 351 | Type = ELF::R_PPC64_TLS; |
| 352 | break; |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 353 | } |
Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 354 | break; |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 355 | case FK_Data_8: |
| 356 | switch (Modifier) { |
| 357 | default: llvm_unreachable("Unsupported Modifier"); |
Ulrich Weigand | 68e2e1b | 2013-06-20 22:39:42 +0000 | [diff] [blame] | 358 | case MCSymbolRefExpr::VK_PPC_TOCBASE: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 359 | Type = ELF::R_PPC64_TOC; |
| 360 | break; |
| 361 | case MCSymbolRefExpr::VK_None: |
| 362 | Type = ELF::R_PPC64_ADDR64; |
| 363 | break; |
Ulrich Weigand | f11efe7 | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 364 | case MCSymbolRefExpr::VK_PPC_DTPMOD: |
| 365 | Type = ELF::R_PPC64_DTPMOD64; |
| 366 | break; |
| 367 | case MCSymbolRefExpr::VK_PPC_TPREL: |
| 368 | Type = ELF::R_PPC64_TPREL64; |
| 369 | break; |
| 370 | case MCSymbolRefExpr::VK_PPC_DTPREL: |
| 371 | Type = ELF::R_PPC64_DTPREL64; |
| 372 | break; |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 373 | } |
| 374 | break; |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 375 | case FK_Data_4: |
| 376 | Type = ELF::R_PPC_ADDR32; |
| 377 | break; |
| 378 | case FK_Data_2: |
| 379 | Type = ELF::R_PPC_ADDR16; |
| 380 | break; |
| 381 | } |
| 382 | } |
| 383 | return Type; |
| 384 | } |
| 385 | |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 386 | unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target, |
| 387 | const MCFixup &Fixup, |
Rafael Espindola | c03f44c | 2014-03-27 20:49:35 +0000 | [diff] [blame] | 388 | bool IsPCRel) const { |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 389 | return getRelocTypeInner(Target, Fixup, IsPCRel); |
| 390 | } |
| 391 | |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame^] | 392 | bool PPCELFObjectWriter::needsRelocateWithSymbol(unsigned Type) const { |
| 393 | switch (Type) { |
| 394 | default: |
| 395 | return false; |
| 396 | |
| 397 | case ELF::R_PPC_REL24: |
| 398 | // FIXME: We only need to keep the target symbol of the relocation |
| 399 | // if the symbol uses a local entry point. Unfortunately, we do not |
| 400 | // have access to the symbol here ... |
| 401 | return true; |
| 402 | } |
| 403 | } |
| 404 | |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 405 | MCObjectWriter *llvm::createPPCELFObjectWriter(raw_ostream &OS, |
| 406 | bool Is64Bit, |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 407 | bool IsLittleEndian, |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 408 | uint8_t OSABI) { |
| 409 | MCELFObjectTargetWriter *MOTW = new PPCELFObjectWriter(Is64Bit, OSABI); |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 410 | return createELFObjectWriter(MOTW, OS, IsLittleEndian); |
Rafael Espindola | 38a400d | 2011-12-22 01:57:09 +0000 | [diff] [blame] | 411 | } |