zpu: managed to compile program that writes constant to global variable
[llvm/zpu.git] / lib / Target / MBlaze / MBlazeELFWriterInfo.cpp
blob378b5d469fb7b60af85a3bbef42197ac1f26e1b8
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.
12 //===----------------------------------------------------------------------===//
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"
21 using namespace llvm;
23 //===----------------------------------------------------------------------===//
24 // Implementation of the MBlazeELFWriterInfo class
25 //===----------------------------------------------------------------------===//
27 MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM)
28 : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64,
29 TM.getTargetData()->isLittleEndian()) {
32 MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {}
34 unsigned MBlazeELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
35 switch(MachineRelTy) {
36 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");
43 return 0;
46 long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
47 long int Modifier) const {
48 switch(RelTy) {
49 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");
56 return 0;
59 unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
60 // FIXME: Most of these sizes are guesses based on the name
61 switch(RelTy) {
62 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;
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;
81 return 0;
84 bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
85 // FIXME: Most of these are guesses based on the name
86 switch(RelTy) {
87 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;
94 return false;
97 unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
98 return MBlaze::reloc_absolute_word;
101 long 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");
109 return 0;