Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 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 "X86TargetObjectFile.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame^] | 11 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Chris Lattner | 228252f | 2009-09-18 20:22:52 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame^] | 14 | #include "llvm/Target/Mangler.h" |
| 15 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Chris Lattner | 228252f | 2009-09-18 20:22:52 +0000 | [diff] [blame] | 18 | const MCExpr *X8632_MachoTargetObjectFile:: |
| 19 | getSymbolForDwarfGlobalReference(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 | |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame^] | 30 | // FIXME: Use GetSymbolWithGlobalValueBase. |
Chris Lattner | 228252f | 2009-09-18 20:22:52 +0000 | [diff] [blame] | 31 | SmallString<128> Name; |
| 32 | Mang->getNameWithPrefix(Name, GV, true); |
| 33 | Name += "$non_lazy_ptr"; |
| 34 | |
| 35 | // Add information about the stub reference to MachOMMI so that the stub gets |
| 36 | // emitted by the asmprinter. |
| 37 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str()); |
| 38 | const MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym); |
| 39 | if (StubSym == 0) { |
| 40 | Name.clear(); |
| 41 | Mang->getNameWithPrefix(Name, GV, false); |
| 42 | StubSym = getContext().GetOrCreateSymbol(Name.str()); |
| 43 | } |
| 44 | |
| 45 | return MCSymbolRefExpr::Create(Sym, getContext()); |
| 46 | } |
| 47 | |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 48 | const MCExpr *X8664_MachoTargetObjectFile:: |
| 49 | getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, |
Chris Lattner | 8609c7c | 2009-09-17 18:49:52 +0000 | [diff] [blame] | 50 | MachineModuleInfo *MMI, |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 51 | bool &IsIndirect, bool &IsPCRel) const { |
| 52 | |
| 53 | // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which |
| 54 | // is an indirect pc-relative reference. |
| 55 | IsIndirect = true; |
| 56 | IsPCRel = true; |
| 57 | |
| 58 | SmallString<128> Name; |
| 59 | Mang->getNameWithPrefix(Name, GV, false); |
| 60 | Name += "@GOTPCREL"; |
| 61 | const MCExpr *Res = |
| 62 | MCSymbolRefExpr::Create(Name.str(), getContext()); |
| 63 | const MCExpr *Four = MCConstantExpr::Create(4, getContext()); |
| 64 | return MCBinaryExpr::CreateAdd(Res, Four, getContext()); |
| 65 | } |
| 66 | |