diff options
| -rw-r--r-- | lld/ELF/InputSection.cpp | 22 | ||||
| -rw-r--r-- | lld/test/ELF/x86-64-split-stack-prologue-adjust-shared.s | 31 |
2 files changed, 44 insertions, 9 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 48603a30e6a..801e2f86867 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -928,9 +928,8 @@ void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *Buf, 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::adjustSplitStackFunctionPrologues(uint8_t *Buf, // 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::adjustSplitStackFunctionPrologues(uint8_t *Buf, 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"); } } diff --git a/lld/test/ELF/x86-64-split-stack-prologue-adjust-shared.s b/lld/test/ELF/x86-64-split-stack-prologue-adjust-shared.s new file mode 100644 index 00000000000..9da2dde2e20 --- /dev/null +++ b/lld/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 |

