Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 1 | //===-- X86AsmBackend.cpp - X86 Assembler Backend -------------------------===// |
| 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 "llvm/Target/TargetAsmBackend.h" |
| 11 | #include "X86.h" |
Daniel Dunbar | d6e5908 | 2010-03-15 21:56:50 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCSectionMachO.h" |
Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 13 | #include "llvm/Target/TargetRegistry.h" |
| 14 | #include "llvm/Target/TargetAsmBackend.h" |
| 15 | using namespace llvm; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | class X86AsmBackend : public TargetAsmBackend { |
| 20 | public: |
Daniel Dunbar | 6c27f5e | 2010-03-11 01:34:16 +0000 | [diff] [blame] | 21 | X86AsmBackend(const Target &T) |
Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 22 | : TargetAsmBackend(T) {} |
| 23 | }; |
| 24 | |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 25 | class DarwinX86AsmBackend : public X86AsmBackend { |
| 26 | public: |
| 27 | DarwinX86AsmBackend(const Target &T) |
Daniel Dunbar | 0682951 | 2010-03-18 00:58:53 +0000 | [diff] [blame^] | 28 | : X86AsmBackend(T) { |
| 29 | HasAbsolutizedSet = true; |
| 30 | HasScatteredSymbols = true; |
| 31 | } |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Daniel Dunbar | d6e5908 | 2010-03-15 21:56:50 +0000 | [diff] [blame] | 34 | class DarwinX86_32AsmBackend : public DarwinX86AsmBackend { |
| 35 | public: |
| 36 | DarwinX86_32AsmBackend(const Target &T) |
| 37 | : DarwinX86AsmBackend(T) {} |
| 38 | }; |
| 39 | |
| 40 | class DarwinX86_64AsmBackend : public DarwinX86AsmBackend { |
| 41 | public: |
| 42 | DarwinX86_64AsmBackend(const Target &T) |
Daniel Dunbar | 0682951 | 2010-03-18 00:58:53 +0000 | [diff] [blame^] | 43 | : DarwinX86AsmBackend(T) { |
| 44 | HasReliableSymbolDifference = true; |
| 45 | } |
Daniel Dunbar | d6e5908 | 2010-03-15 21:56:50 +0000 | [diff] [blame] | 46 | |
| 47 | virtual bool doesSectionRequireSymbols(const MCSection &Section) const { |
| 48 | // Temporary labels in the string literals sections require symbols. The |
| 49 | // issue is that the x86_64 relocation format does not allow symbol + |
| 50 | // offset, and so the linker does not have enough information to resolve the |
| 51 | // access to the appropriate atom unless an external relocation is used. For |
| 52 | // non-cstring sections, we expect the compiler to use a non-temporary label |
| 53 | // for anything that could have an addend pointing outside the symbol. |
| 54 | // |
| 55 | // See <rdar://problem/4765733>. |
| 56 | const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section); |
| 57 | return SMO.getType() == MCSectionMachO::S_CSTRING_LITERALS; |
| 58 | } |
| 59 | }; |
| 60 | |
Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T, |
Daniel Dunbar | 6c27f5e | 2010-03-11 01:34:16 +0000 | [diff] [blame] | 64 | const std::string &TT) { |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 65 | switch (Triple(TT).getOS()) { |
| 66 | case Triple::Darwin: |
Daniel Dunbar | d6e5908 | 2010-03-15 21:56:50 +0000 | [diff] [blame] | 67 | return new DarwinX86_32AsmBackend(T); |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 68 | default: |
| 69 | return new X86AsmBackend(T); |
| 70 | } |
Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T, |
Daniel Dunbar | 6c27f5e | 2010-03-11 01:34:16 +0000 | [diff] [blame] | 74 | const std::string &TT) { |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 75 | switch (Triple(TT).getOS()) { |
| 76 | case Triple::Darwin: |
Daniel Dunbar | d6e5908 | 2010-03-15 21:56:50 +0000 | [diff] [blame] | 77 | return new DarwinX86_64AsmBackend(T); |
Daniel Dunbar | 23ac7c7 | 2010-03-11 01:34:21 +0000 | [diff] [blame] | 78 | default: |
| 79 | return new X86AsmBackend(T); |
| 80 | } |
Daniel Dunbar | 12783d1 | 2010-02-21 21:54:14 +0000 | [diff] [blame] | 81 | } |