Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===// |
Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 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 | |
Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 10 | #include "X86TargetObjectFile.h" |
Chandler Carruth | 07baed5 | 2014-01-13 08:04:33 +0000 | [diff] [blame^] | 11 | #include "llvm/IR/Mangler.h" |
Chris Lattner | 3a78ce3 | 2009-09-18 20:22:52 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCContext.h" |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCExpr.h" |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCSectionELF.h" |
Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Dwarf.h" |
Jakub Staszak | ab3d878 | 2013-01-10 23:43:56 +0000 | [diff] [blame] | 16 | |
Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 17 | using namespace llvm; |
Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 18 | using namespace dwarf; |
Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 19 | |
Bill Wendling | 8ed4446 | 2012-06-26 10:05:06 +0000 | [diff] [blame] | 20 | const MCExpr *X86_64MachoTargetObjectFile:: |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 21 | getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, |
| 22 | MachineModuleInfo *MMI, unsigned Encoding, |
| 23 | MCStreamer &Streamer) const { |
Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 24 | |
Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 25 | // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which |
| 26 | // is an indirect pc-relative reference. |
Anton Korobeynikov | c9adb6a | 2010-02-15 22:38:10 +0000 | [diff] [blame] | 27 | if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { |
Rafael Espindola | e133ed8 | 2013-10-29 17:28:26 +0000 | [diff] [blame] | 28 | const MCSymbol *Sym = getSymbol(*Mang, GV); |
Anton Korobeynikov | c9adb6a | 2010-02-15 22:38:10 +0000 | [diff] [blame] | 29 | const MCExpr *Res = |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 30 | MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext()); |
Anton Korobeynikov | c9adb6a | 2010-02-15 22:38:10 +0000 | [diff] [blame] | 31 | const MCExpr *Four = MCConstantExpr::Create(4, getContext()); |
| 32 | return MCBinaryExpr::CreateAdd(Res, Four, getContext()); |
Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | return TargetLoweringObjectFileMachO:: |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 36 | getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer); |
Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Bill Wendling | 8ed4446 | 2012-06-26 10:05:06 +0000 | [diff] [blame] | 39 | MCSymbol *X86_64MachoTargetObjectFile:: |
Rafael Espindola | ce83fc3 | 2011-04-27 23:17:57 +0000 | [diff] [blame] | 40 | getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, |
Rafael Espindola | 0870434 | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 41 | MachineModuleInfo *MMI) const { |
Rafael Espindola | e133ed8 | 2013-10-29 17:28:26 +0000 | [diff] [blame] | 42 | return getSymbol(*Mang, GV); |
Rafael Espindola | 0870434 | 2011-04-27 23:08:15 +0000 | [diff] [blame] | 43 | } |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 44 | |
| 45 | void |
| 46 | X86LinuxTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { |
| 47 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); |
| 48 | InitializeELF(TM.Options.UseInitArray); |
| 49 | } |
David Blaikie | 1b01ae8 | 2013-07-01 21:45:25 +0000 | [diff] [blame] | 50 | |
Ulrich Weigand | 2b6fc8d | 2013-07-02 18:47:09 +0000 | [diff] [blame] | 51 | const MCExpr * |
David Blaikie | 1b01ae8 | 2013-07-01 21:45:25 +0000 | [diff] [blame] | 52 | X86LinuxTargetObjectFile::getDebugThreadLocalSymbol( |
| 53 | const MCSymbol *Sym) const { |
| 54 | return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext()); |
| 55 | } |