Eliminate getNamed/getUnnamedSection, adding a new and unified getOrCreateSection
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetAsmInfo.cpp
1 //===-- PPCTargetAsmInfo.cpp - PPC asm properties ---------------*- C++ -*-===//
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 // This file contains the declarations of the DarwinTargetAsmInfo properties.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCTargetAsmInfo.h"
15 #include "PPCTargetMachine.h"
16 #include "llvm/Function.h"
17 #include "llvm/Support/Dwarf.h"
18
19 using namespace llvm;
20 using namespace llvm::dwarf;
21
22 PPCDarwinTargetAsmInfo::PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM) :
23   PPCTargetAsmInfo<DarwinTargetAsmInfo>(TM) {
24   PCSymbol = ".";
25   CommentString = ";";
26   ConstantPoolSection = "\t.const\t";
27   UsedDirective = "\t.no_dead_strip\t";
28   SupportsExceptionHandling = true;
29   
30   DwarfEHFrameSection =
31    ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
32   DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
33   GlobalEHDirective = "\t.globl\t";
34   SupportsWeakOmittedEHFrame = false;
35 }
36
37 /// PreferredEHDataFormat - This hook allows the target to select data
38 /// format used for encoding pointers in exception handling data. Reason is
39 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
40 /// if the symbol can be relocated.
41 unsigned
42 PPCDarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
43                                               bool Global) const {
44   if (Reason == DwarfEncoding::Functions && Global)
45     return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
46   else if (Reason == DwarfEncoding::CodeLabels || !Global)
47     return DW_EH_PE_pcrel;
48   else
49     return DW_EH_PE_absptr;
50 }
51
52 const char *PPCDarwinTargetAsmInfo::getEHGlobalPrefix() const {
53   const PPCSubtarget* Subtarget = &TM.getSubtarget<PPCSubtarget>();
54   if (Subtarget->getDarwinVers() > 9)
55     return PrivateGlobalPrefix;
56   return "";
57 }
58
59 PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) :
60   PPCTargetAsmInfo<ELFTargetAsmInfo>(TM) {
61   CommentString = "#";
62   GlobalPrefix = "";
63   PrivateGlobalPrefix = ".L";
64   ConstantPoolSection = "\t.section .rodata.cst4\t";
65   JumpTableDataSection = ".section .rodata.cst4";
66   CStringSection = ".rodata.str";
67   StaticCtorsSection = ".section\t.ctors,\"aw\",@progbits";
68   StaticDtorsSection = ".section\t.dtors,\"aw\",@progbits";
69   UsedDirective = "\t# .no_dead_strip\t";
70   WeakRefDirective = "\t.weak\t";
71   BSSSection = "\t.section\t\".sbss\",\"aw\",@nobits";
72
73   // PPC/Linux normally uses named section for BSS.
74   BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
75
76   // Debug Information
77   AbsoluteDebugSectionOffsets = true;
78   SupportsDebugInformation = true;
79   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
80   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
81   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
82   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
83   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
84   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
85   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
86   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
87   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
88   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
89   DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
90
91   PCSymbol = ".";
92
93   // Set up DWARF directives
94   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
95
96   // Exceptions handling
97   if (!TM.getSubtargetImpl()->isPPC64())
98     SupportsExceptionHandling = true;
99   AbsoluteEHSectionOffsets = false;
100   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
101   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
102 }
103
104 /// PreferredEHDataFormat - This hook allows the target to select data
105 /// format used for encoding pointers in exception handling data. Reason is
106 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
107 /// if the symbol can be relocated.
108 unsigned
109 PPCLinuxTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
110                                              bool Global) const {
111   // We really need to write something here.
112   return TargetAsmInfo::PreferredEHDataFormat(Reason, Global);
113 }
114
115 // Instantiate default implementation.
116 TEMPLATE_INSTANTIATION(class PPCTargetAsmInfo<TargetAsmInfo>);