1 //===-- X86ELFWriterInfo.cpp - ELF Writer Info for the X86 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 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"
23 //===----------------------------------------------------------------------===//
24 // Implementation of the X86ELFWriterInfo class
25 //===----------------------------------------------------------------------===//
27 X86ELFWriterInfo::X86ELFWriterInfo(TargetMachine &TM)
28 : TargetELFWriterInfo(TM) {
29 EMachine = is64Bit ? EM_X86_64 : EM_386;
32 X86ELFWriterInfo::~X86ELFWriterInfo() {}
34 unsigned X86ELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
36 switch(MachineRelTy) {
37 case X86::reloc_pcrel_word:
39 case X86::reloc_absolute_word:
41 case X86::reloc_absolute_word_sext:
43 case X86::reloc_absolute_dword:
45 case X86::reloc_picrel_word:
47 llvm_unreachable("unknown x86_64 machine relocation type");
50 switch(MachineRelTy) {
51 case X86::reloc_pcrel_word:
53 case X86::reloc_absolute_word:
55 case X86::reloc_absolute_word_sext:
56 case X86::reloc_absolute_dword:
57 case X86::reloc_picrel_word:
59 llvm_unreachable("unknown x86 machine relocation type");
65 long int X86ELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
66 long int Modifier) const {
69 case R_X86_64_PC32: return Modifier - 4;
75 llvm_unreachable("unknown x86_64 relocation type");
79 case R_386_PC32: return Modifier - 4;
80 case R_386_32: return Modifier;
82 llvm_unreachable("unknown x86 relocation type");
88 unsigned X86ELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
98 llvm_unreachable("unknown x86_64 relocation type");
106 llvm_unreachable("unknown x86 relocation type");
112 bool X86ELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
122 llvm_unreachable("unknown x86_64 relocation type");
131 llvm_unreachable("unknown x86 relocation type");
137 unsigned X86ELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
139 X86::reloc_absolute_dword : X86::reloc_absolute_word;
142 long int X86ELFWriterInfo::computeRelocation(unsigned SymOffset,
144 unsigned RelTy) const {
146 if (RelTy == R_X86_64_PC32 || RelTy == R_386_PC32)
147 return SymOffset - (RelOffset + 4);
149 assert("computeRelocation unknown for this relocation type");