1Pull in r200373 from upstream llvm trunk (by Venkatraman Govindaraju): 2 3 [Sparc] Use %r_disp32 for pc_rel entries in gcc_except_table and eh_frame. 4 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. 8 9Introduced here: http://svnweb.freebsd.org/changeset/base/262261 10 11Index: lib/Target/Sparc/SparcTargetObjectFile.h 12=================================================================== 13--- lib/Target/Sparc/SparcTargetObjectFile.h 14+++ lib/Target/Sparc/SparcTargetObjectFile.h 15@@ -0,0 +1,34 @@ 16+//===-- SparcTargetObjectFile.h - Sparc Object Info -------------*- C++ -*-===// 17+// 18+// The LLVM Compiler Infrastructure 19+// 20+// This file is distributed under the University of Illinois Open Source 21+// License. See LICENSE.TXT for details. 22+// 23+//===----------------------------------------------------------------------===// 24+ 25+#ifndef LLVM_TARGET_SPARC_TARGETOBJECTFILE_H 26+#define LLVM_TARGET_SPARC_TARGETOBJECTFILE_H 27+ 28+#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 29+ 30+namespace llvm { 31+ 32+class MCContext; 33+class TargetMachine; 34+ 35+class SparcELFTargetObjectFile : public TargetLoweringObjectFileELF { 36+public: 37+ SparcELFTargetObjectFile() : 38+ TargetLoweringObjectFileELF() 39+ {} 40+ 41+ const MCExpr * 42+ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, 43+ MachineModuleInfo *MMI, unsigned Encoding, 44+ MCStreamer &Streamer) const; 45+}; 46+ 47+} // end namespace llvm 48+ 49+#endif 50Index: lib/Target/Sparc/SparcISelLowering.cpp 51=================================================================== 52--- lib/Target/Sparc/SparcISelLowering.cpp 53+++ lib/Target/Sparc/SparcISelLowering.cpp 54@@ -16,6 +16,7 @@ 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 63 } 64 65 SparcTargetLowering::SparcTargetLowering(TargetMachine &TM) 66- : TargetLowering(TM, new TargetLoweringObjectFileELF()) { 67+ : TargetLowering(TM, new SparcELFTargetObjectFile()) { 68 Subtarget = &TM.getSubtarget<SparcSubtarget>(); 69 70 // Set up the register classes. 71Index: lib/Target/Sparc/SparcTargetObjectFile.cpp 72=================================================================== 73--- lib/Target/Sparc/SparcTargetObjectFile.cpp 74+++ lib/Target/Sparc/SparcTargetObjectFile.cpp 75@@ -0,0 +1,48 @@ 76+//===------- SparcTargetObjectFile.cpp - Sparc Object Info Impl -----------===// 77+// 78+// The LLVM Compiler Infrastructure 79+// 80+// This file is distributed under the University of Illinois Open Source 81+// License. See LICENSE.TXT for details. 82+// 83+//===----------------------------------------------------------------------===// 84+ 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" 90+ 91+using namespace llvm; 92+ 93+ 94+const MCExpr *SparcELFTargetObjectFile:: 95+getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, 96+ MachineModuleInfo *MMI, unsigned Encoding, 97+ MCStreamer &Streamer) const { 98+ 99+ if (Encoding & dwarf::DW_EH_PE_pcrel) { 100+ MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>(); 101+ 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()); 107+ 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()); 114+ } 115+ 116+ MCContext &Ctx = getContext(); 117+ return SparcMCExpr::Create(SparcMCExpr::VK_Sparc_R_DISP32, 118+ MCSymbolRefExpr::Create(SSym, Ctx), Ctx); 119+ } 120+ 121+ return TargetLoweringObjectFileELF:: 122+ getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer); 123+} 124Index: lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp 125=================================================================== 126--- lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp 127+++ lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp 128@@ -12,7 +12,9 @@ 129 //===----------------------------------------------------------------------===// 130 131 #include "SparcMCAsmInfo.h" 132+#include "SparcMCExpr.h" 133 #include "llvm/ADT/Triple.h" 134+#include "llvm/MC/MCStreamer.h" 135 136 using namespace llvm; 137 138@@ -44,4 +46,15 @@ SparcELFMCAsmInfo::SparcELFMCAsmInfo(StringRef TT) 139 PrivateGlobalPrefix = ".L"; 140 } 141 142+const MCExpr* 143+SparcELFMCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym, 144+ unsigned Encoding, 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); 150+ } 151 152+ return MCAsmInfo::getExprForPersonalitySymbol(Sym, Encoding, Streamer); 153+} 154Index: 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 175 bool 176 SparcMCExpr::EvaluateAsRelocatableImpl(MCValue &Res, 177 const MCAsmLayout *Layout) const { 178+ if (!Layout) 179+ return false; 180 return getSubExpr()->EvaluateAsRelocatable(Res, *Layout); 181 } 182 183Index: lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h 184=================================================================== 185--- lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h 186+++ lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.h 187@@ -17,13 +17,16 @@ 188 #include "llvm/MC/MCAsmInfoELF.h" 189 190 namespace llvm { 191- class StringRef; 192+class StringRef; 193 194- class SparcELFMCAsmInfo : public MCAsmInfoELF { 195- virtual void anchor(); 196- public: 197- explicit SparcELFMCAsmInfo(StringRef TT); 198- }; 199+class SparcELFMCAsmInfo : public MCAsmInfoELF { 200+ virtual void anchor(); 201+public: 202+ explicit SparcELFMCAsmInfo(StringRef TT); 203+ virtual const MCExpr* getExprForPersonalitySymbol(const MCSymbol *Sym, 204+ unsigned Encoding, 205+ MCStreamer &Streamer) const; 206+}; 207 208 } // namespace llvm 209 210Index: 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 { 215 VK_Sparc_L44, 216 VK_Sparc_HH, 217 VK_Sparc_HM, 218+ VK_Sparc_R_DISP32, 219 VK_Sparc_TLS_GD_HI22, 220 VK_Sparc_TLS_GD_LO10, 221 VK_Sparc_TLS_GD_ADD, 222Index: 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 227 SparcJITInfo.cpp 228 SparcCodeEmitter.cpp 229 SparcMCInstLower.cpp 230+ SparcTargetObjectFile.cpp 231 ) 232 233 add_dependencies(LLVMSparcCodeGen SparcCommonTableGen intrinsics_gen) 234Index: test/CodeGen/SPARC/exception.ll 235=================================================================== 236--- test/CodeGen/SPARC/exception.ll 237+++ test/CodeGen/SPARC/exception.ll 238@@ -1,7 +1,9 @@ 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 245 246 247 %struct.__fundamental_type_info_pseudo = type { %struct.__type_info_pseudo } 248@@ -40,11 +42,23 @@ 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) 254 ; V8PIC: .data 255 ; V8PIC: .L_ZTIi.DW.stub: 256 ; V8PIC-NEXT: .word _ZTIi 257 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) 268+ 269+ 270 ; V9ABS-LABEL: main: 271 ; V9ABS: .cfi_startproc 272 ; V9ABS: .cfi_personality 0, __gxx_personality_v0 273@@ -65,11 +79,22 @@ 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) 279 ; V9PIC: .data 280 ; V9PIC: .L_ZTIi.DW.stub: 281 ; V9PIC-NEXT: .xword _ZTIi 282 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) 293+ 294 define i32 @main(i32 %argc, i8** nocapture readnone %argv) unnamed_addr #0 { 295 entry: 296 %0 = icmp eq i32 %argc, 2 297