Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -894,9 +894,8 @@ continue; // Ignore calls into the split-stack api. - Defined *D = cast(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; } @@ -904,13 +903,18 @@ // 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(D->Section); - if (!IS || IS->getFile()->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(Rel.Sym)) + if (InputSection *IS = cast_or_null(D->Section)) + if (!IS || IS->getFile()->SplitStack) + continue; if (enclosingPrologueAttempted(Rel.Offset, Prologues)) continue; @@ -922,7 +926,7 @@ continue; if (!getFile()->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"); } } 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,@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,"",@progbits + .section .note.GNU-split-stack,"",@progbits