1 //===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "X86TargetObjectFile.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/BinaryFormat/COFF.h"
13 #include "llvm/BinaryFormat/Dwarf.h"
14 #include "llvm/CodeGen/TargetLowering.h"
15 #include "llvm/IR/Mangler.h"
16 #include "llvm/IR/Operator.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCSectionCOFF.h"
20 #include "llvm/MC/MCSectionELF.h"
21 #include "llvm/MC/MCValue.h"
24 using namespace dwarf
;
26 const MCExpr
*X86_64MachoTargetObjectFile::getTTypeGlobalReference(
27 const GlobalValue
*GV
, unsigned Encoding
, const TargetMachine
&TM
,
28 MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
30 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
31 // is an indirect pc-relative reference.
32 if ((Encoding
& DW_EH_PE_indirect
) && (Encoding
& DW_EH_PE_pcrel
)) {
33 const MCSymbol
*Sym
= TM
.getSymbol(GV
);
35 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
36 const MCExpr
*Four
= MCConstantExpr::create(4, getContext());
37 return MCBinaryExpr::createAdd(Res
, Four
, getContext());
40 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
41 GV
, Encoding
, TM
, MMI
, Streamer
);
44 MCSymbol
*X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
45 const GlobalValue
*GV
, const TargetMachine
&TM
,
46 MachineModuleInfo
*MMI
) const {
47 return TM
.getSymbol(GV
);
50 const MCExpr
*X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
51 const MCSymbol
*Sym
, const MCValue
&MV
, int64_t Offset
,
52 MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
53 // On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
54 // from a data section. In case there's an additional offset, then use
55 // foo@GOTPCREL+4+<offset>.
56 unsigned FinalOff
= Offset
+MV
.getConstant()+4;
58 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
59 const MCExpr
*Off
= MCConstantExpr::create(FinalOff
, getContext());
60 return MCBinaryExpr::createAdd(Res
, Off
, getContext());
63 const MCExpr
*X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
64 const MCSymbol
*Sym
) const {
65 return MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_DTPOFF
, getContext());
69 X86FreeBSDTargetObjectFile::Initialize(MCContext
&Ctx
,
70 const TargetMachine
&TM
) {
71 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
72 InitializeELF(TM
.Options
.UseInitArray
);
76 X86FuchsiaTargetObjectFile::Initialize(MCContext
&Ctx
,
77 const TargetMachine
&TM
) {
78 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
79 InitializeELF(TM
.Options
.UseInitArray
);
83 X86LinuxNaClTargetObjectFile::Initialize(MCContext
&Ctx
,
84 const TargetMachine
&TM
) {
85 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
86 InitializeELF(TM
.Options
.UseInitArray
);
89 void X86SolarisTargetObjectFile::Initialize(MCContext
&Ctx
,
90 const TargetMachine
&TM
) {
91 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
92 InitializeELF(TM
.Options
.UseInitArray
);