Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 1 | //===-- 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 Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "ARMTargetObjectFile.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 11 | #include "ARMSubtarget.h" |
Eric Christopher | 2a0bc68 | 2015-01-30 01:30:01 +0000 | [diff] [blame] | 12 | #include "ARMTargetMachine.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 13 | #include "llvm/BinaryFormat/Dwarf.h" |
| 14 | #include "llvm/BinaryFormat/ELF.h" |
Joerg Sonnenberger | cf86ce1 | 2014-05-07 07:49:34 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | 80c3459 | 2010-04-08 21:34:17 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCSectionELF.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCTargetOptions.h" |
| 20 | #include "llvm/MC/SectionKind.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
| 22 | #include <cassert> |
| 23 | |
Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | using namespace dwarf; |
| 26 | |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | // ELF Target |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
| 31 | void ARMElfTargetObjectFile::Initialize(MCContext &Ctx, |
| 32 | const TargetMachine &TM) { |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame] | 33 | const ARMBaseTargetMachine &ARM_TM = static_cast<const ARMBaseTargetMachine &>(TM); |
| 34 | bool isAAPCS_ABI = ARM_TM.TargetABI == ARMBaseTargetMachine::ARMABI::ARM_ABI_AAPCS; |
Eric Christopher | fe83270 | 2018-09-06 22:09:31 +0000 | [diff] [blame^] | 35 | bool genExecuteOnly = |
| 36 | ARM_TM.getMCSubtargetInfo()->hasFeature(ARM::FeatureExecuteOnly); |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 37 | |
Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 38 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 39 | InitializeELF(isAAPCS_ABI); |
Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 40 | |
Anton Korobeynikov | 7722a2d | 2012-01-25 22:24:19 +0000 | [diff] [blame] | 41 | if (isAAPCS_ABI) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 42 | LSDASection = nullptr; |
Bill Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 43 | } |
Eric Christopher | fe83270 | 2018-09-06 22:09:31 +0000 | [diff] [blame^] | 44 | |
| 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 Wendling | 9481181 | 2010-03-09 18:31:07 +0000 | [diff] [blame] | 55 | } |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 56 | |
Rafael Espindola | 15b2669 | 2014-02-09 14:50:44 +0000 | [diff] [blame] | 57 | const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference( |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 58 | const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, |
| 59 | MachineModuleInfo *MMI, MCStreamer &Streamer) const { |
Joerg Sonnenberger | cf86ce1 | 2014-05-07 07:49:34 +0000 | [diff] [blame] | 60 | if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM) |
| 61 | return TargetLoweringObjectFileELF::getTTypeGlobalReference( |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 62 | GV, Encoding, TM, MMI, Streamer); |
Joerg Sonnenberger | cf86ce1 | 2014-05-07 07:49:34 +0000 | [diff] [blame] | 63 | |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 64 | assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only"); |
| 65 | |
Tim Northover | b64fb45 | 2016-11-22 16:17:20 +0000 | [diff] [blame] | 66 | return MCSymbolRefExpr::create(TM.getSymbol(GV), |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 67 | MCSymbolRefExpr::VK_ARM_TARGET2, getContext()); |
Anton Korobeynikov | e42af36 | 2012-11-14 01:47:00 +0000 | [diff] [blame] | 68 | } |
Kai Nacke | 382c140 | 2014-02-05 07:23:09 +0000 | [diff] [blame] | 69 | |
| 70 | const MCExpr *ARMElfTargetObjectFile:: |
| 71 | getDebugThreadLocalSymbol(const MCSymbol *Sym) const { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 72 | return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_ARM_TLSLDO, |
Kai Nacke | 382c140 | 2014-02-05 07:23:09 +0000 | [diff] [blame] | 73 | getContext()); |
| 74 | } |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 75 | |
Eric Christopher | 015dc20 | 2017-07-01 02:55:22 +0000 | [diff] [blame] | 76 | static 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 | |
| 84 | MCSection *ARMElfTargetObjectFile::getExplicitSectionGlobal( |
| 85 | const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const { |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 86 | // Set execute-only access for the explicit section |
Eric Christopher | 015dc20 | 2017-07-01 02:55:22 +0000 | [diff] [blame] | 87 | if (isExecuteOnlyFunction(GO, SK, TM)) |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 88 | SK = SectionKind::getExecuteOnly(); |
| 89 | |
| 90 | return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, SK, TM); |
| 91 | } |
| 92 | |
Eric Christopher | 015dc20 | 2017-07-01 02:55:22 +0000 | [diff] [blame] | 93 | MCSection *ARMElfTargetObjectFile::SelectSectionForGlobal( |
| 94 | const GlobalObject *GO, SectionKind SK, const TargetMachine &TM) const { |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 95 | // Place the global in the execute-only text section |
Eric Christopher | 015dc20 | 2017-07-01 02:55:22 +0000 | [diff] [blame] | 96 | if (isExecuteOnlyFunction(GO, SK, TM)) |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 97 | SK = SectionKind::getExecuteOnly(); |
| 98 | |
| 99 | return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, SK, TM); |
| 100 | } |