xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86TargetObjectFile.cpp (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 //===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
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"
14 
15 using namespace llvm;
16 using namespace dwarf;
17 
18 const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
19     const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
20     MachineModuleInfo *MMI, MCStreamer &Streamer) const {
21 
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);
26     const MCExpr *Res =
27       MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
28     const MCExpr *Four = MCConstantExpr::create(4, getContext());
29     return MCBinaryExpr::createAdd(Res, Four, getContext());
30   }
31 
32   return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
33       GV, Encoding, TM, MMI, Streamer);
34 }
35 
36 MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
37     const GlobalValue *GV, const TargetMachine &TM,
38     MachineModuleInfo *MMI) const {
39   return TM.getSymbol(GV);
40 }
41 
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;
49   const MCExpr *Res =
50     MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
51   const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
52   return MCBinaryExpr::createAdd(Res, Off, getContext());
53 }
54 
55 const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
56     const MCSymbol *Sym) const {
57   return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
58 }
59