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 MBlazeELFWriterInfo(TargetMachine & TM)28MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM) 29 : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64, 30 TM.getTargetData()->isLittleEndian()) { 31 } 32 ~MBlazeELFWriterInfo()33MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {} 34 getRelocationType(unsigned MachineRelTy) const35unsigned 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 } 45 getDefaultAddendForRelTy(unsigned RelTy,long int Modifier) const46long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy, 47 long int Modifier) const { 48 switch (RelTy) { 49 case ELF::R_MICROBLAZE_32_PCREL: 50 return Modifier - 4; 51 case ELF::R_MICROBLAZE_32: 52 return Modifier; 53 default: 54 llvm_unreachable("unknown mblaze relocation type"); 55 } 56 } 57 getRelocationTySize(unsigned RelTy) const58unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const { 59 // FIXME: Most of these sizes are guesses based on the name 60 switch (RelTy) { 61 case ELF::R_MICROBLAZE_32: 62 case ELF::R_MICROBLAZE_32_PCREL: 63 case ELF::R_MICROBLAZE_32_PCREL_LO: 64 case ELF::R_MICROBLAZE_32_LO: 65 case ELF::R_MICROBLAZE_SRO32: 66 case ELF::R_MICROBLAZE_SRW32: 67 case ELF::R_MICROBLAZE_32_SYM_OP_SYM: 68 case ELF::R_MICROBLAZE_GOTOFF_32: 69 return 32; 70 71 case ELF::R_MICROBLAZE_64_PCREL: 72 case ELF::R_MICROBLAZE_64: 73 case ELF::R_MICROBLAZE_GOTPC_64: 74 case ELF::R_MICROBLAZE_GOT_64: 75 case ELF::R_MICROBLAZE_PLT_64: 76 case ELF::R_MICROBLAZE_GOTOFF_64: 77 return 64; 78 } 79 80 return 0; 81 } 82 isPCRelativeRel(unsigned RelTy) const83bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const { 84 // FIXME: Most of these are guesses based on the name 85 switch (RelTy) { 86 case ELF::R_MICROBLAZE_32_PCREL: 87 case ELF::R_MICROBLAZE_64_PCREL: 88 case ELF::R_MICROBLAZE_32_PCREL_LO: 89 case ELF::R_MICROBLAZE_GOTPC_64: 90 return true; 91 } 92 93 return false; 94 } 95 getAbsoluteLabelMachineRelTy() const96unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const { 97 return MBlaze::reloc_absolute_word; 98 } 99 computeRelocation(unsigned SymOffset,unsigned RelOffset,unsigned RelTy) const100long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset, 101 unsigned RelOffset, 102 unsigned RelTy) const { 103 assert((RelTy == ELF::R_MICROBLAZE_32_PCREL || 104 RelTy == ELF::R_MICROBLAZE_64_PCREL) && 105 "computeRelocation unknown for this relocation type"); 106 return SymOffset - (RelOffset + 4); 107 } 108