blob: a5b27abeb27fe1573bd542172f2696f462358736 [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;
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000035 genExecuteOnly = ARM_TM.getSubtargetImpl()->genExecuteOnly();
36
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 }
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000043
Jason W Kim109ff292010-10-11 23:01:44 +000044 AttributesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +000045 getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000046
47 // Make code section unreadable when in execute-only mode
48 if (genExecuteOnly) {
49 unsigned Type = ELF::SHT_PROGBITS;
50 unsigned Flags = ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
51 // Since we cannot modify flags for an existing section, we create a new
52 // section with the right flags, and use 0 as the unique ID for
53 // execute-only text
54 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
55 }
Bill Wendling94811812010-03-09 18:31:07 +000056}
Anton Korobeynikove42af362012-11-14 01:47:00 +000057
Rafael Espindola15b26692014-02-09 14:50:44 +000058const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000059 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
60 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000061 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
62 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000063 GV, Encoding, TM, MMI, Streamer);
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000064
Anton Korobeynikove42af362012-11-14 01:47:00 +000065 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
66
Tim Northoverb64fb452016-11-22 16:17:20 +000067 return MCSymbolRefExpr::create(TM.getSymbol(GV),
Rafael Espindoladaeafb42014-02-19 17:23:20 +000068 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +000069}
Kai Nacke382c1402014-02-05 07:23:09 +000070
71const MCExpr *ARMElfTargetObjectFile::
72getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
Jim Grosbach13760bd2015-05-30 01:25:56 +000073 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
Kai Nacke382c1402014-02-05 07:23:09 +000074 getContext());
75}
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000076
77MCSection *
78ARMElfTargetObjectFile::getExplicitSectionGlobal(const GlobalObject *GO,
79 SectionKind SK, const TargetMachine &TM) const {
80 // Set execute-only access for the explicit section
81 if (genExecuteOnly && SK.isText())
82 SK = SectionKind::getExecuteOnly();
83
84 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
85}
86
87MCSection *
88ARMElfTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
89 SectionKind SK, const TargetMachine &TM) const {
90 // Place the global in the execute-only text section
91 if (genExecuteOnly && SK.isText())
92 SK = SectionKind::getExecuteOnly();
93
94 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
95}