1 //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declarations of the ARMTargetAsmInfo properties.
12 //===----------------------------------------------------------------------===//
14 #include "ARMTargetAsmInfo.h"
15 #include "ARMTargetMachine.h"
20 static const char *const arm_asm_table[] = {
45 ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
46 AsmTransCBE = arm_asm_table;
48 AlignmentIsInBytes = false;
49 Data64bitsDirective = 0;
51 ConstantPoolSection = "\t.text\n";
52 COMMDirectiveTakesAlignment = false;
53 InlineAsmStart = "@ InlineAsm Start";
54 InlineAsmEnd = "@ InlineAsm End";
55 LCOMMDirective = "\t.lcomm\t";
58 ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
59 ARMTargetAsmInfo(TM), DarwinTargetAsmInfo(TM) {
60 Subtarget = &DTM->getSubtarget<ARMSubtarget>();
63 PrivateGlobalPrefix = "L";
64 LessPrivateGlobalPrefix = "l";
65 StringConstantPrefix = "\1LC";
66 BSSSection = 0; // no BSS section
67 ZeroDirective = "\t.space\t";
68 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
69 SetDirective = "\t.set\t";
70 WeakRefDirective = "\t.weak_reference\t";
71 HiddenDirective = "\t.private_extern\t";
72 ProtectedDirective = NULL;
73 JumpTableDataSection = ".const";
74 CStringSection = "\t.cstring";
75 ReadOnlySection = "\t.const\n";
76 HasDotTypeDotSizeDirective = false;
77 NeedsIndirectEncoding = true;
78 if (TM.getRelocationModel() == Reloc::Static) {
79 StaticCtorsSection = ".constructor";
80 StaticDtorsSection = ".destructor";
82 StaticCtorsSection = ".mod_init_func";
83 StaticDtorsSection = ".mod_term_func";
86 // In non-PIC modes, emit a special label before jump tables so that the
87 // linker can perform more accurate dead code stripping.
88 if (TM.getRelocationModel() != Reloc::PIC_) {
89 // Emit a local label that is preserved until the linker runs.
90 JumpTableSpecialLabelPrefix = "l";
94 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
95 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
96 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
97 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
98 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
99 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
100 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
101 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
102 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
103 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
104 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
107 ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM):
108 ARMTargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
109 Subtarget = &ETM->getSubtarget<ARMSubtarget>();
113 AbsoluteDebugSectionOffsets = true;
114 CStringSection = ".rodata.str";
115 ReadOnlySection = "\t.section\t.rodata\n";
116 PrivateGlobalPrefix = ".L";
117 WeakRefDirective = "\t.weak\t";
118 SetDirective = "\t.set\t";
119 DwarfRequiresFrameSection = false;
120 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits";
121 DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits";
122 DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits";
123 DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits";
124 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
125 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
126 DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits";
127 DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits";
128 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
129 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits";
130 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
132 if (Subtarget->isAAPCS_ABI()) {
133 StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
134 StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
136 StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
137 StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
141 /// Count the number of comma-separated arguments.
142 /// Do not try to detect errors.
143 unsigned ARMTargetAsmInfo::countArguments(const char* p) const {
145 while (*p && isspace(*p) && *p != '\n')
148 while (*p && *p!='\n' &&
149 strncmp(p, CommentString, strlen(CommentString))!=0) {
157 /// Count the length of a string enclosed in quote characters.
158 /// Do not try to detect errors.
159 unsigned ARMTargetAsmInfo::countString(const char* p) const {
161 while (*p && isspace(*p) && *p!='\n')
163 if (!*p || *p != '\"')
165 while (*++p && *p != '\"')
170 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
171 unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
172 // Make a lowercase-folded version of s for counting purposes.
173 char *q, *s_copy = (char *)malloc(strlen(s) + 1);
175 for (q=s_copy; *q; q++)
177 const char *Str = s_copy;
179 // Count the number of bytes in the asm.
180 bool atInsnStart = true;
181 bool inTextSection = true;
183 for (; *Str; ++Str) {
186 while (*Str && isspace(*Str) && *Str != '\n')
189 for (const char* p = Str; *p && !isspace(*p); p++)
192 while (*Str && isspace(*Str) && *Str != '\n')
196 // Ignore everything from comment char(s) to EOL
197 if (strncmp(Str, CommentString, strlen(CommentString))==-0)
199 // FIXME do something like the following for non-Darwin
200 else if (*Str == '.' && Subtarget->isTargetDarwin()) {
204 // Some change the section, but don't generate code.
205 if (strncmp(Str, ".literal4", strlen(".literal4"))==0 ||
206 strncmp(Str, ".literal8", strlen(".literal8"))==0 ||
207 strncmp(Str, ".const", strlen(".const"))==0 ||
208 strncmp(Str, ".constructor", strlen(".constructor"))==0 ||
209 strncmp(Str, ".cstring", strlen(".cstring"))==0 ||
210 strncmp(Str, ".data", strlen(".data"))==0 ||
211 strncmp(Str, ".destructor", strlen(".destructor"))==0 ||
212 strncmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
213 strncmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
214 strncmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 ||
215 strncmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 ||
216 strncmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
217 strncmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 ||
218 strncmp(Str, ".static_data", strlen(".static_data"))==0 ||
219 strncmp(Str, ".section", strlen(".section"))==0 ||
220 strncmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
221 strncmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
222 strncmp(Str, ".dyld", strlen(".dyld"))==0 ||
223 strncmp(Str, ".const_data", strlen(".const_data"))==0 ||
224 strncmp(Str, ".objc", strlen(".objc"))==0 || //// many directives
225 strncmp(Str, ".static_const", strlen(".static_const"))==0)
227 else if (strncmp(Str, ".text", strlen(".text"))==0)
228 inTextSection = true;
229 // Some can't really be handled without implementing significant pieces
230 // of an assembler. Others require dynamic adjustment of block sizes in
231 // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
232 // instruction in there, and none of these are currently used in the kernel.
233 else if (strncmp(Str, ".macro", strlen(".macro"))==0 ||
234 strncmp(Str, ".if", strlen(".if"))==0 ||
235 strncmp(Str, ".align", strlen(".align"))==0 ||
236 strncmp(Str, ".fill", strlen(".fill"))==0 ||
237 strncmp(Str, ".space", strlen(".space"))==0 ||
238 strncmp(Str, ".zerofill", strlen(".zerofill"))==0 ||
239 strncmp(Str, ".p2align", strlen(".p2align"))==0 ||
240 strncmp(Str, ".p2alignw", strlen(".p2alignw"))==0 ||
241 strncmp(Str, ".p2alignl", strlen(".p2alignl"))==0 ||
242 strncmp(Str, ".align32", strlen(".p2align32"))==0 ||
243 strncmp(Str, ".include", strlen(".include"))==0)
244 cerr << "Directive " << Str << " in asm may lead to invalid offsets for" <<
245 " constant pools (the assembler will tell you if this happens).\n";
246 // Some generate code, but this is only interesting in the text section.
247 else if (inTextSection) {
248 if (strncmp(Str, ".long", strlen(".long"))==0)
249 Length += 4*countArguments(Str+strlen(".long"));
250 else if (strncmp(Str, ".short", strlen(".short"))==0)
251 Length += 2*countArguments(Str+strlen(".short"));
252 else if (strncmp(Str, ".byte", strlen(".byte"))==0)
253 Length += 1*countArguments(Str+strlen(".byte"));
254 else if (strncmp(Str, ".single", strlen(".single"))==0)
255 Length += 4*countArguments(Str+strlen(".single"));
256 else if (strncmp(Str, ".double", strlen(".double"))==0)
257 Length += 8*countArguments(Str+strlen(".double"));
258 else if (strncmp(Str, ".quad", strlen(".quad"))==0)
259 Length += 16*countArguments(Str+strlen(".quad"));
260 else if (strncmp(Str, ".ascii", strlen(".ascii"))==0)
261 Length += countString(Str+strlen(".ascii"));
262 else if (strncmp(Str, ".asciz", strlen(".asciz"))==0)
263 Length += countString(Str+strlen(".asciz"))+1;
265 } else if (inTextSection) {
268 if (Subtarget->isThumb()) {
269 // BL and BLX <non-reg> are 4 bytes, all others 2.
270 if (strncmp(Str, "blx", strlen("blx"))==0) {
271 const char* p = Str+3;
272 while (*p && isspace(*p))
274 if (*p == 'r' || *p=='R')
275 Length += 2; // BLX reg
277 Length += 4; // BLX non-reg
278 } else if (strncmp(Str, "bl", strlen("bl"))==0)
281 Length += 2; // Thumb anything else
287 if (*Str == '\n' || *Str == SeparatorChar)