LLVM  8.0.1
X86TargetObjectFile.cpp
Go to the documentation of this file.
1 //===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "X86TargetObjectFile.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/BinaryFormat/COFF.h"
15 #include "llvm/IR/Mangler.h"
16 #include "llvm/IR/Operator.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCSectionCOFF.h"
20 #include "llvm/MC/MCSectionELF.h"
21 #include "llvm/MC/MCValue.h"
22 
23 using namespace llvm;
24 using namespace dwarf;
25 
27  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
28  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
29 
30  // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
31  // is an indirect pc-relative reference.
32  if ((Encoding & DW_EH_PE_indirect) && (Encoding & DW_EH_PE_pcrel)) {
33  const MCSymbol *Sym = TM.getSymbol(GV);
34  const MCExpr *Res =
36  const MCExpr *Four = MCConstantExpr::create(4, getContext());
37  return MCBinaryExpr::createAdd(Res, Four, getContext());
38  }
39 
41  GV, Encoding, TM, MMI, Streamer);
42 }
43 
45  const GlobalValue *GV, const TargetMachine &TM,
46  MachineModuleInfo *MMI) const {
47  return TM.getSymbol(GV);
48 }
49 
51  const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
52  MachineModuleInfo *MMI, MCStreamer &Streamer) const {
53  // On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
54  // from a data section. In case there's an additional offset, then use
55  // foo@GOTPCREL+4+<offset>.
56  unsigned FinalOff = Offset+MV.getConstant()+4;
57  const MCExpr *Res =
59  const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
60  return MCBinaryExpr::createAdd(Res, Off, getContext());
61 }
62 
64  const MCSymbol *Sym) const {
65  return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
66 }
67 
68 void
69 X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx,
70  const TargetMachine &TM) {
72  InitializeELF(TM.Options.UseInitArray);
73 }
74 
75 void
76 X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx,
77  const TargetMachine &TM) {
79  InitializeELF(TM.Options.UseInitArray);
80 }
81 
82 void
83 X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
84  const TargetMachine &TM) {
86  InitializeELF(TM.Options.UseInitArray);
87 }
88 
89 void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx,
90  const TargetMachine &TM) {
92  InitializeELF(TM.Options.UseInitArray);
93 }
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
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.
int64_t getConstant() const
Definition: MCValue.h:47
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:36
Context object for machine code objects.
Definition: MCContext.h:63
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:461
Streaming machine code generation interface.
Definition: MCStreamer.h:189
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
Definition: TargetMachine.h:97
const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.