wg icon indicating copy to clipboard operation
wg copied to clipboard

Expose the -warn-stack-size= LLVM option somehow

Open whitequark opened this issue 7 years ago • 6 comments

I've just learned that LLVM can, in fact, do a limited stack size analysis: https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20130603/177010.html.

It's not interprocedural but I think it's still quite useful e.g. if LLVM ends up allocating a large array on stack, which seems to be a source of stack overflows that might be on the second place after recursion IME.

whitequark avatar Apr 06 '18 19:04 whitequark

In theory -C llvm-args=-warn-stack-size=$N should pass the flag to LLVM, but since these are warnings rustc won't report them to the console, I think.

I'm looking at the LLVM source code and it seems that there's some option to emit (as debug logs?) the number of stack bytes that each function uses. I have no idea how to make rustc print these statistics though.

Perhaps @nagisa or @eddyb can give us some clues here?

japaric avatar Apr 07 '18 00:04 japaric

@japaric I think you need to call LLVMContextSetDiagnosticHandler. But probably a better idea is an LLVM patch that exposes this data directly in a proper format.

whitequark avatar Apr 07 '18 08:04 whitequark

Hey @japaric, I know you've done some work exposing stack usage, is this issue still open/relevant?

jamesmunns avatar Feb 04 '19 00:02 jamesmunns

@jamesmunns the work I did was related to #106. The llvm feature described here is a different feature.

japaric avatar Feb 04 '19 17:02 japaric

@japaric do you think this should stay open? If so, please remove the cleanup tag.

jamesmunns avatar Feb 14 '19 18:02 jamesmunns

@jamesmunns not sure, but I can tell you that I don't intend to work on this one. We don't really have a policy for keeping "interesting project" issues around. Perhaps this could be moved into the "not yet awesome embedded Rust" list? Then we can close this issue.

japaric avatar Mar 04 '19 05:03 japaric

Closing this issue as part of today's triage. I'm sure there's still work to be done on improving stack size handling and overflow detection, but no one in the WG is currently planning to do it. There have been some interesting developments in handling stack overflows, such as flip-link, and newer Arm cores even have stack limit registers that are checked in hardware.

adamgreig avatar Jun 11 '24 18:06 adamgreig