1 //===-- MipsELFWriterInfo.cpp - ELF Writer Info for the Mips backend ------===//
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 // This file implements ELF writer information for the Mips backend.
12 //===----------------------------------------------------------------------===//
14 #include "MipsELFWriterInfo.h"
15 #include "MipsRelocations.h"
16 #include "llvm/Function.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/Target/TargetData.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/Support/ELF.h"
24 //===----------------------------------------------------------------------===//
25 // Implementation of the MipsELFWriterInfo class
26 //===----------------------------------------------------------------------===//
28 MipsELFWriterInfo::MipsELFWriterInfo(bool is64Bit_, bool isLittleEndian_)
29 : TargetELFWriterInfo(is64Bit_, isLittleEndian_) {
33 MipsELFWriterInfo::~MipsELFWriterInfo() {}
35 unsigned MipsELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
36 switch(MachineRelTy) {
37 case Mips::reloc_mips_pc16:
38 return ELF::R_MIPS_GOT16;
39 case Mips::reloc_mips_hi:
40 return ELF::R_MIPS_HI16;
41 case Mips::reloc_mips_lo:
42 return ELF::R_MIPS_LO16;
43 case Mips::reloc_mips_26:
44 return ELF::R_MIPS_26;
46 llvm_unreachable("unknown Mips machine relocation type");
50 long int MipsELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
51 long int Modifier) const {
53 case ELF::R_MIPS_26: return Modifier;
55 llvm_unreachable("unknown Mips relocation type");
59 unsigned MipsELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
61 case ELF::R_MIPS_GOT16:
65 llvm_unreachable("unknown Mips relocation type");
69 bool MipsELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
71 case ELF::R_MIPS_GOT16:
76 llvm_unreachable("unknown Mips relocation type");
80 unsigned MipsELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
81 return Mips::reloc_mips_26;
84 long int MipsELFWriterInfo::computeRelocation(unsigned SymOffset,
86 unsigned RelTy) const {
88 if (RelTy == ELF::R_MIPS_GOT16)
89 return SymOffset - (RelOffset + 4);
91 llvm_unreachable("computeRelocation unknown for this relocation type");