LLVM  10.0.0svn
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"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/BinaryFormat/COFF.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"
21 
22 using namespace llvm;
23 using namespace dwarf;
24 
26  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
27  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
28 
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);
33  const MCExpr *Res =
35  const MCExpr *Four = MCConstantExpr::create(4, getContext());
36  return MCBinaryExpr::createAdd(Res, Four, getContext());
37  }
38 
40  GV, Encoding, TM, MMI, Streamer);
41 }
42 
44  const GlobalValue *GV, const TargetMachine &TM,
45  MachineModuleInfo *MMI) const {
46  return TM.getSymbol(GV);
47 }
48 
50  const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
51  int64_t Offset, 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;
56  const MCExpr *Res =
58  const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
59  return MCBinaryExpr::createAdd(Res, Off, getContext());
60 }
61 
63  const MCSymbol *Sym) const {
64  return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
65 }
66 
67 void
68 X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx,
69  const TargetMachine &TM) {
71  InitializeELF(TM.Options.UseInitArray);
72 }
73 
74 void
75 X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx,
76  const TargetMachine &TM) {
78  InitializeELF(TM.Options.UseInitArray);
79 }
80 
81 void
82 X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
83  const TargetMachine &TM) {
85  InitializeELF(TM.Options.UseInitArray);
86 }
87 
88 void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx,
89  const TargetMachine &TM) {
91  InitializeELF(TM.Options.UseInitArray);
92 }
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:327
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
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.
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.
int64_t getConstant() const
Definition: MCValue.h:46
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Context object for machine code objects.
Definition: MCContext.h:65
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:465
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
Definition: MCExpr.cpp:169
Streaming machine code generation interface.
Definition: MCStreamer.h:190
MCSymbol * getSymbol(const GlobalValue *GV) const
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.
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
This file contains constants used for implementing Dwarf debug support.
TargetOptions Options
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.