blob: 709fc972560d9a8a2b0464454c3411fe113dab66 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
Chris Lattnerb8666022009-09-16 01:46:41 +00002//
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 Korobeynikovae4ccc12010-02-15 22:35:59 +000010#include "X86TargetObjectFile.h"
Chandler Carruth07baed52014-01-13 08:04:33 +000011#include "llvm/IR/Mangler.h"
Chris Lattner3a78ce32009-09-18 20:22:52 +000012#include "llvm/MC/MCContext.h"
Daniel Dunbar55992562010-03-15 23:51:06 +000013#include "llvm/MC/MCExpr.h"
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000014#include "llvm/MC/MCSectionELF.h"
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000015#include "llvm/Support/Dwarf.h"
Jakub Staszakab3d8782013-01-10 23:43:56 +000016
Chris Lattnerb8666022009-09-16 01:46:41 +000017using namespace llvm;
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000018using namespace dwarf;
Chris Lattnerb8666022009-09-16 01:46:41 +000019
Bill Wendling8ed44462012-06-26 10:05:06 +000020const MCExpr *X86_64MachoTargetObjectFile::
Anton Korobeynikove42af362012-11-14 01:47:00 +000021getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
22 MachineModuleInfo *MMI, unsigned Encoding,
23 MCStreamer &Streamer) const {
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000024
Chris Lattnerb8666022009-09-16 01:46:41 +000025 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
26 // is an indirect pc-relative reference.
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000027 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
Rafael Espindolae133ed82013-10-29 17:28:26 +000028 const MCSymbol *Sym = getSymbol(*Mang, GV);
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000029 const MCExpr *Res =
Daniel Dunbar55992562010-03-15 23:51:06 +000030 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000031 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
32 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000033 }
34
35 return TargetLoweringObjectFileMachO::
Anton Korobeynikove42af362012-11-14 01:47:00 +000036 getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer);
Chris Lattnerb8666022009-09-16 01:46:41 +000037}
38
Bill Wendling8ed44462012-06-26 10:05:06 +000039MCSymbol *X86_64MachoTargetObjectFile::
Rafael Espindolace83fc32011-04-27 23:17:57 +000040getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
Rafael Espindola08704342011-04-27 23:08:15 +000041 MachineModuleInfo *MMI) const {
Rafael Espindolae133ed82013-10-29 17:28:26 +000042 return getSymbol(*Mang, GV);
Rafael Espindola08704342011-04-27 23:08:15 +000043}
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000044
45void
46X86LinuxTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
47 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
48 InitializeELF(TM.Options.UseInitArray);
49}
David Blaikie1b01ae82013-07-01 21:45:25 +000050
Ulrich Weigand2b6fc8d2013-07-02 18:47:09 +000051const MCExpr *
David Blaikie1b01ae82013-07-01 21:45:25 +000052X86LinuxTargetObjectFile::getDebugThreadLocalSymbol(
53 const MCSymbol *Sym) const {
54 return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
55}