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
10#include "ARMTargetObjectFile.h"
11#include "ARMSubtarget.h"
12#include "llvm/MC/MCContext.h"
13#include "llvm/MC/MCSectionELF.h"
14#include "llvm/Support/Dwarf.h"
15#include "llvm/Support/ELF.h"
16#include "llvm/Target/TargetMachine.h"
17#include "llvm/ADT/StringExtras.h"
18using 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);
28  isAAPCS_ABI = TM.getSubtarget<ARMSubtarget>().isAAPCS_ABI();
29
30  if (isAAPCS_ABI) {
31    StaticCtorSection =
32      getContext().getELFSection(".init_array", ELF::SHT_INIT_ARRAY,
33                                 ELF::SHF_WRITE |
34                                 ELF::SHF_ALLOC,
35                                 SectionKind::getDataRel());
36    StaticDtorSection =
37      getContext().getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
38                                 ELF::SHF_WRITE |
39                                 ELF::SHF_ALLOC,
40                                 SectionKind::getDataRel());
41    LSDASection = NULL;
42  }
43
44  AttributesSection =
45    getContext().getELFSection(".ARM.attributes",
46                               ELF::SHT_ARM_ATTRIBUTES,
47                               0,
48                               SectionKind::getMetadata());
49}
50
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}
80