2012-02-18 13:03:15 +01:00
|
|
|
//===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
|
2009-09-16 03:46:41 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-09-16 03:46:41 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-02-15 23:35:59 +01:00
|
|
|
#include "X86TargetObjectFile.h"
|
2014-07-15 00:57:27 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2014-01-13 09:04:33 +01:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2014-01-15 10:16:42 +01:00
|
|
|
#include "llvm/IR/Operator.h"
|
2009-09-18 22:22:52 +02:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-03-16 00:51:06 +01:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-07-15 00:57:27 +02:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2012-06-19 02:48:28 +02:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2015-03-06 14:49:05 +01:00
|
|
|
#include "llvm/MC/MCValue.h"
|
2013-01-11 00:43:56 +01:00
|
|
|
|
2009-09-16 03:46:41 +02:00
|
|
|
using namespace llvm;
|
2010-02-15 23:35:59 +01:00
|
|
|
using namespace dwarf;
|
2009-09-16 03:46:41 +02:00
|
|
|
|
2014-02-09 15:50:44 +01:00
|
|
|
const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
|
2016-09-16 09:33:15 +02:00
|
|
|
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
2010-02-15 23:35:59 +01:00
|
|
|
|
2009-09-16 03:46:41 +02:00
|
|
|
// On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
|
|
|
|
// is an indirect pc-relative reference.
|
2014-05-01 00:40:27 +02:00
|
|
|
if ((Encoding & DW_EH_PE_indirect) && (Encoding & DW_EH_PE_pcrel)) {
|
2016-11-22 17:17:20 +01:00
|
|
|
const MCSymbol *Sym = TM.getSymbol(GV);
|
2010-02-15 23:38:10 +01:00
|
|
|
const MCExpr *Res =
|
2015-05-30 03:25:56 +02:00
|
|
|
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
|
|
|
const MCExpr *Four = MCConstantExpr::create(4, getContext());
|
|
|
|
return MCBinaryExpr::createAdd(Res, Four, getContext());
|
2010-02-15 23:35:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 15:50:44 +01:00
|
|
|
return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
2016-09-16 09:33:15 +02:00
|
|
|
GV, Encoding, TM, MMI, Streamer);
|
2010-02-15 23:35:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 18:23:20 +01:00
|
|
|
MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
|
2016-09-16 09:33:15 +02:00
|
|
|
const GlobalValue *GV, const TargetMachine &TM,
|
2014-02-19 18:23:20 +01:00
|
|
|
MachineModuleInfo *MMI) const {
|
2016-11-22 17:17:20 +01:00
|
|
|
return TM.getSymbol(GV);
|
2011-04-28 01:08:15 +02:00
|
|
|
}
|
2012-06-19 02:48:28 +02:00
|
|
|
|
2015-02-23 22:26:18 +01:00
|
|
|
const MCExpr *X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
|
2015-03-06 14:49:05 +01:00
|
|
|
const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
2015-02-23 22:26:18 +01:00
|
|
|
// On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
|
|
|
|
// from a data section. In case there's an additional offset, then use
|
|
|
|
// foo@GOTPCREL+4+<offset>.
|
2015-03-06 14:49:05 +01:00
|
|
|
unsigned FinalOff = Offset+MV.getConstant()+4;
|
2015-02-23 22:26:18 +01:00
|
|
|
const MCExpr *Res =
|
2015-05-30 03:25:56 +02:00
|
|
|
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
|
|
|
const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
|
|
|
|
return MCBinaryExpr::createAdd(Res, Off, getContext());
|
2015-02-23 22:26:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 22:01:27 +01:00
|
|
|
const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
|
|
|
|
const MCSymbol *Sym) const {
|
2015-05-30 03:25:56 +02:00
|
|
|
return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
|
2015-03-03 22:01:27 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 00:53:15 +02:00
|
|
|
void
|
|
|
|
X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2016-10-06 07:17:26 +02:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2016-09-27 00:53:15 +02:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
|
|
|
|
2012-06-19 02:48:28 +02:00
|
|
|
void
|
2015-03-11 17:16:09 +01:00
|
|
|
X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2012-06-19 02:48:28 +02:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
2013-07-01 23:45:25 +02:00
|
|
|
|
2017-06-21 22:36:32 +02:00
|
|
|
void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|