2012-02-18 20:03:15 +08:00
|
|
|
//===-- X86TargetObjectFile.cpp - X86 Object Info -------------------------===//
|
2009-09-16 09:46:41 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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 09:46:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-02-16 06:35:59 +08:00
|
|
|
#include "X86TargetObjectFile.h"
|
2014-07-15 06:57:27 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2014-01-13 16:04:33 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2014-01-15 17:16:42 +08:00
|
|
|
#include "llvm/IR/Operator.h"
|
2009-09-19 04:22:52 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-03-16 07:51:06 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-07-15 06:57:27 +08:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2012-06-19 08:48:28 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2015-03-06 21:49:05 +08:00
|
|
|
#include "llvm/MC/MCValue.h"
|
2013-01-11 07:43:56 +08:00
|
|
|
|
2009-09-16 09:46:41 +08:00
|
|
|
using namespace llvm;
|
2010-02-16 06:35:59 +08:00
|
|
|
using namespace dwarf;
|
2009-09-16 09:46:41 +08:00
|
|
|
|
2014-02-09 22:50:44 +08:00
|
|
|
const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
|
2016-09-16 15:33:15 +08:00
|
|
|
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
2010-02-16 06:35:59 +08:00
|
|
|
|
2009-09-16 09:46:41 +08:00
|
|
|
// On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
|
|
|
|
// is an indirect pc-relative reference.
|
2014-05-01 06:40:27 +08:00
|
|
|
if ((Encoding & DW_EH_PE_indirect) && (Encoding & DW_EH_PE_pcrel)) {
|
2016-11-23 00:17:20 +08:00
|
|
|
const MCSymbol *Sym = TM.getSymbol(GV);
|
2010-02-16 06:38:10 +08:00
|
|
|
const MCExpr *Res =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
|
|
|
const MCExpr *Four = MCConstantExpr::create(4, getContext());
|
|
|
|
return MCBinaryExpr::createAdd(Res, Four, getContext());
|
2010-02-16 06:35:59 +08:00
|
|
|
}
|
|
|
|
|
2014-02-09 22:50:44 +08:00
|
|
|
return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
2016-09-16 15:33:15 +08:00
|
|
|
GV, Encoding, TM, MMI, Streamer);
|
2010-02-16 06:35:59 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 01:23:20 +08:00
|
|
|
MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
|
2016-09-16 15:33:15 +08:00
|
|
|
const GlobalValue *GV, const TargetMachine &TM,
|
2014-02-20 01:23:20 +08:00
|
|
|
MachineModuleInfo *MMI) const {
|
2016-11-23 00:17:20 +08:00
|
|
|
return TM.getSymbol(GV);
|
2011-04-28 07:08:15 +08:00
|
|
|
}
|
2012-06-19 08:48:28 +08:00
|
|
|
|
2015-02-24 05:26:18 +08:00
|
|
|
const MCExpr *X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
|
2015-03-06 21:49:05 +08:00
|
|
|
const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
2015-02-24 05:26:18 +08: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 21:49:05 +08:00
|
|
|
unsigned FinalOff = Offset+MV.getConstant()+4;
|
2015-02-24 05:26:18 +08:00
|
|
|
const MCExpr *Res =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
|
|
|
const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
|
|
|
|
return MCBinaryExpr::createAdd(Res, Off, getContext());
|
2015-02-24 05:26:18 +08:00
|
|
|
}
|
|
|
|
|
2015-03-04 05:01:27 +08:00
|
|
|
const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
|
|
|
|
const MCSymbol *Sym) const {
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
|
2015-03-04 05:01:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 06:53:15 +08:00
|
|
|
void
|
|
|
|
X86FreeBSDTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2016-10-06 13:17:26 +08:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
X86FuchsiaTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2016-09-27 06:53:15 +08:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
|
|
|
|
2012-06-19 08:48:28 +08:00
|
|
|
void
|
2015-03-12 00:16:09 +08:00
|
|
|
X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2012-06-19 08:48:28 +08:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|
2013-07-02 05:45:25 +08:00
|
|
|
|
2017-06-22 04:36:32 +08:00
|
|
|
void X86SolarisTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
InitializeELF(TM.Options.UseInitArray);
|
|
|
|
}
|