LLVM has a handy option, -fstack-size-section
, which includes an elf section with stack sizes of all functions:
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fstack-size-section
Is there some way I can use that feature with Zig?
Figured this out! You can use emit-llvm-ir
to get an .ll
file with textual IR:
if (options.emit_llvm_ir) {
steps.install.dependOn(&b.addInstallBinFile(
tigerbeetle_exe.getEmittedLlvmIr(),
"tigerbeetle.ll",
).step);
}
Then, you can feed that file to llc
which accepts all the LLVM options:
/opt/homebrew/opt/llvm/bin/llc zig-out/bin/tigerbeetle.ll --stack-size-section -non-global-value-max-name-size=65536
That produces an .s
file which you still need to compile somehow, but I was able to get the stack size info from the textual file just fine.
5 Likes