blob: 625c4280e1a6851011267d24e3710d7e55b1dd1f [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
10#include "ARMTargetObjectFile.h"
Eric Christopher2a0bc682015-01-30 01:30:01 +000011#include "ARMTargetMachine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "llvm/ADT/StringExtras.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000013#include "llvm/IR/Mangler.h"
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000014#include "llvm/MC/MCAsmInfo.h"
Chris Lattner80c34592010-04-08 21:34:17 +000015#include "llvm/MC/MCContext.h"
Anton Korobeynikove42af362012-11-14 01:47:00 +000016#include "llvm/MC/MCExpr.h"
Bill Wendling94811812010-03-09 18:31:07 +000017#include "llvm/MC/MCSectionELF.h"
Bill Wendling94811812010-03-09 18:31:07 +000018#include "llvm/Support/Dwarf.h"
Rafael Espindolaaea49582011-01-23 04:28:49 +000019#include "llvm/Support/ELF.h"
Rafael Espindoladaeafb42014-02-19 17:23:20 +000020#include "llvm/Target/TargetLowering.h"
Bill Wendling94811812010-03-09 18:31:07 +000021using namespace llvm;
22using namespace dwarf;
23
24//===----------------------------------------------------------------------===//
25// ELF Target
26//===----------------------------------------------------------------------===//
27
28void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
29 const TargetMachine &TM) {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000030 const ARMTargetMachine &ARM_TM = static_cast<const ARMTargetMachine &>(TM);
31 bool isAAPCS_ABI = ARM_TM.TargetABI == ARMTargetMachine::ARMABI::ARM_ABI_AAPCS;
32 genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
33
Bill Wendling94811812010-03-09 18:31:07 +000034 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
Rafael Espindolaca3e0ee2012-06-19 00:48:28 +000035 InitializeELF(isAAPCS_ABI);
Bill Wendling94811812010-03-09 18:31:07 +000036
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +000037 if (isAAPCS_ABI) {
Craig Topper062a2ba2014-04-25 05:30:21 +000038 LSDASection = nullptr;
Bill Wendling94811812010-03-09 18:31:07 +000039 }
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000040
Jason W Kim109ff292010-10-11 23:01:44 +000041 AttributesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +000042 getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000043
44 // Make code section unreadable when in execute-only mode
45 if (genExecuteOnly) {
46 unsigned Type = ELF::SHT_PROGBITS;
47 unsigned Flags = ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
48 // Since we cannot modify flags for an existing section, we create a new
49 // section with the right flags, and use 0 as the unique ID for
50 // execute-only text
51 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
52 }
Bill Wendling94811812010-03-09 18:31:07 +000053}
Anton Korobeynikove42af362012-11-14 01:47:00 +000054
Rafael Espindola15b26692014-02-09 14:50:44 +000055const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000056 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
57 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000058 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
59 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000060 GV, Encoding, TM, MMI, Streamer);
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000061
Anton Korobeynikove42af362012-11-14 01:47:00 +000062 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
63
Tim Northoverb64fb452016-11-22 16:17:20 +000064 return MCSymbolRefExpr::create(TM.getSymbol(GV),
Rafael Espindoladaeafb42014-02-19 17:23:20 +000065 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +000066}
Kai Nacke382c1402014-02-05 07:23:09 +000067
68const MCExpr *ARMElfTargetObjectFile::
69getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
Jim Grosbach13760bd2015-05-30 01:25:56 +000070 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
Kai Nacke382c1402014-02-05 07:23:09 +000071 getContext());
72}
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000073
74MCSection *
75ARMElfTargetObjectFile::getExplicitSectionGlobal(const GlobalObject *GO,
76 SectionKind SK, const TargetMachine &TM) const {
77 // Set execute-only access for the explicit section
78 if (genExecuteOnly && SK.isText())
79 SK = SectionKind::getExecuteOnly();
80
81 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
82}
83
84MCSection *
85ARMElfTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
86 SectionKind SK, const TargetMachine &TM) const {
87 // Place the global in the execute-only text section
88 if (genExecuteOnly && SK.isText())
89 SK = SectionKind::getExecuteOnly();
90
91 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
92}