blob: d0620761ea9c88c9afe896cbaad481fec7a884ac [file] [log] [blame]
Bill Wendling94811812010-03-09 18:31:07 +00001//===-- llvm/Target/ARMTargetObjectFile.cpp - ARM Object Info Impl --------===//
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
Chandler Carruth6bda14b2017-06-06 11:49:48 +000010#include "ARMTargetObjectFile.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000011#include "ARMSubtarget.h"
Eric Christopher2a0bc682015-01-30 01:30:01 +000012#include "ARMTargetMachine.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000013#include "llvm/BinaryFormat/Dwarf.h"
14#include "llvm/BinaryFormat/ELF.h"
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000015#include "llvm/MC/MCAsmInfo.h"
Chris Lattner80c34592010-04-08 21:34:17 +000016#include "llvm/MC/MCContext.h"
Anton Korobeynikove42af362012-11-14 01:47:00 +000017#include "llvm/MC/MCExpr.h"
Bill Wendling94811812010-03-09 18:31:07 +000018#include "llvm/MC/MCSectionELF.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000019#include "llvm/MC/MCTargetOptions.h"
20#include "llvm/MC/SectionKind.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000021#include "llvm/Target/TargetMachine.h"
22#include <cassert>
23
Bill Wendling94811812010-03-09 18:31:07 +000024using namespace llvm;
25using namespace dwarf;
26
27//===----------------------------------------------------------------------===//
28// ELF Target
29//===----------------------------------------------------------------------===//
30
31void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
32 const TargetMachine &TM) {
Florian Hahnd211fe72017-05-24 10:18:57 +000033 const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
34 bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
Eric Christopher015dc202017-07-01 02:55:22 +000035 // genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000036
Bill Wendling94811812010-03-09 18:31:07 +000037 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000038 InitializeELF(isAAPCS_ABI);
Bill Wendling94811812010-03-09 18:31:07 +000039
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +000040 if (isAAPCS_ABI) {
Craig Topper062a2ba2014-04-25 05:30:21 +000041 LSDASection = nullptr;
Bill Wendling94811812010-03-09 18:31:07 +000042 }
43}
Anton Korobeynikove42af362012-11-14 01:47:00 +000044
Rafael Espindola15b26692014-02-09 14:50:44 +000045const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000046 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
47 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000048 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
49 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000050 GV, Encoding, TM, MMI, Streamer);
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000051
Anton Korobeynikove42af362012-11-14 01:47:00 +000052 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
53
Tim Northoverb64fb452016-11-22 16:17:20 +000054 return MCSymbolRefExpr::create(TM.getSymbol(GV),
Rafael Espindoladaeafb42014-02-19 17:23:20 +000055 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +000056}
Kai Nacke382c1402014-02-05 07:23:09 +000057
58const MCExpr *ARMElfTargetObjectFile::
59getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
Jim Grosbach13760bd2015-05-30 01:25:56 +000060 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
Kai Nacke382c1402014-02-05 07:23:09 +000061 getContext());
62}
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000063
Eric Christopher015dc202017-07-01 02:55:22 +000064static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
65 const TargetMachine &TM) {
66 if (const Function *F = dyn_cast<Function>(GO))
67 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
68 return true;
69 return false;
70}
71
72MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
73 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000074 // Set execute-only access for the explicit section
Eric Christopher015dc202017-07-01 02:55:22 +000075 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000076 SK = SectionKind::getExecuteOnly();
77
78 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
79}
80
Eric Christopher015dc202017-07-01 02:55:22 +000081MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
82 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000083 // Place the global in the execute-only text section
Eric Christopher015dc202017-07-01 02:55:22 +000084 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000085 SK = SectionKind::getExecuteOnly();
86
87 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
88}