1 //===-- MBlazeELFWriterInfo.cpp - ELF Writer Info for the MBlaze backend --===// 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 // 10 // This file implements ELF writer information for the MBlaze backend. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "MBlazeELFWriterInfo.h" 15 #include "MBlazeRelocations.h" 16 #include "llvm/Function.h" 17 #include "llvm/Support/ELF.h" 18 #include "llvm/Support/ErrorHandling.h" 19 #include "llvm/Target/TargetData.h" 20 #include "llvm/Target/TargetMachine.h" 21 22 using namespace llvm; 23 24 //===----------------------------------------------------------------------===// 25 // Implementation of the MBlazeELFWriterInfo class 26 //===----------------------------------------------------------------------===// 27 28 MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM) 29 : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64, 30 TM.getTargetData()->isLittleEndian()) { 31 } 32 33 MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {} 34 35 unsigned MBlazeELFWriterInfo::getRelocationType(unsigned MachineRelTy) const { 36 switch (MachineRelTy) { 37 case MBlaze::reloc_pcrel_word: 38 return ELF::R_MICROBLAZE_64_PCREL; 39 case MBlaze::reloc_absolute_word: 40 return ELF::R_MICROBLAZE_NONE; 41 default: 42 llvm_unreachable("unknown mblaze machine relocation type"); 43 } 44 return 0; 45 } 46 47 long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy, 48 long int Modifier) const { 49 switch (RelTy) { 50 case ELF::R_MICROBLAZE_32_PCREL: 51 return Modifier - 4; 52 case ELF::R_MICROBLAZE_32: 53 return Modifier; 54 default: 55 llvm_unreachable("unknown mblaze relocation type"); 56 } 57 return 0; 58 } 59 60 unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const { 61 // FIXME: Most of these sizes are guesses based on the name 62 switch (RelTy) { 63 case ELF::R_MICROBLAZE_32: 64 case ELF::R_MICROBLAZE_32_PCREL: 65 case ELF::R_MICROBLAZE_32_PCREL_LO: 66 case ELF::R_MICROBLAZE_32_LO: 67 case ELF::R_MICROBLAZE_SRO32: 68 case ELF::R_MICROBLAZE_SRW32: 69 case ELF::R_MICROBLAZE_32_SYM_OP_SYM: 70 case ELF::R_MICROBLAZE_GOTOFF_32: 71 return 32; 72 73 case ELF::R_MICROBLAZE_64_PCREL: 74 case ELF::R_MICROBLAZE_64: 75 case ELF::R_MICROBLAZE_GOTPC_64: 76 case ELF::R_MICROBLAZE_GOT_64: 77 case ELF::R_MICROBLAZE_PLT_64: 78 case ELF::R_MICROBLAZE_GOTOFF_64: 79 return 64; 80 } 81 82 return 0; 83 } 84 85 bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const { 86 // FIXME: Most of these are guesses based on the name 87 switch (RelTy) { 88 case ELF::R_MICROBLAZE_32_PCREL: 89 case ELF::R_MICROBLAZE_64_PCREL: 90 case ELF::R_MICROBLAZE_32_PCREL_LO: 91 case ELF::R_MICROBLAZE_GOTPC_64: 92 return true; 93 } 94 95 return false; 96 } 97 98 unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const { 99 return MBlaze::reloc_absolute_word; 100 } 101 102 long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset, 103 unsigned RelOffset, 104 unsigned RelTy) const { 105 if (RelTy == ELF::R_MICROBLAZE_32_PCREL || ELF::R_MICROBLAZE_64_PCREL) 106 return SymOffset - (RelOffset + 4); 107 else 108 assert("computeRelocation unknown for this relocation type"); 109 110 return 0; 111 } 112