]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/patches/patch-r262261-llvm-r200282-sparc.diff
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / patches / patch-r262261-llvm-r200282-sparc.diff
1 Pull in r200282 from upstream llvm trunk (by Jakob Stoklund Olesen):
2
3   Fix the DWARF EH encodings for Sparc PIC code.
4
5   Also emit the stubs that were generated for references to typeinfo
6   symbols.
7
8 Introduced here: http://svnweb.freebsd.org/changeset/base/262261
9
10 Index: lib/Target/Sparc/SparcAsmPrinter.cpp
11 ===================================================================
12 --- lib/Target/Sparc/SparcAsmPrinter.cpp
13 +++ lib/Target/Sparc/SparcAsmPrinter.cpp
14 @@ -23,7 +23,9 @@
15  #include "llvm/ADT/SmallString.h"
16  #include "llvm/CodeGen/AsmPrinter.h"
17  #include "llvm/CodeGen/MachineInstr.h"
18 +#include "llvm/CodeGen/MachineModuleInfoImpls.h"
19  #include "llvm/CodeGen/MachineRegisterInfo.h"
20 +#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
21  #include "llvm/MC/MCAsmInfo.h"
22  #include "llvm/MC/MCContext.h"
23  #include "llvm/MC/MCInst.h"
24 @@ -54,6 +56,7 @@ namespace {
25  
26      virtual void EmitFunctionBodyStart();
27      virtual void EmitInstruction(const MachineInstr *MI);
28 +    virtual void EmitEndOfAsmFile(Module &M);
29  
30      static const char *getRegisterName(unsigned RegNo) {
31        return SparcInstPrinter::getRegisterName(RegNo);
32 @@ -450,6 +453,23 @@ bool SparcAsmPrinter::PrintAsmMemoryOperand(const
33    return false;
34  }
35  
36 +void SparcAsmPrinter::EmitEndOfAsmFile(Module &M) {
37 +  const TargetLoweringObjectFileELF &TLOFELF =
38 +    static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
39 +  MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
40 +
41 +  // Generate stubs for global variables.
42 +  MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
43 +  if (!Stubs.empty()) {
44 +    OutStreamer.SwitchSection(TLOFELF.getDataSection());
45 +    unsigned PtrSize = TM.getDataLayout()->getPointerSize(0);
46 +    for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
47 +      OutStreamer.EmitLabel(Stubs[i].first);
48 +      OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(), PtrSize);
49 +    }
50 +  }
51 +}
52 +
53  // Force static initialization.
54  extern "C" void LLVMInitializeSparcAsmPrinter() {
55    RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
56 Index: lib/MC/MCObjectFileInfo.cpp
57 ===================================================================
58 --- lib/MC/MCObjectFileInfo.cpp
59 +++ lib/MC/MCObjectFileInfo.cpp
60 @@ -310,6 +310,33 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Tri
61      FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
62      TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
63        dwarf::DW_EH_PE_udata8;
64 +  } else if (T.getArch() == Triple::sparc) {
65 +    if (RelocM == Reloc::PIC_) {
66 +      LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
67 +      PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
68 +        dwarf::DW_EH_PE_sdata4;
69 +      FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
70 +      TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
71 +        dwarf::DW_EH_PE_sdata4;
72 +    } else {
73 +      LSDAEncoding = dwarf::DW_EH_PE_absptr;
74 +      PersonalityEncoding = dwarf::DW_EH_PE_absptr;
75 +      FDEEncoding = dwarf::DW_EH_PE_udata4;
76 +      TTypeEncoding = dwarf::DW_EH_PE_absptr;
77 +    }
78 +  } else if (T.getArch() == Triple::sparcv9) {
79 +    LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
80 +    if (RelocM == Reloc::PIC_) {
81 +      PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
82 +        dwarf::DW_EH_PE_sdata4;
83 +      FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
84 +      TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
85 +        dwarf::DW_EH_PE_sdata4;
86 +    } else {
87 +      PersonalityEncoding = dwarf::DW_EH_PE_absptr;
88 +      FDEEncoding = dwarf::DW_EH_PE_udata4;
89 +      TTypeEncoding = dwarf::DW_EH_PE_absptr;
90 +    }
91    } else if (T.getArch() == Triple::systemz) {
92      // All currently-defined code models guarantee that 4-byte PC-relative
93      // values will be in range.
94 Index: test/CodeGen/SPARC/exception.ll
95 ===================================================================
96 --- test/CodeGen/SPARC/exception.ll
97 +++ test/CodeGen/SPARC/exception.ll
98 @@ -1,4 +1,7 @@
99 -; RUN: llc < %s -march=sparc | FileCheck %s
100 +; RUN: llc < %s -march=sparc   -relocation-model=static | FileCheck -check-prefix=V8ABS %s
101 +; RUN: llc < %s -march=sparc   -relocation-model=pic    | FileCheck -check-prefix=V8PIC %s
102 +; RUN: llc < %s -march=sparcv9 -relocation-model=static | FileCheck -check-prefix=V9ABS %s
103 +; RUN: llc < %s -march=sparcv9 -relocation-model=pic    | FileCheck -check-prefix=V9PIC %s
104  
105  
106  %struct.__fundamental_type_info_pseudo = type { %struct.__type_info_pseudo }
107 @@ -9,23 +12,64 @@
108  @.cst = linker_private unnamed_addr constant [12 x i8] c"catched int\00", align 64
109  @.cst1 = linker_private unnamed_addr constant [14 x i8] c"catched float\00", align 64
110  
111 -; CHECK-LABEL: main:
112 -; CHECK:       .cfi_startproc
113 -; CHECK:       .cfi_def_cfa_register {{30|%fp}}
114 -; CHECK:       .cfi_window_save
115 -; CHECK:       .cfi_register 15, 31
116 +; V8ABS-LABEL: main:
117 +; V8ABS:        .cfi_startproc
118 +; V8ABS:        .cfi_personality 0, __gxx_personality_v0
119 +; V8ABS:        .cfi_lsda 0,
120 +; V8ABS:        .cfi_def_cfa_register {{30|%fp}}
121 +; V8ABS:        .cfi_window_save
122 +; V8ABS:        .cfi_register 15, 31
123  
124 -; CHECK:        call __cxa_throw
125 -; CHECK:        call __cxa_throw
126 +; V8ABS:        call __cxa_throw
127 +; V8ABS:        call __cxa_throw
128  
129 -; CHECK:        call __cxa_begin_catch
130 -; CHECK:        call __cxa_end_catch
131 +; V8ABS:        call __cxa_begin_catch
132 +; V8ABS:        call __cxa_end_catch
133  
134 -; CHECK:        call __cxa_begin_catch
135 -; CHECK:        call __cxa_end_catch
136 +; V8ABS:        call __cxa_begin_catch
137 +; V8ABS:        call __cxa_end_catch
138  
139 -; CHECK:        .cfi_endproc
140 +; V8ABS:        .cfi_endproc
141  
142 +; V8PIC-LABEL: main:
143 +; V8PIC:        .cfi_startproc
144 +; V8PIC:        .cfi_personality 155, DW.ref.__gxx_personality_v0
145 +; V8PIC:        .cfi_lsda 27,
146 +; V8PIC:        .cfi_def_cfa_register {{30|%fp}}
147 +; V8PIC:        .cfi_window_save
148 +; V8PIC:        .cfi_register 15, 31
149 +; V8PIC:        .section .gcc_except_table
150 +; V8PIC-NOT:    .section
151 +; V8PIC:        .word .L_ZTIi.DW.stub-
152 +; V8PIC:        .data
153 +; V8PIC: .L_ZTIi.DW.stub:
154 +; V8PIC-NEXT:   .word _ZTIi
155 +
156 +; V9ABS-LABEL: main:
157 +; V9ABS:        .cfi_startproc
158 +; V9ABS:        .cfi_personality 0, __gxx_personality_v0
159 +; V9ABS:        .cfi_lsda 27,
160 +; V9ABS:        .cfi_def_cfa_register {{30|%fp}}
161 +; V9ABS:        .cfi_window_save
162 +; V9ABS:        .cfi_register 15, 31
163 +; V9ABS:        .section .gcc_except_table
164 +; V9ABS-NOT:    .section
165 +; V9ABS:        .xword _ZTIi
166 +
167 +; V9PIC-LABEL: main:
168 +; V9PIC:        .cfi_startproc
169 +; V9PIC:        .cfi_personality 155, DW.ref.__gxx_personality_v0
170 +; V9PIC:        .cfi_lsda 27,
171 +; V9PIC:        .cfi_def_cfa_register {{30|%fp}}
172 +; V9PIC:        .cfi_window_save
173 +; V9PIC:        .cfi_register 15, 31
174 +; V9PIC:        .section .gcc_except_table
175 +; V9PIC-NOT:    .section
176 +; V9PIC:        .word .L_ZTIi.DW.stub-
177 +; V9PIC:        .data
178 +; V9PIC: .L_ZTIi.DW.stub:
179 +; V9PIC-NEXT:   .xword _ZTIi
180 +
181  define i32 @main(i32 %argc, i8** nocapture readnone %argv) unnamed_addr #0 {
182  entry:
183    %0 = icmp eq i32 %argc, 2