blob: 891329d3f2979fb06f0ea16b75f26a3fdad2aef0 [file] [log] [blame]
Bill Wendling94811812010-03-09 18:31:07 +00001//===-- llvm/Target/ARMTargetObjectFile.cpp - ARM Object Info Impl --------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Bill Wendling94811812010-03-09 18:31:07 +00006//
7//===----------------------------------------------------------------------===//
8
Chandler Carruth6bda14b2017-06-06 11:49:48 +00009#include "ARMTargetObjectFile.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000010#include "ARMSubtarget.h"
Eric Christopher2a0bc682015-01-30 01:30:01 +000011#include "ARMTargetMachine.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000012#include "llvm/BinaryFormat/Dwarf.h"
13#include "llvm/BinaryFormat/ELF.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"
Eugene Zelenko342257e2017-01-31 00:56:17 +000018#include "llvm/MC/MCTargetOptions.h"
19#include "llvm/MC/SectionKind.h"
Eugene Zelenko342257e2017-01-31 00:56:17 +000020#include "llvm/Target/TargetMachine.h"
21#include <cassert>
22
Bill Wendling94811812010-03-09 18:31:07 +000023using namespace llvm;
24using namespace dwarf;
25
26//===----------------------------------------------------------------------===//
27// ELF Target
28//===----------------------------------------------------------------------===//
29
30void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
31 const TargetMachine &TM) {
Florian Hahnd211fe72017-05-24 10:18:57 +000032 const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM);
33 bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS;
Eric Christopherfe832702018-09-06 22:09:31 +000034 bool genExecuteOnly =
35 ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly);
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 }
Eric Christopherfe832702018-09-06 22:09:31 +000043
44 // Make code section unreadable when in execute-only mode
45 if (genExecuteOnly) {
46 unsigned Type = ELF::SHT_PROGBITS;
47 unsigned Flags =
48 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC | ELF::SHF_ARM_PURECODE;
49 // Since we cannot modify flags for an existing section, we create a new
50 // section with the right flags, and use 0 as the unique ID for
51 // execute-only text
52 TextSection = Ctx.getELFSection(".text", Type, Flags, 0, "", 0U);
53 }
Bill Wendling94811812010-03-09 18:31:07 +000054}
Anton Korobeynikove42af362012-11-14 01:47:00 +000055
Rafael Espindola15b26692014-02-09 14:50:44 +000056const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000057 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
58 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000059 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
60 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000061 GV, Encoding, TM, MMI, Streamer);
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +000062
Anton Korobeynikove42af362012-11-14 01:47:00 +000063 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
64
Tim Northoverb64fb452016-11-22 16:17:20 +000065 return MCSymbolRefExpr::create(TM.getSymbol(GV),
Rafael Espindoladaeafb42014-02-19 17:23:20 +000066 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +000067}
Kai Nacke382c1402014-02-05 07:23:09 +000068
69const MCExpr *ARMElfTargetObjectFile::
70getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
Jim Grosbach13760bd2015-05-30 01:25:56 +000071 return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO,
Kai Nacke382c1402014-02-05 07:23:09 +000072 getContext());
73}
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000074
Eric Christopher015dc202017-07-01 02:55:22 +000075static bool isExecuteOnlyFunction(const GlobalObject *GO, SectionKind SK,
76 const TargetMachine &TM) {
77 if (const Function *F = dyn_cast<Function>(GO))
78 if (TM.getSubtarget<ARMSubtarget>(*F).genExecuteOnly() && SK.isText())
79 return true;
80 return false;
81}
82
83MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal(
84 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000085 // Set execute-only access for the explicit section
Eric Christopher015dc202017-07-01 02:55:22 +000086 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000087 SK = SectionKind::getExecuteOnly();
88
89 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM);
90}
91
Eric Christopher015dc202017-07-01 02:55:22 +000092MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal(
93 const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const {
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000094 // Place the global in the execute-only text section
Eric Christopher015dc202017-07-01 02:55:22 +000095 if (isExecuteOnlyFunction(GO, SK, TM))
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +000096 SK = SectionKind::getExecuteOnly();
97
98 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM);
99}