1 //===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "X86TargetObjectFile.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/BinaryFormat/COFF.h"
12 #include "llvm/BinaryFormat/Dwarf.h"
13 #include "llvm/CodeGen/TargetLowering.h"
14 #include "llvm/IR/Mangler.h"
15 #include "llvm/IR/Operator.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCSectionCOFF.h"
19 #include "llvm/MC/MCSectionELF.h"
20 #include "llvm/MC/MCValue.h"
23 using namespace dwarf
;
25 const MCExpr
*X86_64MachoTargetObjectFile::getTTypeGlobalReference(
26 const GlobalValue
*GV
, unsigned Encoding
, const TargetMachine
&TM
,
27 MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
29 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
30 // is an indirect pc-relative reference.
31 if ((Encoding
& DW_EH_PE_indirect
) && (Encoding
& DW_EH_PE_pcrel
)) {
32 const MCSymbol
*Sym
= TM
.getSymbol(GV
);
34 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
35 const MCExpr
*Four
= MCConstantExpr::create(4, getContext());
36 return MCBinaryExpr::createAdd(Res
, Four
, getContext());
39 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
40 GV
, Encoding
, TM
, MMI
, Streamer
);
43 MCSymbol
*X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
44 const GlobalValue
*GV
, const TargetMachine
&TM
,
45 MachineModuleInfo
*MMI
) const {
46 return TM
.getSymbol(GV
);
49 const MCExpr
*X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
50 const MCSymbol
*Sym
, const MCValue
&MV
, int64_t Offset
,
51 MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
52 // On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
53 // from a data section. In case there's an additional offset, then use
54 // foo@GOTPCREL+4+<offset>.
55 unsigned FinalOff
= Offset
+MV
.getConstant()+4;
57 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
58 const MCExpr
*Off
= MCConstantExpr::create(FinalOff
, getContext());
59 return MCBinaryExpr::createAdd(Res
, Off
, getContext());
62 const MCExpr
*X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
63 const MCSymbol
*Sym
) const {
64 return MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_DTPOFF
, getContext());
68 X86FreeBSDTargetObjectFile::Initialize(MCContext
&Ctx
,
69 const TargetMachine
&TM
) {
70 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
71 InitializeELF(TM
.Options
.UseInitArray
);
75 X86FuchsiaTargetObjectFile::Initialize(MCContext
&Ctx
,
76 const TargetMachine
&TM
) {
77 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
78 InitializeELF(TM
.Options
.UseInitArray
);
82 X86LinuxNaClTargetObjectFile::Initialize(MCContext
&Ctx
,
83 const TargetMachine
&TM
) {
84 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
85 InitializeELF(TM
.Options
.UseInitArray
);
88 void X86SolarisTargetObjectFile::Initialize(MCContext
&Ctx
,
89 const TargetMachine
&TM
) {
90 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
91 InitializeELF(TM
.Options
.UseInitArray
);