Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit a stack size section using LLVM and parse this data #106

Closed
whitequark opened this issue Jun 15, 2018 · 5 comments
Closed

Emit a stack size section using LLVM and parse this data #106

whitequark opened this issue Jun 15, 2018 · 5 comments

Comments

@whitequark
Copy link

From the manual:

Emitting function stack size information
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A section containing metadata on function stack sizes will be emitted when
``TargetLoweringObjectFile::StackSizesSection`` is not null, and
``TargetOptions::EmitStackSizeSection`` is set (-stack-size-section). The
section will contain an array of pairs of function symbol values (pointer size)
and stack sizes (unsigned LEB128). The stack size values only include the space
allocated in the function prologue. Functions with dynamic stack allocations are
not included.
@japaric
Copy link
Member

japaric commented Jun 29, 2018

@whitequark how does this relate to #79 (Expose the -warn-stack-size= LLVM option)? At first glance it sounds like using the stack size section (as described in this issue) would give us more fine grained information and that we should do this instead of #79.

@whitequark
Copy link
Author

Generally yes, but I think the stack size section might not be supported on all targets, so this should be investigated more carefully.

@japaric
Copy link
Member

japaric commented Jun 30, 2018

PR rust-lang/rust#51946 exposes this LLVM feature

@japaric
Copy link
Member

japaric commented Sep 29, 2018

Update:

The -Z emit-stack-sizes flag is available since nightly-2018-09-27 as an experimental feature. The (LLVM) feature only supports the ELF object format (as of LLVM 8, AFAICT) and the rustc flag is documented in the unstable book.

The stack-sizes crate can be used as a library to parse this information and also contains tools to print the information in human readable format.

@japaric
Copy link
Member

japaric commented Mar 4, 2019

Update:

cargo-call-stack is a whole program stack analysis tool that uses the -Z emit-stack-sizes feature / flag.

I think we can close this issue since the feature is exposed in rustc and there are libraries to parse the emitted data and end user tools.

It's unclear if this flag will ever be stabilized or when; there's no precedent for exposing stable interfaces to llvm internals from rustc (except for 1.0 mistakes like llvm-args) and I'm not aware of any plans to do anything like that in the near future. If I heard of any movement on that front I'll report back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants