Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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" |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ELF.h" |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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 { |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 36 | switch (MachineRelTy) { |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 37 | case MBlaze::reloc_pcrel_word: |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 38 | return ELF::R_MICROBLAZE_64_PCREL; |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 39 | case MBlaze::reloc_absolute_word: |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 40 | return ELF::R_MICROBLAZE_NONE; |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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 { |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 49 | switch (RelTy) { |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 50 | case ELF::R_MICROBLAZE_32_PCREL: |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 51 | return Modifier - 4; |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 52 | case ELF::R_MICROBLAZE_32: |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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 |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 62 | switch (RelTy) { |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 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: |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 71 | return 32; |
| 72 | |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 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: |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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 |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 87 | switch (RelTy) { |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 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: |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 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 { |
Wesley Peck | 4b04713 | 2010-11-21 22:06:28 +0000 | [diff] [blame] | 105 | if (RelTy == ELF::R_MICROBLAZE_32_PCREL || ELF::R_MICROBLAZE_64_PCREL) |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 106 | return SymOffset - (RelOffset + 4); |
| 107 | else |
| 108 | assert("computeRelocation unknown for this relocation type"); |
| 109 | |
| 110 | return 0; |
| 111 | } |