blob: 92aee0dd3fcfd953ae44ad58ca8ca87d5c96de91 [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"
11#include "X86TargetMachine.h"
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000012#include "llvm/ADT/StringExtras.h"
Chris Lattnerf62e3ee2010-01-16 21:57:06 +000013#include "llvm/CodeGen/MachineModuleInfoImpls.h"
Chris Lattner3a78ce32009-09-18 20:22:52 +000014#include "llvm/MC/MCContext.h"
Daniel Dunbar55992562010-03-15 23:51:06 +000015#include "llvm/MC/MCExpr.h"
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000016#include "llvm/MC/MCSectionELF.h"
Bill Wendling03448742010-03-15 19:04:37 +000017#include "llvm/MC/MCSectionMachO.h"
Chris Lattnerf62e3ee2010-01-16 21:57:06 +000018#include "llvm/Target/Mangler.h"
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000019#include "llvm/Support/Dwarf.h"
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000020#include "llvm/Support/ELF.h"
Chris Lattnerb8666022009-09-16 01:46:41 +000021using namespace llvm;
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000022using namespace dwarf;
Chris Lattnerb8666022009-09-16 01:46:41 +000023
Bill Wendling8ed44462012-06-26 10:05:06 +000024const MCExpr *X86_64MachoTargetObjectFile::
Chris Lattner25623562010-03-11 19:41:58 +000025getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
26 MachineModuleInfo *MMI, unsigned Encoding,
27 MCStreamer &Streamer) const {
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000028
Chris Lattnerb8666022009-09-16 01:46:41 +000029 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
30 // is an indirect pc-relative reference.
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000031 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
Chris Lattnerc116a872010-03-15 20:37:57 +000032 const MCSymbol *Sym = Mang->getSymbol(GV);
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000033 const MCExpr *Res =
Daniel Dunbar55992562010-03-15 23:51:06 +000034 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
Anton Korobeynikovc9adb6a2010-02-15 22:38:10 +000035 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
36 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +000037 }
38
39 return TargetLoweringObjectFileMachO::
Chris Lattner25623562010-03-11 19:41:58 +000040 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
Chris Lattnerb8666022009-09-16 01:46:41 +000041}
42
Bill Wendling8ed44462012-06-26 10:05:06 +000043MCSymbol *X86_64MachoTargetObjectFile::
Rafael Espindolace83fc32011-04-27 23:17:57 +000044getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
Rafael Espindola08704342011-04-27 23:08:15 +000045 MachineModuleInfo *MMI) const {
46 return Mang->getSymbol(GV);
47}
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000048
49void
50X86LinuxTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
51 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
52 InitializeELF(TM.Options.UseInitArray);
53}