X86TargetObjectFile.cpp revision 204961
1//===-- llvm/Target/X86/X86TargetObjectFile.cpp - X86 Object Info ---------===//
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#include "X86MCTargetExpr.h"
11#include "X86TargetObjectFile.h"
12#include "X86TargetMachine.h"
13#include "llvm/CodeGen/MachineModuleInfoImpls.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/Target/Mangler.h"
16#include "llvm/ADT/SmallString.h"
17#include "llvm/Support/Dwarf.h"
18using namespace llvm;
19using namespace dwarf;
20
21const MCExpr *X8664_MachoTargetObjectFile::
22getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
23                                 MachineModuleInfo *MMI,
24                                 unsigned Encoding) const {
25
26  // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
27  // is an indirect pc-relative reference.
28  if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
29    SmallString<128> Name;
30    Mang->getNameWithPrefix(Name, GV, false);
31    const MCSymbol *Sym;
32    if (GV->hasPrivateLinkage())
33      Sym = getContext().GetOrCreateTemporarySymbol(Name);
34    else
35      Sym = getContext().GetOrCreateSymbol(Name);
36    const MCExpr *Res =
37      X86MCTargetExpr::Create(Sym, X86MCTargetExpr::GOTPCREL, getContext());
38    const MCExpr *Four = MCConstantExpr::Create(4, getContext());
39    return MCBinaryExpr::CreateAdd(Res, Four, getContext());
40  }
41
42  return TargetLoweringObjectFileMachO::
43    getSymbolForDwarfGlobalReference(GV, Mang, MMI, Encoding);
44}
45
46unsigned X8632_ELFTargetObjectFile::getPersonalityEncoding() const {
47  if (TM.getRelocationModel() == Reloc::PIC_)
48    return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4;
49  else
50    return DW_EH_PE_absptr;
51}
52
53unsigned X8632_ELFTargetObjectFile::getLSDAEncoding() const {
54  if (TM.getRelocationModel() == Reloc::PIC_)
55    return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
56  else
57    return DW_EH_PE_absptr;
58}
59
60unsigned X8632_ELFTargetObjectFile::getFDEEncoding() const {
61  if (TM.getRelocationModel() == Reloc::PIC_)
62    return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
63  else
64    return DW_EH_PE_absptr;
65}
66
67unsigned X8632_ELFTargetObjectFile::getTTypeEncoding() const {
68  if (TM.getRelocationModel() == Reloc::PIC_)
69    return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4;
70  else
71    return DW_EH_PE_absptr;
72}
73
74unsigned X8664_ELFTargetObjectFile::getPersonalityEncoding() const {
75  CodeModel::Model Model = TM.getCodeModel();
76  if (TM.getRelocationModel() == Reloc::PIC_)
77    return DW_EH_PE_indirect | DW_EH_PE_pcrel | (Model == CodeModel::Small ||
78                                                 Model == CodeModel::Medium ?
79                                            DW_EH_PE_sdata4 : DW_EH_PE_sdata8);
80
81  if (Model == CodeModel::Small || Model == CodeModel::Medium)
82    return DW_EH_PE_udata4;
83
84  return DW_EH_PE_absptr;
85}
86
87unsigned X8664_ELFTargetObjectFile::getLSDAEncoding() const {
88  CodeModel::Model Model = TM.getCodeModel();
89  if (TM.getRelocationModel() == Reloc::PIC_)
90    return DW_EH_PE_pcrel | (Model == CodeModel::Small ?
91                             DW_EH_PE_sdata4 : DW_EH_PE_sdata8);
92
93  if (Model == CodeModel::Small)
94    return DW_EH_PE_udata4;
95
96  return DW_EH_PE_absptr;
97}
98
99unsigned X8664_ELFTargetObjectFile::getFDEEncoding() const {
100  CodeModel::Model Model = TM.getCodeModel();
101  if (TM.getRelocationModel() == Reloc::PIC_)
102    return DW_EH_PE_pcrel | (Model == CodeModel::Small ||
103                             Model == CodeModel::Medium ?
104                             DW_EH_PE_sdata4 : DW_EH_PE_sdata8);
105
106  if (Model == CodeModel::Small || Model == CodeModel::Medium)
107    return DW_EH_PE_udata4;
108
109  return DW_EH_PE_absptr;
110}
111
112unsigned X8664_ELFTargetObjectFile::getTTypeEncoding() const {
113  CodeModel::Model Model = TM.getCodeModel();
114  if (TM.getRelocationModel() == Reloc::PIC_)
115    return DW_EH_PE_indirect | DW_EH_PE_pcrel | (Model == CodeModel::Small ||
116                                                 Model == CodeModel::Medium ?
117                                            DW_EH_PE_sdata4 : DW_EH_PE_sdata8);
118
119  if (Model == CodeModel::Small)
120    return DW_EH_PE_udata4;
121
122  return DW_EH_PE_absptr;
123}
124