Fix part 1 of pr4682. PICADD is a 16-bit instruction even in thumb2 mode.
[llvm/avr.git] / lib / Target / X86 / X86ELFWriterInfo.cpp
blob096c00ee305840f051fca0998720d4a486ede4fc
1 //===-- X86ELFWriterInfo.cpp - ELF Writer Info for the X86 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 X86 backend.
12 //===----------------------------------------------------------------------===//
14 #include "X86ELFWriterInfo.h"
15 #include "X86Relocations.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 X86ELFWriterInfo class
25 //===----------------------------------------------------------------------===//
27 X86ELFWriterInfo::X86ELFWriterInfo(TargetMachine &TM)
28 : TargetELFWriterInfo(TM) {
29 bool is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
30 EMachine = is64Bit ? EM_X86_64 : EM_386;
33 X86ELFWriterInfo::~X86ELFWriterInfo() {}
35 unsigned X86ELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
36 if (is64Bit) {
37 switch(MachineRelTy) {
38 case X86::reloc_pcrel_word:
39 return R_X86_64_PC32;
40 case X86::reloc_absolute_word:
41 return R_X86_64_32;
42 case X86::reloc_absolute_dword:
43 return R_X86_64_64;
44 case X86::reloc_picrel_word:
45 default:
46 llvm_unreachable("unknown x86_64 machine relocation type");
48 } else {
49 switch(MachineRelTy) {
50 case X86::reloc_pcrel_word:
51 return R_386_PC32;
52 case X86::reloc_absolute_word:
53 return R_386_32;
54 case X86::reloc_absolute_dword:
55 case X86::reloc_picrel_word:
56 default:
57 llvm_unreachable("unknown x86 machine relocation type");
60 return 0;
63 long int X86ELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy) const {
64 if (is64Bit) {
65 switch(RelTy) {
66 case R_X86_64_PC32: return -4;
67 case R_X86_64_32:
68 case R_X86_64_64:
69 return 0;
70 default:
71 llvm_unreachable("unknown x86_64 relocation type");
73 } else {
74 switch(RelTy) {
75 case R_386_PC32: return -4;
76 case R_386_32: return 0;
77 default:
78 llvm_unreachable("unknown x86 relocation type");
81 return 0;
84 unsigned X86ELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
85 if (is64Bit) {
86 switch(RelTy) {
87 case R_X86_64_PC32:
88 case R_X86_64_32:
89 case R_X86_64_32S:
90 return 32;
91 case R_X86_64_64:
92 return 64;
93 default:
94 llvm_unreachable("unknown x86_64 relocation type");
96 } else {
97 switch(RelTy) {
98 case R_386_PC32:
99 case R_386_32:
100 return 32;
101 default:
102 llvm_unreachable("unknown x86 relocation type");
105 return 0;
108 bool X86ELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
109 if (is64Bit) {
110 switch(RelTy) {
111 case R_X86_64_PC32:
112 return true;
113 case R_X86_64_32:
114 case R_X86_64_32S:
115 case R_X86_64_64:
116 return false;
117 default:
118 llvm_unreachable("unknown x86_64 relocation type");
120 } else {
121 switch(RelTy) {
122 case R_386_PC32:
123 return true;
124 case R_386_32:
125 return false;
126 default:
127 llvm_unreachable("unknown x86 relocation type");
130 return 0;
133 unsigned X86ELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
134 return is64Bit ?
135 X86::reloc_absolute_dword : X86::reloc_absolute_word;
138 long int X86ELFWriterInfo::computeRelocation(unsigned SymOffset,
139 unsigned RelOffset,
140 unsigned RelTy) const {
142 if (RelTy == R_X86_64_PC32 || RelTy == R_386_PC32)
143 return SymOffset - (RelOffset + 4);
144 else
145 assert("computeRelocation unknown for this relocation type");
147 return 0;