[PATCH] D68907: [6/7/trunk] -fno-plt generates wrong relocation for std::ios_base::Init leading to segmentation fault

kamlesh kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 13 10:10:26 PDT 2019


kamleshbhalui updated this revision to Diff 224785.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68907/new/

https://reviews.llvm.org/D68907

Files:
  llvm/lib/Target/X86/X86FastISel.cpp
  llvm/test/CodeGen/X86/pr39252.ll


Index: llvm/test/CodeGen/X86/pr39252.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/pr39252.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -fast-isel=1 | FileCheck %s -check-prefix=FASTISEL
+
+%"g1" = type { i8 }
+
+ at g2 = internal global %"g1" zeroinitializer, align 1
+ at __dso_handle = external hidden global i8
+
+define internal void @foobar() #0  {
+entry:
+  call void @foo(%"g1"* @g2)
+  %0 = call i32 @func(void (i8*)* bitcast (void (%"g1"*)* @bar to void (i8*)*), i8* getelementptr inbounds (%"g1", %"g1"* @g2, i32 0, i32 0), i8* @__dso_handle) #3
+  ret void
+; FASTISEL: movq    bar at GOTPCREL(%rip), %rdi
+}
+
+declare void @foo(%"g1"*) unnamed_addr #1
+
+declare void @bar(%"g1"*) unnamed_addr #2
+
+declare i32 @func(void (i8*)*, i8*, i8*) #3
+
+attributes #0 = { noinline uwtable }
+attributes #1 = { nonlazybind }
+attributes #2 = { nounwind nonlazybind }
+attributes #3 = { nounwind }
+
+
Index: llvm/lib/Target/X86/X86FastISel.cpp
===================================================================
--- llvm/lib/Target/X86/X86FastISel.cpp
+++ llvm/lib/Target/X86/X86FastISel.cpp
@@ -745,6 +745,12 @@
         AM.Base.Reg = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
       }

+      bool NeedLoad = GVFlags == X86II::MO_GOTPCREL;
+      if (NeedLoad) {
+          assert(AM.Base.Reg == 0 && AM.IndexReg == 0);
+          AM.Base.Reg = X86::RIP;
+      }
+
       // Unless the ABI requires an extra load, return a direct reference to
       // the global.
       if (!isGlobalStubReference(GVFlags)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68907.224785.patch
Type: text/x-patch
Size: 1608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191013/b8751636/attachment.bin>


More information about the llvm-commits mailing list