LLVM  14.0.0git
X86TargetObjectFile.cpp
Go to the documentation of this file.
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"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCValue.h"
14 
15 using namespace llvm;
16 using namespace dwarf;
17 
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 =
28  const MCExpr *Four = MCConstantExpr::create(4, getContext());
29  return MCBinaryExpr::createAdd(Res, Four, getContext());
30  }
31 
33  GV, Encoding, TM, MMI, Streamer);
34 }
35 
37  const GlobalValue *GV, const TargetMachine &TM,
38  MachineModuleInfo *MMI) const {
39  return TM.getSymbol(GV);
40 }
41 
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 =
51  const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
52  return MCBinaryExpr::createAdd(Res, Off, getContext());
53 }
54 
56  const MCSymbol *Sym) const {
57  return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
58 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::X86_64MachoTargetObjectFile::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
Definition: X86TargetObjectFile.cpp:18
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
Definition: X86TargetObjectFile.cpp:42
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::TargetLoweringObjectFileMachO::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
Definition: TargetLoweringObjectFileImpl.cpp:1357
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
TargetMachine.h
llvm::dwarf::DW_EH_PE_indirect
@ DW_EH_PE_indirect
Definition: Dwarf.h:448
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition: Dwarf.h:443
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:80
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:525
Dwarf.h
llvm::MCSymbolRefExpr::VK_GOTPCREL
@ VK_GOTPCREL
Definition: MCExpr.h:202
llvm::X86ELFTargetObjectFile::getDebugThreadLocalSymbol
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
Definition: X86TargetObjectFile.cpp:55
X86TargetObjectFile.h
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
MCValue.h
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::X86_64MachoTargetObjectFile::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition: X86TargetObjectFile.cpp:36
llvm::MCSymbolRefExpr::VK_DTPOFF
@ VK_DTPOFF
Definition: MCExpr.h:213