1 //===-- MBlazeELFWriterInfo.cpp - ELF Writer Info for the MBlaze 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 MBlaze backend.
12 //===----------------------------------------------------------------------===//
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"
24 //===----------------------------------------------------------------------===//
25 // Implementation of the MBlazeELFWriterInfo class
26 //===----------------------------------------------------------------------===//
28 MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM)
29 : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64,
30 TM.getTargetData()->isLittleEndian()) {
33 MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {}
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;
42 llvm_unreachable("unknown mblaze machine relocation type");
46 long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
47 long int Modifier) const {
49 case ELF::R_MICROBLAZE_32_PCREL:
51 case ELF::R_MICROBLAZE_32:
54 llvm_unreachable("unknown mblaze relocation type");
58 unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
59 // FIXME: Most of these sizes are guesses based on the name
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:
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:
83 bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
84 // FIXME: Most of these are guesses based on the name
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:
96 unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
97 return MBlaze::reloc_absolute_word;
100 long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset,
102 unsigned RelTy) const {
103 if (RelTy == ELF::R_MICROBLAZE_32_PCREL || ELF::R_MICROBLAZE_64_PCREL)
104 return SymOffset - (RelOffset + 4);
106 llvm_unreachable("computeRelocation unknown for this relocation type");