Convert PPC/Linux to new section printing stuff
[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 PPCTargetAsmInfo::PPCTargetAsmInfo(const PPCTargetMachine &TM) {
23   bool isPPC64 = TM.getSubtargetImpl()->isPPC64();
24
25   ZeroDirective = "\t.space\t";
26   SetDirective = "\t.set";
27   Data64bitsDirective = isPPC64 ? "\t.quad\t" : 0;  
28   AlignmentIsInBytes = false;
29   LCOMMDirective = "\t.lcomm\t";
30   InlineAsmStart = "# InlineAsm Start";
31   InlineAsmEnd = "# InlineAsm End";
32   AssemblerDialect = TM.getSubtargetImpl()->getAsmFlavor();
33 }
34
35 PPCDarwinTargetAsmInfo::PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM):
36   PPCTargetAsmInfo(TM), DarwinTargetAsmInfo(TM) {
37   PCSymbol = ".";
38   CommentString = ";";
39   GlobalPrefix = "_";
40   PrivateGlobalPrefix = "L";
41   StringConstantPrefix = "\1LC";
42   ConstantPoolSection = "\t.const\t";
43   JumpTableDataSection = ".const";
44   CStringSection = "\t.cstring";
45   FourByteConstantSection = "\t.literal4\n";
46   EightByteConstantSection = "\t.literal8\n";
47   ReadOnlySection = "\t.const\n";
48   if (TM.getRelocationModel() == Reloc::Static) {
49     StaticCtorsSection = ".constructor";
50     StaticDtorsSection = ".destructor";
51   } else {
52     StaticCtorsSection = ".mod_init_func";
53     StaticDtorsSection = ".mod_term_func";
54   }
55   SwitchToSectionDirective = "\t.section ";
56   UsedDirective = "\t.no_dead_strip\t";
57   WeakDefDirective = "\t.weak_definition ";
58   WeakRefDirective = "\t.weak_reference ";
59   HiddenDirective = "\t.private_extern ";
60   SupportsExceptionHandling = true;
61   NeedsIndirectEncoding = true;
62   NeedsSet = true;
63   BSSSection = 0;
64   
65   DwarfEHFrameSection =
66   ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
67   DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
68   GlobalEHDirective = "\t.globl\t";
69   SupportsWeakOmittedEHFrame = false;
70
71   DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
72   DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
73   DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
74   DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
75   DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
76   DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
77   DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
78   DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
79   DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
80   DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
81   DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
82   
83   // In non-PIC modes, emit a special label before jump tables so that the
84   // linker can perform more accurate dead code stripping.
85   if (TM.getRelocationModel() != Reloc::PIC_) {
86     // Emit a local label that is preserved until the linker runs.
87     JumpTableSpecialLabelPrefix = "l";
88   }
89 }
90
91 /// PreferredEHDataFormat - This hook allows the target to select data
92 /// format used for encoding pointers in exception handling data. Reason is
93 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
94 /// if the symbol can be relocated.
95 unsigned
96 PPCDarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
97                                               bool Global) const {
98   if (Reason == DwarfEncoding::Functions && Global)
99     return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
100   else if (Reason == DwarfEncoding::CodeLabels || !Global)
101     return DW_EH_PE_pcrel;
102   else
103     return DW_EH_PE_absptr;
104 }
105
106
107 PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) :
108   PPCTargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
109   CommentString = "#";
110   GlobalPrefix = "";
111   PrivateGlobalPrefix = "";
112   ConstantPoolSection = "\t.section .rodata.cst4\t";
113   JumpTableDataSection = ".section .rodata.cst4";
114   CStringSection = "\t.section\t.rodata";
115   StaticCtorsSection = ".section\t.ctors,\"aw\",@progbits";
116   StaticDtorsSection = ".section\t.dtors,\"aw\",@progbits";
117   UsedDirective = "\t# .no_dead_strip\t";
118   WeakRefDirective = "\t.weak\t";
119   BSSSection = "\t.section\t\".sbss\",\"aw\",@nobits";
120
121   // Debug Information
122   AbsoluteDebugSectionOffsets = true;
123   SupportsDebugInformation = true;
124   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
125   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
126   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
127   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
128   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
129   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
130   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
131   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
132   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
133   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
134   DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
135
136   ReadOnlySection = "\t.section\t.rodata";
137   FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
138   EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
139   SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
140   PCSymbol = ".";
141
142   // Set up DWARF directives
143   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
144
145   // Exceptions handling
146   if (!TM.getSubtargetImpl()->isPPC64())
147     SupportsExceptionHandling = true;
148   AbsoluteEHSectionOffsets = false;
149   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
150   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
151 }
152
153 /// PreferredEHDataFormat - This hook allows the target to select data
154 /// format used for encoding pointers in exception handling data. Reason is
155 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
156 /// if the symbol can be relocated.
157 unsigned
158 PPCLinuxTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
159                                              bool Global) const {
160   // We really need to write something here.
161   return TargetAsmInfo::PreferredEHDataFormat(Reason, Global);
162 }