912ab0e886f4d8539567eb918e94ae05f7ec2cb6
[oota-llvm.git] / lib / Target / X86 / X86ELFWriterInfo.cpp
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.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86ELFWriterInfo.h"
15 #include "X86Relocations.h"
16 #include "llvm/Function.h"
17 #include "llvm/Target/TargetData.h"
18 #include "llvm/Target/TargetMachine.h"
19
20 using namespace llvm;
21
22 //===----------------------------------------------------------------------===//
23 //  Implementation of the X86ELFWriterInfo class
24 //===----------------------------------------------------------------------===//
25
26 X86ELFWriterInfo::X86ELFWriterInfo(TargetMachine &TM)
27   : TargetELFWriterInfo(TM) {
28     bool is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
29     EMachine = is64Bit ? EM_X86_64 : EM_386;
30   }
31
32 X86ELFWriterInfo::~X86ELFWriterInfo() {}
33
34 unsigned X86ELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
35   if (is64Bit) {
36     switch(MachineRelTy) {
37     case X86::reloc_pcrel_word:
38       return R_X86_64_PC32;
39     case X86::reloc_absolute_word:
40       return R_X86_64_32;
41     case X86::reloc_absolute_dword:
42       return R_X86_64_64;
43     case X86::reloc_picrel_word:
44     default:
45       assert(0 && "unknown relocation type");
46     }
47   } else {
48     switch(MachineRelTy) {
49     case X86::reloc_pcrel_word:
50       return R_386_PC32;
51     case X86::reloc_absolute_word:
52       return R_386_32;
53     case X86::reloc_absolute_dword:
54     case X86::reloc_picrel_word:
55     default:
56       assert(0 && "unknown relocation type");
57     }
58   }
59   return 0;
60 }
61
62 long int X86ELFWriterInfo::getAddendForRelTy(unsigned RelTy) const {
63   if (is64Bit) {
64     switch(RelTy) {
65     case R_X86_64_PC32: return -4;
66       break;
67     default:
68       assert(0 && "unknown x86 relocation type");
69     }
70   }
71   return 0;
72 }