Anton Korobeynikov | 745e864 | 2008-07-19 13:14:46 +0000 | [diff] [blame] | 1 | //===-- DarwinTargetAsmInfo.cpp - Darwin 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 defines target asm properties related what form asm statements |
| 11 | // should take in general on Darwin-based targets |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Constants.h" |
| 16 | #include "llvm/DerivedTypes.h" |
| 17 | #include "llvm/Function.h" |
| 18 | #include "llvm/GlobalVariable.h" |
| 19 | #include "llvm/ADT/StringExtras.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Dale Johannesen | d2e51af | 2008-09-09 22:29:13 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Mangler.h" |
Anton Korobeynikov | 745e864 | 2008-07-19 13:14:46 +0000 | [diff] [blame] | 22 | #include "llvm/Target/DarwinTargetAsmInfo.h" |
| 23 | #include "llvm/Target/TargetMachine.h" |
| 24 | #include "llvm/Target/TargetData.h" |
| 25 | |
| 26 | using namespace llvm; |
| 27 | |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 28 | DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) |
| 29 | : TargetAsmInfo(TM) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame^] | 30 | |
Chris Lattner | 4e0f25b | 2009-06-19 00:08:39 +0000 | [diff] [blame] | 31 | // Common settings for all Darwin targets. |
| 32 | // Syntax: |
| 33 | GlobalPrefix = "_"; |
| 34 | PrivateGlobalPrefix = "L"; |
Chris Lattner | 90f8b70 | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 35 | LinkerPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata |
Chris Lattner | 4e0f25b | 2009-06-19 00:08:39 +0000 | [diff] [blame] | 36 | NeedsSet = true; |
| 37 | NeedsIndirectEncoding = true; |
| 38 | AllowQuotesInName = true; |
| 39 | HasSingleParameterDotFile = false; |
| 40 | |
| 41 | // In non-PIC modes, emit a special label before jump tables so that the |
| 42 | // linker can perform more accurate dead code stripping. We do not check the |
| 43 | // relocation model here since it can be overridden later. |
| 44 | JumpTableSpecialLabelPrefix = "l"; |
| 45 | |
| 46 | // Directives: |
| 47 | WeakDefDirective = "\t.weak_definition "; |
| 48 | WeakRefDirective = "\t.weak_reference "; |
| 49 | HiddenDirective = "\t.private_extern "; |
| 50 | |
| 51 | // Sections: |
| 52 | CStringSection = "\t.cstring"; |
Chris Lattner | 30c4a3b | 2009-07-26 01:24:18 +0000 | [diff] [blame] | 53 | JumpTableDataSection = "\t.const"; |
Chris Lattner | 4e0f25b | 2009-06-19 00:08:39 +0000 | [diff] [blame] | 54 | BSSSection = 0; |
| 55 | |
| 56 | if (TM.getRelocationModel() == Reloc::Static) { |
| 57 | StaticCtorsSection = ".constructor"; |
| 58 | StaticDtorsSection = ".destructor"; |
| 59 | } else { |
| 60 | StaticCtorsSection = ".mod_init_func"; |
| 61 | StaticDtorsSection = ".mod_term_func"; |
| 62 | } |
| 63 | |
Chris Lattner | e2cf37b | 2009-07-17 20:46:40 +0000 | [diff] [blame] | 64 | // _foo.eh symbols are currently always exported so that the linker knows |
| 65 | // about them. This may not strictly be necessary on 10.6 and later, but it |
| 66 | // doesn't hurt anything. |
| 67 | Is_EHSymbolPrivate = false; |
| 68 | |
Chris Lattner | 4e0f25b | 2009-06-19 00:08:39 +0000 | [diff] [blame] | 69 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 70 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 71 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 72 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 73 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 74 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 75 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 76 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 77 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 78 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 79 | DwarfMacroInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
Anton Korobeynikov | 745e864 | 2008-07-19 13:14:46 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Dale Johannesen | d2e51af | 2008-09-09 22:29:13 +0000 | [diff] [blame] | 82 | /// emitUsedDirectiveFor - On Darwin, internally linked data beginning with |
Chris Lattner | 90f8b70 | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 83 | /// the PrivateGlobalPrefix or the LinkerPrivateGlobalPrefix does not have the |
Dale Johannesen | d2e51af | 2008-09-09 22:29:13 +0000 | [diff] [blame] | 84 | /// directive emitted (this occurs in ObjC metadata). |
Bill Wendling | ecc2da8 | 2009-07-20 21:38:26 +0000 | [diff] [blame] | 85 | bool DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV, |
| 86 | Mangler *Mang) const { |
| 87 | if (!GV) return false; |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 90f8b70 | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 89 | // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix. |
Bill Wendling | ecc2da8 | 2009-07-20 21:38:26 +0000 | [diff] [blame] | 90 | if (GV->hasLocalLinkage() && !isa<Function>(GV)) { |
Chris Lattner | 449e379 | 2009-07-21 22:32:55 +0000 | [diff] [blame] | 91 | // FIXME: ObjC metadata is currently emitted as internal symbols that have |
| 92 | // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and |
| 93 | // this horrible hack can go away. |
Bill Wendling | ecc2da8 | 2009-07-20 21:38:26 +0000 | [diff] [blame] | 94 | const std::string &Name = Mang->getMangledName(GV); |
Chris Lattner | 449e379 | 2009-07-21 22:32:55 +0000 | [diff] [blame] | 95 | if (Name[0] == 'L' || Name[0] == 'l') |
Bill Wendling | ecc2da8 | 2009-07-20 21:38:26 +0000 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | |
Dale Johannesen | d2e51af | 2008-09-09 22:29:13 +0000 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |