Skip to content

Commit 24e0831

Browse files
committed
Revert "Revert "add stack-probes to make stack-overflow detection more reliable (#40068)""
This reverts commit 7da505b. Elliot didn't `git worktree` right, and ended up commiting to `master` isntead of a feature branch
1 parent 7da505b commit 24e0831

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/codegen.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,14 @@ static void jl_init_function(Function *F)
17771777
#ifdef JL_DISABLE_FPO
17781778
F->addFnAttr("frame-pointer", "all");
17791779
#endif
1780+
#if !defined(_COMPILER_ASAN_ENABLED_) && !defined(_OS_WINDOWS_)
1781+
// ASAN won't like us accessing undefined memory causing spurious issues,
1782+
// and Windows has platform-specific handling which causes it to mishandle
1783+
// this annotation. Other platforms should just ignore this if they don't
1784+
// implement it.
1785+
F->addFnAttr("probe-stack", "inline-asm");
1786+
//F->addFnAttr("stack-probe-size", 4096); // can use this to change the default
1787+
#endif
17801788
}
17811789

17821790
static std::pair<bool, bool> uses_specsig(jl_method_instance_t *lam, jl_value_t *rettype, bool prefer_specsig)
@@ -6488,28 +6496,15 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
64886496
}
64896497
}
64906498

6491-
/*
6492-
// step 6. (optional) check for stack overflow (the slower way)
6493-
Value *cur_sp =
6494-
ctx.builder.CreateCall(Intrinsic::getDeclaration(M,
6495-
Intrinsic::frameaddress),
6496-
ConstantInt::get(T_int32, 0));
6497-
Value *sp_ok =
6498-
ctx.builder.CreateICmpUGT(cur_sp,
6499-
ConstantInt::get(T_size,
6500-
(uptrint_t)jl_stack_lo));
6501-
error_unless(ctx, sp_ok, "stack overflow");
6502-
*/
6503-
6504-
// step 7. set up GC frame
6499+
// step 6. set up GC frame
65056500
allocate_gc_frame(ctx, b0);
65066501
Value *last_age = NULL;
65076502
emit_last_age_field(ctx);
65086503
if (toplevel || ctx.is_opaque_closure) {
65096504
last_age = tbaa_decorate(tbaa_gcframe, ctx.builder.CreateAlignedLoad(ctx.world_age_field, Align(sizeof(size_t))));
65106505
}
65116506

6512-
// step 8. allocate local variables slots
6507+
// step 7. allocate local variables slots
65136508
// must be in the first basic block for the llvm mem2reg pass to work
65146509
auto allocate_local = [&](jl_varinfo_t &varinfo, jl_sym_t *s) {
65156510
jl_value_t *jt = varinfo.value.typ;
@@ -6627,7 +6622,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
66276622
}
66286623
}
66296624

6630-
// step 9. move args into local variables
6625+
// step 8. move args into local variables
66316626
Function::arg_iterator AI = f->arg_begin();
66326627

66336628
auto get_specsig_arg = [&](jl_value_t *argType, Type *llvmArgType, bool isboxed) {
@@ -6757,7 +6752,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
67576752
}
67586753
}
67596754

6760-
// step 10. allocate rest argument
6755+
// step 9. allocate rest argument
67616756
CallInst *restTuple = NULL;
67626757
if (va && ctx.vaSlot != -1) {
67636758
jl_varinfo_t &vi = ctx.slots[ctx.vaSlot];
@@ -6799,7 +6794,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
67996794
}
68006795
}
68016796

6802-
// step 11. Compute properties for each statements
6797+
// step 10. Compute properties for each statements
68036798
// This needs to be computed by iterating in the IR order
68046799
// instead of control flow order.
68056800
auto in_user_mod = [] (jl_module_t *mod) {
@@ -6921,7 +6916,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
69216916
Instruction &prologue_end = ctx.builder.GetInsertBlock()->back();
69226917

69236918

6924-
// step 12. Do codegen in control flow order
6919+
// step 11. Do codegen in control flow order
69256920
std::vector<int> workstack;
69266921
std::map<int, BasicBlock*> BB;
69276922
std::map<size_t, BasicBlock*> come_from_bb;
@@ -7468,7 +7463,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
74687463
PN->eraseFromParent();
74697464
}
74707465

7471-
// step 13. Perform any delayed instantiations
7466+
// step 12. Perform any delayed instantiations
74727467
if (ctx.debug_enabled) {
74737468
bool in_prologue = true;
74747469
for (auto &BB : *ctx.f) {

test/llvmpasses/noinline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ include(joinpath("..", "testhelpers", "llvmpasses.jl"))
1717
return A + B
1818
end
1919

20-
# CHECK: attributes #{{[0-9]+}} = {{{([a-z]+ )*}} noinline {{([a-z]+ )*}}}
20+
# CHECK: attributes #{{[0-9]+}} = {{{[^}]*}} noinline {{[^}]*}}}
2121
emit(simple_noinline, Float64, Float64)

0 commit comments

Comments
 (0)