blob: a5ea1c202e2cc4de1a8c5287b5d42f2e83a2d376 [file] [log] [blame]
Bill Wendlingbdc38e52010-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"
11#include "ARMSubtarget.h"
Chris Lattner287df1b2010-04-08 21:34:17 +000012#include "llvm/MC/MCContext.h"
Bill Wendlingbdc38e52010-03-09 18:31:07 +000013#include "llvm/MC/MCSectionELF.h"
Bill Wendlingbdc38e52010-03-09 18:31:07 +000014#include "llvm/Support/Dwarf.h"
Rafael Espindolac85dca62011-01-23 04:28:49 +000015#include "llvm/Support/ELF.h"
Bill Wendlingbdc38e52010-03-09 18:31:07 +000016#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov4a99f592012-01-25 22:24:19 +000017#include "llvm/ADT/StringExtras.h"
Bill Wendlingbdc38e52010-03-09 18:31:07 +000018using namespace llvm;
19using namespace dwarf;
20
21//===----------------------------------------------------------------------===//
22// ELF Target
23//===----------------------------------------------------------------------===//
24
25void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
26 const TargetMachine &TM) {
27 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
Anton Korobeynikov4a99f592012-01-25 22:24:19 +000028 isAAPCS_ABI = TM.getSubtarget<ARMSubtarget>().isAAPCS_ABI();
Bill Wendlingbdc38e52010-03-09 18:31:07 +000029
Anton Korobeynikov4a99f592012-01-25 22:24:19 +000030 if (isAAPCS_ABI) {
Bill Wendlingbdc38e52010-03-09 18:31:07 +000031 StaticCtorSection =
Rafael Espindolac85dca62011-01-23 04:28:49 +000032 getContext().getELFSection(".init_array", ELF::SHT_INIT_ARRAY,
Rafael Espindola1c130262011-01-23 04:43:11 +000033 ELF::SHF_WRITE |
34 ELF::SHF_ALLOC,
Chris Lattner287df1b2010-04-08 21:34:17 +000035 SectionKind::getDataRel());
Bill Wendlingbdc38e52010-03-09 18:31:07 +000036 StaticDtorSection =
Rafael Espindolac85dca62011-01-23 04:28:49 +000037 getContext().getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
Rafael Espindola1c130262011-01-23 04:43:11 +000038 ELF::SHF_WRITE |
39 ELF::SHF_ALLOC,
Chris Lattner287df1b2010-04-08 21:34:17 +000040 SectionKind::getDataRel());
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000041 LSDASection = NULL;
Bill Wendlingbdc38e52010-03-09 18:31:07 +000042 }
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000043
Jason W Kim17b443d2010-10-11 23:01:44 +000044 AttributesSection =
45 getContext().getELFSection(".ARM.attributes",
Rafael Espindolac85dca62011-01-23 04:28:49 +000046 ELF::SHT_ARM_ATTRIBUTES,
Jason W Kim17b443d2010-10-11 23:01:44 +000047 0,
48 SectionKind::getMetadata());
Bill Wendlingbdc38e52010-03-09 18:31:07 +000049}
Anton Korobeynikov4a99f592012-01-25 22:24:19 +000050
51const MCSection *
52ARMElfTargetObjectFile::getStaticCtorSection(unsigned Priority) const {
53 if (!isAAPCS_ABI)
54 return TargetLoweringObjectFileELF::getStaticCtorSection(Priority);
55
56 if (Priority == 65535)
57 return StaticCtorSection;
58
59 // Emit ctors in priority order.
60 std::string Name = std::string(".init_array.") + utostr(Priority);
61 return getContext().getELFSection(Name, ELF::SHT_INIT_ARRAY,
62 ELF::SHF_ALLOC | ELF::SHF_WRITE,
63 SectionKind::getDataRel());
64}
65
66const MCSection *
67ARMElfTargetObjectFile::getStaticDtorSection(unsigned Priority) const {
68 if (!isAAPCS_ABI)
69 return TargetLoweringObjectFileELF::getStaticDtorSection(Priority);
70
71 if (Priority == 65535)
72 return StaticDtorSection;
73
74 // Emit dtors in priority order.
75 std::string Name = std::string(".fini_array.") + utostr(Priority);
76 return getContext().getELFSection(Name, ELF::SHT_FINI_ARRAY,
77 ELF::SHF_ALLOC | ELF::SHF_WRITE,
78 SectionKind::getDataRel());
79}