1 //===-- PPCELFObjectWriter.cpp - PPC ELF Writer ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/PPCFixupKinds.h"
11 #include "MCTargetDesc/PPCMCTargetDesc.h"
12 #include "llvm/MC/MCELFObjectWriter.h"
13 #include "llvm/Support/ErrorHandling.h"
18 class PPCELFObjectWriter : public MCELFObjectTargetWriter {
20 PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI);
22 virtual ~PPCELFObjectWriter();
24 virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
25 bool IsPCRel, bool IsRelocWithSymbol,
26 int64_t Addend) const;
27 virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset);
31 PPCELFObjectWriter::PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
32 : MCELFObjectTargetWriter(Is64Bit, OSABI,
33 Is64Bit ? ELF::EM_PPC64 : ELF::EM_PPC,
34 /*HasRelocationAddend*/ true) {}
36 PPCELFObjectWriter::~PPCELFObjectWriter() {
39 unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target,
42 bool IsRelocWithSymbol,
43 int64_t Addend) const {
44 // determine the type of the relocation
47 switch ((unsigned)Fixup.getKind()) {
49 llvm_unreachable("Unimplemented");
50 case PPC::fixup_ppc_br24:
51 Type = ELF::R_PPC_REL24;
54 Type = ELF::R_PPC_REL32;
58 switch ((unsigned)Fixup.getKind()) {
59 default: llvm_unreachable("invalid fixup kind!");
60 case PPC::fixup_ppc_br24:
61 Type = ELF::R_PPC_ADDR24;
63 case PPC::fixup_ppc_brcond14:
64 Type = ELF::R_PPC_ADDR14_BRTAKEN; // XXX: or BRNTAKEN?_
66 case PPC::fixup_ppc_ha16:
67 Type = ELF::R_PPC_ADDR16_HA;
69 case PPC::fixup_ppc_lo16:
70 Type = ELF::R_PPC_ADDR16_LO;
72 case PPC::fixup_ppc_lo14:
73 Type = ELF::R_PPC_ADDR14;
76 Type = ELF::R_PPC_ADDR32;
79 Type = ELF::R_PPC_ADDR16;
86 void PPCELFObjectWriter::
87 adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) {
88 switch ((unsigned)Fixup.getKind()) {
89 case PPC::fixup_ppc_ha16:
90 case PPC::fixup_ppc_lo16:
98 MCObjectWriter *llvm::createPPCELFObjectWriter(raw_ostream &OS,
101 MCELFObjectTargetWriter *MOTW = new PPCELFObjectWriter(Is64Bit, OSABI);
102 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/false);