[PATCH] D50371: Split-stack support for cross-linking shared-libraries.

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 9 14:46:08 PDT 2018


saugustine updated this revision to Diff 160015.
saugustine added a comment.

Further minimize the test case.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50371

Files:
  ELF/InputSection.cpp
  test/ELF/x86-64-split-stack-prologue-adjust-shared.s


Index: test/ELF/x86-64-split-stack-prologue-adjust-shared.s
===================================================================
--- /dev/null
+++ test/ELF/x86-64-split-stack-prologue-adjust-shared.s
@@ -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
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -894,23 +894,27 @@
       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;
     }
 
     // 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;
@@ -922,7 +926,7 @@
         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");
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50371.160015.patch
Type: text/x-patch
Size: 3234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180809/8279d620/attachment.bin>


More information about the llvm-commits mailing list