2010-03-10 02:31:07 +08:00
|
|
|
//===-- llvm/Target/ARMTargetObjectFile.cpp - ARM Object Info Impl --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "ARMTargetObjectFile.h"
|
2017-01-31 08:56:17 +08:00
|
|
|
#include "ARMSubtarget.h"
|
2015-01-30 09:30:01 +08:00
|
|
|
#include "ARMTargetMachine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2014-05-07 15:49:34 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-04-09 05:34:17 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2012-11-14 09:47:00 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-03-10 02:31:07 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2017-01-31 08:56:17 +08:00
|
|
|
#include "llvm/MC/MCTargetOptions.h"
|
|
|
|
#include "llvm/MC/SectionKind.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
2010-03-10 02:31:07 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace dwarf;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ELF Target
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
|
|
|
|
const TargetMachine &TM) {
|
2017-05-24 18:18:57 +08:00
|
|
|
const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
|
|
|
|
bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
|
2017-07-01 10:55:22 +08:00
|
|
|
// genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
|
2016-12-15 15:59:08 +08:00
|
|
|
|
2010-03-10 02:31:07 +08:00
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
2012-06-19 08:48:28 +08:00
|
|
|
InitializeELF(isAAPCS_ABI);
|
2010-03-10 02:31:07 +08:00
|
|
|
|
2012-01-26 06:24:19 +08:00
|
|
|
if (isAAPCS_ABI) {
|
2014-04-25 13:30:21 +08:00
|
|
|
LSDASection = nullptr;
|
2010-03-10 02:31:07 +08:00
|
|
|
}
|
|
|
|
}
|
2012-11-14 09:47:00 +08:00
|
|
|
|
2014-02-09 22:50:44 +08:00
|
|
|
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
|
2016-09-16 15:33:15 +08:00
|
|
|
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
2014-05-07 15:49:34 +08:00
|
|
|
if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
|
|
|
|
return TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
2016-09-16 15:33:15 +08:00
|
|
|
GV, Encoding, TM, MMI, Streamer);
|
2014-05-07 15:49:34 +08:00
|
|
|
|
2012-11-14 09:47:00 +08:00
|
|
|
assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
|
|
|
|
|
2016-11-23 00:17:20 +08:00
|
|
|
return MCSymbolRefExpr::create(TM.getSymbol(GV),
|
2014-02-20 01:23:20 +08:00
|
|
|
MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
|
2012-11-14 09:47:00 +08:00
|
|
|
}
|
2014-02-05 15:23:09 +08:00
|
|
|
|
|
|
|
const MCExpr *ARMElfTargetObjectFile::
|
|
|
|
getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
|
2014-02-05 15:23:09 +08:00
|
|
|
getContext());
|
|
|
|
}
|
2016-12-15 15:59:08 +08:00
|
|
|
|
2017-07-01 10:55:22 +08:00
|
|
|
static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
|
|
|
|
const TargetMachine &TM) {
|
|
|
|
if (const Function *F = dyn_cast<Function>(GO))
|
|
|
|
if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
|
|
|
|
const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
|
2016-12-15 15:59:08 +08:00
|
|
|
// Set execute-only access for the explicit section
|
2017-07-01 10:55:22 +08:00
|
|
|
if (isExecuteOnlyFunction(GO, SK, TM))
|
2016-12-15 15:59:08 +08:00
|
|
|
SK = SectionKind::getExecuteOnly();
|
|
|
|
|
|
|
|
return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
|
|
|
|
}
|
|
|
|
|
2017-07-01 10:55:22 +08:00
|
|
|
MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
|
|
|
|
const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
|
2016-12-15 15:59:08 +08:00
|
|
|
// Place the global in the execute-only text section
|
2017-07-01 10:55:22 +08:00
|
|
|
if (isExecuteOnlyFunction(GO, SK, TM))
|
2016-12-15 15:59:08 +08:00
|
|
|
SK = SectionKind::getExecuteOnly();
|
|
|
|
|
|
|
|
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
|
|
|
|
}
|