blob: d39b3c4324205a7d8fc7606557a8a771188c9e61 [file] [log] [blame]
Chris Lattner8c6ed052009-09-16 01:46:41 +00001//===-- 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 "X86TargetObjectFile.h"
11#include "llvm/ADT/SmallString.h"
12#include "llvm/Support/Mangler.h"
Chris Lattner228252f2009-09-18 20:22:52 +000013#include "llvm/MC/MCContext.h"
Chris Lattner8c6ed052009-09-16 01:46:41 +000014#include "llvm/MC/MCExpr.h"
Chris Lattner228252f2009-09-18 20:22:52 +000015#include "llvm/CodeGen/MachineModuleInfoImpls.h"
Chris Lattner8c6ed052009-09-16 01:46:41 +000016using namespace llvm;
17
Chris Lattner228252f2009-09-18 20:22:52 +000018const MCExpr *X8632_MachoTargetObjectFile::
19getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
20 MachineModuleInfo *MMI,
21 bool &IsIndirect, bool &IsPCRel) const {
22 // The mach-o version of this method defaults to returning a stub reference.
23 IsIndirect = true;
24 IsPCRel = false;
25
26
27 MachineModuleInfoMachO &MachOMMI =
28 MMI->getObjFileInfo<MachineModuleInfoMachO>();
29
30 SmallString<128> Name;
31 Mang->getNameWithPrefix(Name, GV, true);
32 Name += "$non_lazy_ptr";
33
34 // Add information about the stub reference to MachOMMI so that the stub gets
35 // emitted by the asmprinter.
36 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
37 const MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
38 if (StubSym == 0) {
39 Name.clear();
40 Mang->getNameWithPrefix(Name, GV, false);
41 StubSym = getContext().GetOrCreateSymbol(Name.str());
42 }
43
44 return MCSymbolRefExpr::Create(Sym, getContext());
45}
46
Chris Lattner8c6ed052009-09-16 01:46:41 +000047const MCExpr *X8664_MachoTargetObjectFile::
48getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
Chris Lattner8609c7c2009-09-17 18:49:52 +000049 MachineModuleInfo *MMI,
Chris Lattner8c6ed052009-09-16 01:46:41 +000050 bool &IsIndirect, bool &IsPCRel) const {
51
52 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
53 // is an indirect pc-relative reference.
54 IsIndirect = true;
55 IsPCRel = true;
56
57 SmallString<128> Name;
58 Mang->getNameWithPrefix(Name, GV, false);
59 Name += "@GOTPCREL";
60 const MCExpr *Res =
61 MCSymbolRefExpr::Create(Name.str(), getContext());
62 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
63 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
64}
65