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/BinaryFormat/Dwarf.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCValue.h"
13 #include "llvm/Target/TargetMachine.h"
16 using namespace dwarf
;
18 const MCExpr
*X86_64MachoTargetObjectFile::getTTypeGlobalReference(
19 const GlobalValue
*GV
, unsigned Encoding
, const TargetMachine
&TM
,
20 MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
22 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
23 // is an indirect pc-relative reference.
24 if ((Encoding
& DW_EH_PE_indirect
) && (Encoding
& DW_EH_PE_pcrel
)) {
25 const MCSymbol
*Sym
= TM
.getSymbol(GV
);
27 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
28 const MCExpr
*Four
= MCConstantExpr::create(4, getContext());
29 return MCBinaryExpr::createAdd(Res
, Four
, getContext());
32 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
33 GV
, Encoding
, TM
, MMI
, Streamer
);
36 MCSymbol
*X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
37 const GlobalValue
*GV
, const TargetMachine
&TM
,
38 MachineModuleInfo
*MMI
) const {
39 return TM
.getSymbol(GV
);
42 const MCExpr
*X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
43 const GlobalValue
*GV
, const MCSymbol
*Sym
, const MCValue
&MV
,
44 int64_t Offset
, MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
45 // On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
46 // from a data section. In case there's an additional offset, then use
47 // foo@GOTPCREL+4+<offset>.
48 unsigned FinalOff
= Offset
+MV
.getConstant()+4;
50 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
51 const MCExpr
*Off
= MCConstantExpr::create(FinalOff
, getContext());
52 return MCBinaryExpr::createAdd(Res
, Off
, getContext());
55 const MCExpr
*X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
56 const MCSymbol
*Sym
) const {
57 return MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_DTPOFF
, getContext());
60 const MCExpr
*X86_64ELFTargetObjectFile::getIndirectSymViaGOTPCRel(
61 const GlobalValue
*GV
, const MCSymbol
*Sym
, const MCValue
&MV
,
62 int64_t Offset
, MachineModuleInfo
*MMI
, MCStreamer
&Streamer
) const {
63 int64_t FinalOffset
= Offset
+ MV
.getConstant();
65 MCSymbolRefExpr::create(Sym
, MCSymbolRefExpr::VK_GOTPCREL
, getContext());
66 const MCExpr
*Off
= MCConstantExpr::create(FinalOffset
, getContext());
67 return MCBinaryExpr::createAdd(Res
, Off
, getContext());