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/Target/TargetData.h"
18 #include "llvm/Target/TargetMachine.h"
22 //===----------------------------------------------------------------------===//
23 // Implementation of the X86ELFWriterInfo class
24 //===----------------------------------------------------------------------===//
26 X86ELFWriterInfo::X86ELFWriterInfo(TargetMachine &TM)
27 : TargetELFWriterInfo(TM) {
28 bool is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
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_dword:
43 case X86::reloc_picrel_word:
45 assert(0 && "unknown relocation type");
48 switch(MachineRelTy) {
49 case X86::reloc_pcrel_word:
51 case X86::reloc_absolute_word:
53 case X86::reloc_absolute_dword:
54 case X86::reloc_picrel_word:
56 assert(0 && "unknown relocation type");
62 unsigned X86ELFWriterInfo::getFunctionAlignment(const Function *F) const {
65 if (F->hasFnAttr(Attribute::OptimizeForSize))
68 if (F->getAlignment())
69 FnAlign = Log2_32(F->getAlignment());
71 return (1 << FnAlign);
74 long int X86ELFWriterInfo::getAddendForRelTy(unsigned RelTy) const {
77 case R_X86_64_PC32: return -4;
80 assert(0 && "unknown x86 relocation type");