1 Pull in r200373 from upstream llvm trunk (by Venkatraman Govindaraju):
3 [Sparc] Use %r_disp32 for pc_rel entries in gcc_except_table and eh_frame.
5 Otherwise, assembler (gas) fails to assemble them with error message "operation
6 combines symbols in different segments". This is because MC computes
7 pc_rel entries with subtract expression between labels from different sections.
9 Introduced here: http://svn.freebsd.org/changeset/base/262261
11 Index: lib/Target/Sparc/SparcTargetObjectFile.h
12 ===================================================================
13 --- lib/Target/Sparc/SparcTargetObjectFile.h
14 +++ lib/Target/Sparc/SparcTargetObjectFile.h
16 +//===-- SparcTargetObjectFile.h - Sparc Object Info -------------*- C++ -*-===//
18 +// The LLVM Compiler Infrastructure
20 +// This file is distributed under the University of Illinois Open Source
21 +// License. See LICENSE.TXT for details.
23 +//===----------------------------------------------------------------------===//
25 +#ifndef LLVM_TARGET_SPARC_TARGETOBJECTFILE_H
26 +#define LLVM_TARGET_SPARC_TARGETOBJECTFILE_H
28 +#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
35 +class SparcELFTargetObjectFile : public TargetLoweringObjectFileELF {
37 + SparcELFTargetObjectFile() :
38 + TargetLoweringObjectFileELF()
42 + getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
43 + MachineModuleInfo *MMI, unsigned Encoding,
44 + MCStreamer &Streamer) const;
47 +} // end namespace llvm
50 Index: lib/Target/Sparc/SparcISelLowering.cpp
51 ===================================================================
52 --- lib/Target/Sparc/SparcISelLowering.cpp
53 +++ lib/Target/Sparc/SparcISelLowering.cpp
55 #include "SparcMachineFunctionInfo.h"
56 #include "SparcRegisterInfo.h"
57 #include "SparcTargetMachine.h"
58 +#include "SparcTargetObjectFile.h"
59 #include "MCTargetDesc/SparcBaseInfo.h"
60 #include "llvm/CodeGen/CallingConvLower.h"
61 #include "llvm/CodeGen/MachineFrameInfo.h"
62 @@ -1361,7 +1362,7 @@ static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondC
65 SparcTargetLowering::SparcTargetLowering(TargetMachine &TM)
66 - : TargetLowering(TM, new TargetLoweringObjectFileELF()) {
67 + : TargetLowering(TM, new SparcELFTargetObjectFile()) {
68 Subtarget = &TM.getSubtarget<SparcSubtarget>();
70 // Set up the register classes.
71 Index: lib/Target/Sparc/SparcTargetObjectFile.cpp
72 ===================================================================
73 --- lib/Target/Sparc/SparcTargetObjectFile.cpp
74 +++ lib/Target/Sparc/SparcTargetObjectFile.cpp
76 +//===------- SparcTargetObjectFile.cpp - Sparc Object Info Impl -----------===//
78 +// The LLVM Compiler Infrastructure
80 +// This file is distributed under the University of Illinois Open Source
81 +// License. See LICENSE.TXT for details.
83 +//===----------------------------------------------------------------------===//
85 +#include "SparcTargetObjectFile.h"
86 +#include "MCTargetDesc/SparcMCExpr.h"
87 +#include "llvm/CodeGen/MachineModuleInfoImpls.h"
88 +#include "llvm/Support/Dwarf.h"
89 +#include "llvm/Target/Mangler.h"
91 +using namespace llvm;
94 +const MCExpr *SparcELFTargetObjectFile::
95 +getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
96 + MachineModuleInfo *MMI, unsigned Encoding,
97 + MCStreamer &Streamer) const {
99 + if (Encoding & dwarf::DW_EH_PE_pcrel) {
100 + MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
102 + //MCSymbol *SSym = getSymbolWithGlobalValueBase(*Mang, GV, ".DW.stub");
103 + SmallString<60> NameStr;
104 + Mang->getNameWithPrefix(NameStr, GV, true);
105 + NameStr.append(".DW.stub");
106 + MCSymbol *SSym = getContext().GetOrCreateSymbol(NameStr.str());
108 + // Add information about the stub reference to ELFMMI so that the stub
109 + // gets emitted by the asmprinter.
110 + MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
111 + if (StubSym.getPointer() == 0) {
112 + MCSymbol *Sym = getSymbol(*Mang, GV);
113 + StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
116 + MCContext &Ctx = getContext();
117 + return SparcMCExpr::Create(SparcMCExpr::VK_Sparc_R_DISP32,
118 + MCSymbolRefExpr::Create(SSym, Ctx), Ctx);
121 + return TargetLoweringObjectFileELF::
122 + getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer);
124 Index: lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp
125 ===================================================================
126 --- lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp
127 +++ lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp
129 //===----------------------------------------------------------------------===//
131 #include "SparcMCAsmInfo.h"
132 +#include "SparcMCExpr.h"
133 #include "llvm/ADT/Triple.h"
134 +#include "llvm/MC/MCStreamer.h"
136 using namespace llvm;
138 @@ -44,4 +46,15 @@ SparcELFMCAsmInfo::SparcELFMCAsmInfo(StringRef TT)
139 PrivateGlobalPrefix = ".L";
143 +SparcELFMCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
145 + MCStreamer &Streamer) const {
146 + if (Encoding & dwarf::DW_EH_PE_pcrel) {
147 + MCContext &Ctx = Streamer.getContext();
148 + return SparcMCExpr::Create(SparcMCExpr::VK_Sparc_R_DISP32,
149 + MCSymbolRefExpr::Create(Sym, Ctx), Ctx);
152 + return MCAsmInfo::getExprForPersonalitySymbol(Sym, Encoding, Streamer);
154 Index: lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
155 ===================================================================
156 --- lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
157 +++ lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
158 @@ -41,6 +41,7 @@ void SparcMCExpr::PrintImpl(raw_ostream &OS) const
159 case VK_Sparc_L44: OS << "%l44("; break;
160 case VK_Sparc_HH: OS << "%hh("; break;
161 case VK_Sparc_HM: OS << "%hm("; break;
162 + case VK_Sparc_R_DISP32: OS << "%r_disp32("; break;
163 case VK_Sparc_TLS_GD_HI22: OS << "%tgd_hi22("; break;
164 case VK_Sparc_TLS_GD_LO10: OS << "%tgd_lo10("; break;
165 case VK_Sparc_TLS_GD_ADD: OS << "%tgd_add("; break;
166 @@ -77,6 +78,7 @@ SparcMCExpr::VariantKind SparcMCExpr::parseVariant
167 .Case("l44", VK_Sparc_L44)
168 .Case("hh", VK_Sparc_HH)
169 .Case("hm", VK_Sparc_HM)
170 + .Case("r_disp32", VK_Sparc_R_DISP32)
171 .Case("tgd_hi22", VK_Sparc_TLS_GD_HI22)
172 .Case("tgd_lo10", VK_Sparc_TLS_GD_LO10)
173 .Case("tgd_add", VK_Sparc_TLS_GD_ADD)
174 @@ -101,6 +103,8 @@ SparcMCExpr::VariantKind SparcMCExpr::parseVariant
176 SparcMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
177 const MCAsmLayout *Layout) const {
180 return getSubExpr()->EvaluateAsRelocatable(Res, *Layout);
183 Index: lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h
184 ===================================================================
185 --- lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h
186 +++ lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h
188 #include "llvm/MC/MCAsmInfoELF.h"
194 - class SparcELFMCAsmInfo : public MCAsmInfoELF {
195 - virtual void anchor();
197 - explicit SparcELFMCAsmInfo(StringRef TT);
199 +class SparcELFMCAsmInfo : public MCAsmInfoELF {
200 + virtual void anchor();
202 + explicit SparcELFMCAsmInfo(StringRef TT);
203 + virtual const MCExpr* getExprForPersonalitySymbol(const MCSymbol *Sym,
205 + MCStreamer &Streamer) const;
210 Index: lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h
211 ===================================================================
212 --- lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h
213 +++ lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h
214 @@ -31,6 +31,7 @@ class SparcMCExpr : public MCTargetExpr {
219 VK_Sparc_TLS_GD_HI22,
220 VK_Sparc_TLS_GD_LO10,
222 Index: lib/Target/Sparc/CMakeLists.txt
223 ===================================================================
224 --- lib/Target/Sparc/CMakeLists.txt
225 +++ lib/Target/Sparc/CMakeLists.txt
226 @@ -27,6 +27,7 @@ add_llvm_target(SparcCodeGen
230 + SparcTargetObjectFile.cpp
233 add_dependencies(LLVMSparcCodeGen SparcCommonTableGen intrinsics_gen)
234 Index: test/CodeGen/SPARC/exception.ll
235 ===================================================================
236 --- test/CodeGen/SPARC/exception.ll
237 +++ test/CodeGen/SPARC/exception.ll
239 ; RUN: llc < %s -march=sparc -relocation-model=static | FileCheck -check-prefix=V8ABS %s
240 ; RUN: llc < %s -march=sparc -relocation-model=pic | FileCheck -check-prefix=V8PIC %s
241 +; RUN: llc < %s -march=sparc -relocation-model=pic -disable-cfi | FileCheck -check-prefix=V8PIC_NOCFI %s
242 ; RUN: llc < %s -march=sparcv9 -relocation-model=static | FileCheck -check-prefix=V9ABS %s
243 ; RUN: llc < %s -march=sparcv9 -relocation-model=pic | FileCheck -check-prefix=V9PIC %s
244 +; RUN: llc < %s -march=sparcv9 -relocation-model=pic -disable-cfi | FileCheck -check-prefix=V9PIC_NOCFI %s
247 %struct.__fundamental_type_info_pseudo = type { %struct.__type_info_pseudo }
249 ; V8PIC: .cfi_register 15, 31
250 ; V8PIC: .section .gcc_except_table
251 ; V8PIC-NOT: .section
252 -; V8PIC: .word .L_ZTIi.DW.stub-
253 +; V8PIC: .word %r_disp32(.L_ZTIi.DW.stub)
255 ; V8PIC: .L_ZTIi.DW.stub:
256 ; V8PIC-NEXT: .word _ZTIi
258 +; V8PIC_NOCFI-LABEL: main:
259 +; V8PIC_NOCFI: .section .gcc_except_table
260 +; V8PIC_NOCFI-NOT: .section
261 +; V8PIC_NOCFI: .word %r_disp32(.L_ZTIi.DW.stub)
262 +; V8PIC_NOCFI: .data
263 +; V8PIC_NOCFI: .L_ZTIi.DW.stub:
264 +; V8PIC_NOCFI-NEXT: .word _ZTIi
265 +; V8PIC_NOCFI: .section .eh_frame
266 +; V8PIC_NOCFI-NOT: .section
267 +; V8PIC_NOCFI: .word %r_disp32(DW.ref.__gxx_personality_v0)
271 ; V9ABS: .cfi_startproc
272 ; V9ABS: .cfi_personality 0, __gxx_personality_v0
274 ; V9PIC: .cfi_register 15, 31
275 ; V9PIC: .section .gcc_except_table
276 ; V9PIC-NOT: .section
277 -; V9PIC: .word .L_ZTIi.DW.stub-
278 +; V9PIC: .word %r_disp32(.L_ZTIi.DW.stub)
280 ; V9PIC: .L_ZTIi.DW.stub:
281 ; V9PIC-NEXT: .xword _ZTIi
283 +; V9PIC_NOCFI-LABEL: main:
284 +; V9PIC_NOCFI: .section .gcc_except_table
285 +; V9PIC_NOCFI-NOT: .section
286 +; V9PIC_NOCFI: .word %r_disp32(.L_ZTIi.DW.stub)
287 +; V9PIC_NOCFI: .data
288 +; V9PIC_NOCFI: .L_ZTIi.DW.stub:
289 +; V9PIC_NOCFI-NEXT: .xword _ZTIi
290 +; V9PIC_NOCFI: .section .eh_frame
291 +; V9PIC_NOCFI-NOT: .section
292 +; V9PIC_NOCFI: .word %r_disp32(DW.ref.__gxx_personality_v0)
294 define i32 @main(i32 %argc, i8** nocapture readnone %argv) unnamed_addr #0 {
296 %0 = icmp eq i32 %argc, 2