blob: cf6312f0170823541ce0c6523df0bbe3a0b067c0 [file] [log] [blame]
Wesley Peck4e9141f2010-10-21 03:57:26 +00001//===-- 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/ErrorHandling.h"
18#include "llvm/Target/TargetData.h"
19#include "llvm/Target/TargetMachine.h"
20
21using namespace llvm;
22
23//===----------------------------------------------------------------------===//
24// Implementation of the MBlazeELFWriterInfo class
25//===----------------------------------------------------------------------===//
26
27MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM)
28 : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64,
29 TM.getTargetData()->isLittleEndian()) {
30}
31
32MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {}
33
34unsigned MBlazeELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
Wesley Peck0a67d922010-11-08 19:40:01 +000035 switch (MachineRelTy) {
Wesley Peck4e9141f2010-10-21 03:57:26 +000036 case MBlaze::reloc_pcrel_word:
37 return R_MICROBLAZE_64_PCREL;
38 case MBlaze::reloc_absolute_word:
39 return R_MICROBLAZE_NONE;
40 default:
41 llvm_unreachable("unknown mblaze machine relocation type");
42 }
43 return 0;
44}
45
46long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
47 long int Modifier) const {
Wesley Peck0a67d922010-11-08 19:40:01 +000048 switch (RelTy) {
Wesley Peck4e9141f2010-10-21 03:57:26 +000049 case R_MICROBLAZE_32_PCREL:
50 return Modifier - 4;
51 case R_MICROBLAZE_32:
52 return Modifier;
53 default:
54 llvm_unreachable("unknown mblaze relocation type");
55 }
56 return 0;
57}
58
59unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
60 // FIXME: Most of these sizes are guesses based on the name
Wesley Peck0a67d922010-11-08 19:40:01 +000061 switch (RelTy) {
Wesley Peck4e9141f2010-10-21 03:57:26 +000062 case R_MICROBLAZE_32:
63 case R_MICROBLAZE_32_PCREL:
64 case R_MICROBLAZE_32_PCREL_LO:
65 case R_MICROBLAZE_32_LO:
66 case R_MICROBLAZE_SRO32:
67 case R_MICROBLAZE_SRW32:
68 case R_MICROBLAZE_32_SYM_OP_SYM:
69 case R_MICROBLAZE_GOTOFF_32:
70 return 32;
71
72 case R_MICROBLAZE_64_PCREL:
73 case R_MICROBLAZE_64:
74 case R_MICROBLAZE_GOTPC_64:
75 case R_MICROBLAZE_GOT_64:
76 case R_MICROBLAZE_PLT_64:
77 case R_MICROBLAZE_GOTOFF_64:
78 return 64;
79 }
80
81 return 0;
82}
83
84bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
85 // FIXME: Most of these are guesses based on the name
Wesley Peck0a67d922010-11-08 19:40:01 +000086 switch (RelTy) {
Wesley Peck4e9141f2010-10-21 03:57:26 +000087 case R_MICROBLAZE_32_PCREL:
88 case R_MICROBLAZE_64_PCREL:
89 case R_MICROBLAZE_32_PCREL_LO:
90 case R_MICROBLAZE_GOTPC_64:
91 return true;
92 }
93
94 return false;
95}
96
97unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
98 return MBlaze::reloc_absolute_word;
99}
100
101long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset,
102 unsigned RelOffset,
103 unsigned RelTy) const {
104 if (RelTy == R_MICROBLAZE_32_PCREL || R_MICROBLAZE_64_PCREL)
105 return SymOffset - (RelOffset + 4);
106 else
107 assert("computeRelocation unknown for this relocation type");
108
109 return 0;
110}