Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 1 | //===-- PPCAsmBackend.cpp - PPC Assembler Backend -------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 9 | #include "MCTargetDesc/PPCFixupKinds.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 11 | #include "llvm/BinaryFormat/ELF.h" |
| 12 | #include "llvm/BinaryFormat/MachO.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAsmBackend.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAssembler.h" |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCELFObjectWriter.h" |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCFixupKindInfo.h" |
Daniel Dunbar | 73b8713 | 2010-12-16 16:08:33 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCMachObjectWriter.h" |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCObjectWriter.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCSectionMachO.h" |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSubtargetInfo.h" |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSymbolELF.h" |
Jim Grosbach | 28fcafb | 2011-06-24 23:44:37 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCValue.h" |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 24 | #include "llvm/Support/TargetRegistry.h" |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 27 | static uint64_t adjustFixupValue(unsigned Kind, uint64_t Value) { |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 28 | switch (Kind) { |
| 29 | default: |
| 30 | llvm_unreachable("Unknown fixup kind!"); |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 31 | case FK_NONE: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 32 | case FK_Data_1: |
| 33 | case FK_Data_2: |
| 34 | case FK_Data_4: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 35 | case FK_Data_8: |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 36 | case PPC::fixup_ppc_nofixup: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 37 | return Value; |
| 38 | case PPC::fixup_ppc_brcond14: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 39 | case PPC::fixup_ppc_brcond14abs: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 40 | return Value & 0xfffc; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 41 | case PPC::fixup_ppc_br24: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 42 | case PPC::fixup_ppc_br24abs: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 43 | return Value & 0x3fffffc; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 44 | case PPC::fixup_ppc_half16: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 45 | return Value & 0xffff; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 46 | case PPC::fixup_ppc_half16ds: |
Ulrich Weigand | 3e18601 | 2013-03-26 10:56:47 +0000 | [diff] [blame] | 47 | return Value & 0xfffc; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 51 | static unsigned getFixupKindNumBytes(unsigned Kind) { |
| 52 | switch (Kind) { |
| 53 | default: |
| 54 | llvm_unreachable("Unknown fixup kind!"); |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 55 | case FK_NONE: |
| 56 | return 0; |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 57 | case FK_Data_1: |
| 58 | return 1; |
| 59 | case FK_Data_2: |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 60 | case PPC::fixup_ppc_half16: |
| 61 | case PPC::fixup_ppc_half16ds: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 62 | return 2; |
| 63 | case FK_Data_4: |
| 64 | case PPC::fixup_ppc_brcond14: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 65 | case PPC::fixup_ppc_brcond14abs: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 66 | case PPC::fixup_ppc_br24: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 67 | case PPC::fixup_ppc_br24abs: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 68 | return 4; |
| 69 | case FK_Data_8: |
| 70 | return 8; |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 71 | case PPC::fixup_ppc_nofixup: |
| 72 | return 0; |
| 73 | } |
| 74 | } |
| 75 | |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 76 | namespace { |
Daniel Dunbar | 8888a96 | 2010-12-16 16:09:19 +0000 | [diff] [blame] | 77 | |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 78 | class PPCAsmBackend : public MCAsmBackend { |
Fangrui Song | e18a6ad | 2019-05-17 05:44:26 +0000 | [diff] [blame] | 79 | protected: |
| 80 | Triple TT; |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 81 | public: |
Fangrui Song | e18a6ad | 2019-05-17 05:44:26 +0000 | [diff] [blame] | 82 | PPCAsmBackend(const Target &T, const Triple &TT) |
| 83 | : MCAsmBackend(TT.isLittleEndian() ? support::little : support::big), |
| 84 | TT(TT) {} |
Daniel Dunbar | 0c9d9fd | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 85 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 86 | unsigned getNumFixupKinds() const override { |
| 87 | return PPC::NumTargetFixupKinds; |
| 88 | } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 89 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 90 | const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override { |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 91 | const static MCFixupKindInfo InfosBE[PPC::NumTargetFixupKinds] = { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 92 | // name offset bits flags |
| 93 | { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel }, |
| 94 | { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel }, |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 95 | { "fixup_ppc_br24abs", 6, 24, 0 }, |
| 96 | { "fixup_ppc_brcond14abs", 16, 14, 0 }, |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 97 | { "fixup_ppc_half16", 0, 16, 0 }, |
| 98 | { "fixup_ppc_half16ds", 0, 14, 0 }, |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 99 | { "fixup_ppc_nofixup", 0, 0, 0 } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 100 | }; |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 101 | const static MCFixupKindInfo InfosLE[PPC::NumTargetFixupKinds] = { |
| 102 | // name offset bits flags |
| 103 | { "fixup_ppc_br24", 2, 24, MCFixupKindInfo::FKF_IsPCRel }, |
| 104 | { "fixup_ppc_brcond14", 2, 14, MCFixupKindInfo::FKF_IsPCRel }, |
| 105 | { "fixup_ppc_br24abs", 2, 24, 0 }, |
| 106 | { "fixup_ppc_brcond14abs", 2, 14, 0 }, |
| 107 | { "fixup_ppc_half16", 0, 16, 0 }, |
| 108 | { "fixup_ppc_half16ds", 2, 14, 0 }, |
| 109 | { "fixup_ppc_nofixup", 0, 0, 0 } |
| 110 | }; |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 111 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 112 | if (Kind < FirstTargetFixupKind) |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 113 | return MCAsmBackend::getFixupKindInfo(Kind); |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 114 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 115 | assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && |
| 116 | "Invalid kind!"); |
Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 117 | return (Endian == support::little |
| 118 | ? InfosLE |
| 119 | : InfosBE)[Kind - FirstTargetFixupKind]; |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 120 | } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 121 | |
Rafael Espindola | 801b42d | 2017-06-23 22:52:36 +0000 | [diff] [blame] | 122 | void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, |
| 123 | const MCValue &Target, MutableArrayRef<char> Data, |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 124 | uint64_t Value, bool IsResolved, |
| 125 | const MCSubtargetInfo *STI) const override { |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 126 | Value = adjustFixupValue(Fixup.getKind(), Value); |
| 127 | if (!Value) return; // Doesn't change encoding. |
| 128 | |
| 129 | unsigned Offset = Fixup.getOffset(); |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 130 | unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind()); |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 131 | |
| 132 | // For each byte of the fragment that the fixup touches, mask in the bits |
| 133 | // from the fixup value. The Value has been "split up" into the appropriate |
| 134 | // bitfields above. |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 135 | for (unsigned i = 0; i != NumBytes; ++i) { |
Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 136 | unsigned Idx = Endian == support::little ? i : (NumBytes - 1 - i); |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 137 | Data[Offset + i] |= uint8_t((Value >> (Idx * 8)) & 0xff); |
| 138 | } |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 141 | bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, |
| 142 | const MCValue &Target) override { |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 143 | switch ((unsigned)Fixup.getKind()) { |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 144 | default: |
| 145 | return false; |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 146 | case FK_NONE: |
| 147 | return true; |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 148 | case PPC::fixup_ppc_br24: |
| 149 | case PPC::fixup_ppc_br24abs: |
| 150 | // If the target symbol has a local entry point we must not attempt |
| 151 | // to resolve the fixup directly. Emit a relocation and leave |
| 152 | // resolution of the final target address to the linker. |
| 153 | if (const MCSymbolRefExpr *A = Target.getSymA()) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 154 | if (const auto *S = dyn_cast<MCSymbolELF>(&A->getSymbol())) { |
| 155 | // The "other" values are stored in the last 6 bits of the second |
| 156 | // byte. The traditional defines for STO values assume the full byte |
| 157 | // and thus the shift to pack it. |
| 158 | unsigned Other = S->getOther() << 2; |
| 159 | if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0) |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 160 | return true; |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 161 | } |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 162 | } |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 163 | return false; |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 167 | bool mayNeedRelaxation(const MCInst &Inst, |
| 168 | const MCSubtargetInfo &STI) const override { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 169 | // FIXME. |
| 170 | return false; |
| 171 | } |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 172 | |
| 173 | bool fixupNeedsRelaxation(const MCFixup &Fixup, |
| 174 | uint64_t Value, |
Eli Bendersky | 4d9ada0 | 2013-01-08 00:22:56 +0000 | [diff] [blame] | 175 | const MCRelaxableFragment *DF, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 176 | const MCAsmLayout &Layout) const override { |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 177 | // FIXME. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 178 | llvm_unreachable("relaxInstruction() unimplemented"); |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Nirav Dave | 8603062 | 2016-07-11 14:23:53 +0000 | [diff] [blame] | 181 | void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, |
| 182 | MCInst &Res) const override { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 183 | // FIXME. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 184 | llvm_unreachable("relaxInstruction() unimplemented"); |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 185 | } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 186 | |
Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 187 | bool writeNopData(raw_ostream &OS, uint64_t Count) const override { |
Ulrich Weigand | d3ac7c0 | 2013-07-04 18:28:46 +0000 | [diff] [blame] | 188 | uint64_t NumNops = Count / 4; |
| 189 | for (uint64_t i = 0; i != NumNops; ++i) |
Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 190 | support::endian::write<uint32_t>(OS, 0x60000000, Endian); |
Ulrich Weigand | d3ac7c0 | 2013-07-04 18:28:46 +0000 | [diff] [blame] | 191 | |
Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 192 | OS.write_zeros(Count % 4); |
David Majnemer | 7137420 | 2013-09-26 09:18:48 +0000 | [diff] [blame] | 193 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 194 | return true; |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 195 | } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 196 | }; |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 197 | } // end anonymous namespace |
| 198 | |
| 199 | |
| 200 | // FIXME: This should be in a separate file. |
| 201 | namespace { |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 202 | |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 203 | class DarwinPPCAsmBackend : public PPCAsmBackend { |
| 204 | public: |
| 205 | DarwinPPCAsmBackend(const Target &T, const Triple &TT) |
| 206 | : PPCAsmBackend(T, TT) {} |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 207 | |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 208 | std::unique_ptr<MCObjectTargetWriter> |
| 209 | createObjectTargetWriter() const override { |
| 210 | bool Is64 = TT.isPPC64(); |
| 211 | return createPPCMachObjectWriter( |
| 212 | /*Is64Bit=*/Is64, |
| 213 | (Is64 ? MachO::CPU_TYPE_POWERPC64 : MachO::CPU_TYPE_POWERPC), |
| 214 | MachO::CPU_SUBTYPE_POWERPC_ALL); |
| 215 | } |
| 216 | }; |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 217 | |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 218 | class ELFPPCAsmBackend : public PPCAsmBackend { |
| 219 | public: |
| 220 | ELFPPCAsmBackend(const Target &T, const Triple &TT) : PPCAsmBackend(T, TT) {} |
| 221 | |
| 222 | std::unique_ptr<MCObjectTargetWriter> |
| 223 | createObjectTargetWriter() const override { |
| 224 | uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS()); |
| 225 | bool Is64 = TT.isPPC64(); |
| 226 | return createPPCELFObjectWriter(Is64, OSABI); |
| 227 | } |
| 228 | |
| 229 | Optional<MCFixupKind> getFixupKind(StringRef Name) const override; |
| 230 | }; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 231 | |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 232 | } // end anonymous namespace |
| 233 | |
Fangrui Song | ad7199f | 2019-05-17 06:04:11 +0000 | [diff] [blame] | 234 | Optional<MCFixupKind> ELFPPCAsmBackend::getFixupKind(StringRef Name) const { |
| 235 | if (TT.isPPC64()) { |
| 236 | if (Name == "R_PPC64_NONE") |
| 237 | return FK_NONE; |
| 238 | } else { |
| 239 | if (Name == "R_PPC_NONE") |
| 240 | return FK_NONE; |
| 241 | } |
| 242 | return MCAsmBackend::getFixupKind(Name); |
| 243 | } |
| 244 | |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 245 | MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 246 | const MCSubtargetInfo &STI, |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 247 | const MCRegisterInfo &MRI, |
Joel Jones | 373d7d3 | 2016-07-25 17:18:28 +0000 | [diff] [blame] | 248 | const MCTargetOptions &Options) { |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 249 | const Triple &TT = STI.getTargetTriple(); |
Daniel Sanders | 418caf5 | 2015-06-10 10:35:34 +0000 | [diff] [blame] | 250 | if (TT.isOSDarwin()) |
Fangrui Song | e18a6ad | 2019-05-17 05:44:26 +0000 | [diff] [blame] | 251 | return new DarwinPPCAsmBackend(T, TT); |
Daniel Dunbar | 2b9b0e3 | 2011-04-19 21:14:45 +0000 | [diff] [blame] | 252 | |
Fangrui Song | e18a6ad | 2019-05-17 05:44:26 +0000 | [diff] [blame] | 253 | return new ELFPPCAsmBackend(T, TT); |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 254 | } |