blob: 9c13359cba715807fbd2eaa14e0cf33e40e7ca12 [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 Christopherfe832702018-09-06 22:09:31 +000035 bool genExecuteOnly =
36 ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000037
Bill Wendling94811812010-03-09 18:31:07 +000038 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000039 InitializeELF(isAAPCS_ABI);
Bill Wendling94811812010-03-09 18:31:07 +000040
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +000041 if (isAAPCS_ABI) {
Craig Topper062a2ba2014-04-25 05:30:21 +000042 LSDASection = nullptr;
Bill Wendling94811812010-03-09 18:31:07 +000043 }
Eric Christopherfe832702018-09-06 22:09:31 +000044
45 // Make code section unreadable when in execute-only mode
46 if (genExecuteOnly) {
47 unsigned Type = ELF::SHT_PROGBITS;
48 unsigned Flags =
49 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
50 // Since we cannot modify flags for an existing section, we create a new
51 // section with the right flags, and use 0 as the unique ID for
52 // execute-only text
53 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
54 }
Bill Wendling94811812010-03-09 18:31:07 +000055}
Anton Korobeynikove42af362012-11-14 01:47:00 +000056
Rafael Espindola15b26692014-02-09 14:50:44 +000057const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000058 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
59 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000060 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
61 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000062 GV, Encoding, TM, MMI, Streamer);
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000063
Anton Korobeynikove42af362012-11-14 01:47:00 +000064 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
65
Tim Northoverb64fb452016-11-22 16:17:20 +000066 return MCSymbolRefExpr::create(TM.getSymbol(GV),
Rafael Espindoladaeafb42014-02-19 17:23:20 +000067 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +000068}
Kai Nacke382c1402014-02-05 07:23:09 +000069
70const MCExpr *ARMElfTargetObjectFile::
71getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
Jim Grosbach13760bd2015-05-30 01:25:56 +000072 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
Kai Nacke382c1402014-02-05 07:23:09 +000073 getContext());
74}
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000075
Eric Christopher015dc202017-07-01 02:55:22 +000076static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
77 const TargetMachine &TM) {
78 if (const Function *F = dyn_cast<Function>(GO))
79 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
80 return true;
81 return false;
82}
83
84MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
85 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000086 // Set execute-only access for the explicit section
Eric Christopher015dc202017-07-01 02:55:22 +000087 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000088 SK = SectionKind::getExecuteOnly();
89
90 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
91}
92
Eric Christopher015dc202017-07-01 02:55:22 +000093MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
94 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000095 // Place the global in the execute-only text section
Eric Christopher015dc202017-07-01 02:55:22 +000096 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000097 SK = SectionKind::getExecuteOnly();
98
99 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
100}