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,21 @@ // 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 +929,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,39 @@ +# 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: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-main.s -o %t3.o +# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t1.o %t3.o %t4.so -o %t -z notext +# RUN: llvm-objdump -d %t | FileCheck %s + +.macro prologue1 function_to_call + .global prologue1_calls_\function_to_call + .type prologue1_calls_\function_to_call,@function +prologue1_calls_\function_to_call: + cmp %fs:0x70,%rsp + jae 1f + callq __morestack + retq +1: + # Various and duplicate calls to ensure every code path is taken. + callq \function_to_call + callq \function_to_call + callq 1b + callq non_function_text_symbol + retq + .size prologue1_calls_\function_to_call,. - prologue1_calls_\function_to_call +.endm + .text + +# For a cross .so call, make sure ldd produced the conservative call to __morestack_non_split. +# CHECK: prologue1_calls_split: +# CHECK-NEXT: stc{{.*$}} +# CHECK-NEXT: nopl{{.*$}} +# CHECK: jae{{.*$}} +# CHECK-NEXT: callq{{.*}}<__morestack_non_split> + +prologue1 split + + .section .note.GNU-stack,"",@progbits + .section .note.GNU-split-stack,"",@progbits Index: test/ELF/x86-64-split-stack-prologue-adjust-success.s =================================================================== --- test/ELF/x86-64-split-stack-prologue-adjust-success.s +++ test/ELF/x86-64-split-stack-prologue-adjust-success.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-extra.s -o %t2.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-main.s -o %t3.o -# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t1.o %t2.o %t3.o -o %t -z notext +# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t1.o %t2.o %t3.o -o %t -z notext # RUN: llvm-objdump -d %t | FileCheck %s # Avoid duplicating the prologue for every test via macros.