1 //===-- llvm/Target/X86/X86TargetObjectFile.cpp - X86 Object Info ---------===//
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 #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"
19 using namespace dwarf;
21 const MCExpr *X8664_MachoTargetObjectFile::
22 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
23 MachineModuleInfo *MMI, unsigned Encoding,
24 MCStreamer &Streamer) const {
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);
32 if (GV->hasPrivateLinkage())
33 Sym = getContext().GetOrCreateTemporarySymbol(Name);
35 Sym = getContext().GetOrCreateSymbol(Name);
37 X86MCTargetExpr::Create(Sym, X86MCTargetExpr::GOTPCREL, getContext());
38 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
39 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
42 return TargetLoweringObjectFileMachO::
43 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
46 unsigned X8632_ELFTargetObjectFile::getPersonalityEncoding() const {
47 if (TM.getRelocationModel() == Reloc::PIC_)
48 return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4;
50 return DW_EH_PE_absptr;
53 unsigned X8632_ELFTargetObjectFile::getLSDAEncoding() const {
54 if (TM.getRelocationModel() == Reloc::PIC_)
55 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
57 return DW_EH_PE_absptr;
60 unsigned X8632_ELFTargetObjectFile::getFDEEncoding() const {
61 if (TM.getRelocationModel() == Reloc::PIC_)
62 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
64 return DW_EH_PE_absptr;
67 unsigned X8632_ELFTargetObjectFile::getTTypeEncoding() const {
68 if (TM.getRelocationModel() == Reloc::PIC_)
69 return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4;
71 return DW_EH_PE_absptr;
74 unsigned 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);
81 if (Model == CodeModel::Small || Model == CodeModel::Medium)
82 return DW_EH_PE_udata4;
84 return DW_EH_PE_absptr;
87 unsigned 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);
93 if (Model == CodeModel::Small)
94 return DW_EH_PE_udata4;
96 return DW_EH_PE_absptr;
99 unsigned 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);
106 if (Model == CodeModel::Small || Model == CodeModel::Medium)
107 return DW_EH_PE_udata4;
109 return DW_EH_PE_absptr;
112 unsigned 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);
119 if (Model == CodeModel::Small)
120 return DW_EH_PE_udata4;
122 return DW_EH_PE_absptr;