blob: a44afc6984d389af43830d86d79b732afb60675b [file] [log] [blame]
Daniel Dunbar12783d12010-02-21 21:54:14 +00001//===-- 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 Dunbard6e59082010-03-15 21:56:50 +000012#include "llvm/MC/MCSectionMachO.h"
Daniel Dunbar12783d12010-02-21 21:54:14 +000013#include "llvm/Target/TargetRegistry.h"
14#include "llvm/Target/TargetAsmBackend.h"
15using namespace llvm;
16
17namespace {
18
19class X86AsmBackend : public TargetAsmBackend {
20public:
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +000021 X86AsmBackend(const Target &T)
Daniel Dunbar12783d12010-02-21 21:54:14 +000022 : TargetAsmBackend(T) {}
23};
24
Daniel Dunbar23ac7c72010-03-11 01:34:21 +000025class DarwinX86AsmBackend : public X86AsmBackend {
26public:
27 DarwinX86AsmBackend(const Target &T)
28 : X86AsmBackend(T) {}
29
30 virtual bool hasAbsolutizedSet() const { return true; }
31
32 virtual bool hasScatteredSymbols() const { return true; }
33};
34
Daniel Dunbard6e59082010-03-15 21:56:50 +000035class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {
36public:
37 DarwinX86_32AsmBackend(const Target &T)
38 : DarwinX86AsmBackend(T) {}
39};
40
41class DarwinX86_64AsmBackend : public DarwinX86AsmBackend {
42public:
43 DarwinX86_64AsmBackend(const Target &T)
44 : DarwinX86AsmBackend(T) {}
45
46 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
47 // Temporary labels in the string literals sections require symbols. The
48 // issue is that the x86_64 relocation format does not allow symbol +
49 // offset, and so the linker does not have enough information to resolve the
50 // access to the appropriate atom unless an external relocation is used. For
51 // non-cstring sections, we expect the compiler to use a non-temporary label
52 // for anything that could have an addend pointing outside the symbol.
53 //
54 // See <rdar://problem/4765733>.
55 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
56 return SMO.getType() == MCSectionMachO::S_CSTRING_LITERALS;
57 }
58};
59
Daniel Dunbar12783d12010-02-21 21:54:14 +000060}
61
62TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T,
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +000063 const std::string &TT) {
Daniel Dunbar23ac7c72010-03-11 01:34:21 +000064 switch (Triple(TT).getOS()) {
65 case Triple::Darwin:
Daniel Dunbard6e59082010-03-15 21:56:50 +000066 return new DarwinX86_32AsmBackend(T);
Daniel Dunbar23ac7c72010-03-11 01:34:21 +000067 default:
68 return new X86AsmBackend(T);
69 }
Daniel Dunbar12783d12010-02-21 21:54:14 +000070}
71
72TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +000073 const std::string &TT) {
Daniel Dunbar23ac7c72010-03-11 01:34:21 +000074 switch (Triple(TT).getOS()) {
75 case Triple::Darwin:
Daniel Dunbard6e59082010-03-15 21:56:50 +000076 return new DarwinX86_64AsmBackend(T);
Daniel Dunbar23ac7c72010-03-11 01:34:21 +000077 default:
78 return new X86AsmBackend(T);
79 }
Daniel Dunbar12783d12010-02-21 21:54:14 +000080}