[lld] r339626 - Support shared objects for split stack.

Sterling Augustine via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 13 15:29:15 PDT 2018


Author: saugustine
Date: Mon Aug 13 15:29:15 2018
New Revision: 339626

URL: http://llvm.org/viewvc/llvm-project?rev=339626&view=rev
Log:
Support shared objects for split stack.

Added:
    lld/trunk/test/ELF/x86-64-split-stack-prologue-adjust-shared.s
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=339626&r1=339625&r2=339626&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Aug 13 15:29:15 2018
@@ -928,9 +928,8 @@ void InputSectionBase::adjustSplitStackF
       continue;
 
     // Ignore calls into the split-stack api.
-    Defined *D = cast<Defined>(Rel.Sym);
-    if (D->getName().startswith("__morestack")) {
-      if (D->getName().equals("__morestack"))
+    if (Rel.Sym->getName().startswith("__morestack")) {
+      if (Rel.Sym->getName().equals("__morestack"))
         MorestackCalls.push_back(&Rel);
       continue;
     }
@@ -938,13 +937,18 @@ void InputSectionBase::adjustSplitStackF
     // A relocation to non-function isn't relevant. Sometimes
     // __morestack is not marked as a function, so this check comes
     // after the name check.
-    if (D->Type != STT_FUNC)
+    if (Rel.Sym->Type != STT_FUNC)
       continue;
 
-    // If the callee's-file was compiled with split stack, nothing to do.
-    auto *IS = cast_or_null<InputSection>(D->Section);
-    if (!IS || IS->getFile<ELFT>()->SplitStack)
-      continue;
+    // If the callee's-file was compiled with split stack, nothing to do.  In
+    // this context, a "Defined" symbol is one "defined by the binary currently
+    // being produced". So an "undefined" symbol might be provided by a shared
+    // library. It is not possible to tell how such symbols were compiled, so be
+    // conservative.
+    if (Defined *D = dyn_cast<Defined>(Rel.Sym))
+      if (InputSection *IS = cast_or_null<InputSection>(D->Section))
+        if (!IS || IS->getFile<ELFT>()->SplitStack)
+          continue;
 
     if (enclosingPrologueAttempted(Rel.Offset, Prologues))
       continue;
@@ -956,7 +960,7 @@ void InputSectionBase::adjustSplitStackF
         continue;
       if (!getFile<ELFT>()->SomeNoSplitStack)
         error(lld::toString(this) + ": " + F->getName() +
-              " (with -fsplit-stack) calls " + D->getName() +
+              " (with -fsplit-stack) calls " + Rel.Sym->getName() +
               " (without -fsplit-stack), but couldn't adjust its prologue");
     }
   }

Added: lld/trunk/test/ELF/x86-64-split-stack-prologue-adjust-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-split-stack-prologue-adjust-shared.s?rev=339626&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-split-stack-prologue-adjust-shared.s (added)
+++ lld/trunk/test/ELF/x86-64-split-stack-prologue-adjust-shared.s Mon Aug 13 15:29:15 2018
@@ -0,0 +1,31 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-extra.s -o %t2.o
+# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t2.o -o %t4.so  -shared
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t1.o %t4.so -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+# For a cross .so call, make sure lld produced the conservative call to __morestack_non_split.
+# CHECK: prologue1_cross_so_call:
+# CHECK-NEXT: stc{{.*$}}
+# CHECK-NEXT: nopl{{.*$}}
+# CHECK: jae{{.*$}}
+# CHECK-NEXT: callq{{.*}}<__morestack_non_split>
+
+	.text
+
+	.global	prologue1_cross_so_call
+	.type	prologue1_cross_so_call, at function
+prologue1_cross_so_call:
+	cmp %fs:0x70,%rsp
+	jae 1f
+	callq __morestack
+	retq
+1:
+	callq split
+	retq
+	.size	prologue1_cross_so_call,. - prologue1_cross_so_call
+
+	.section	.note.GNU-stack,"", at progbits
+	.section	.note.GNU-split-stack,"", at progbits




More information about the llvm-commits mailing list