<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Quarkslab's blog - automatic initialisation</title><link href="http://blog.quarkslab.com/" rel="alternate"></link><link href="http://blog.quarkslab.com/feeds/automatic-initialisation.rss.xml" rel="self"></link><id>http://blog.quarkslab.com/</id><updated>2026-06-09T00:00:00+02:00</updated><entry><title>Extending LLVM's BOLT-based Binary Analyser to Validate Stack Variable Initialisation</title><link href="http://blog.quarkslab.com/extending-llvms-bolt-based-binary-analyser-to-validate-stack-variable-initialisation.html" rel="alternate"></link><published>2026-06-09T00:00:00+02:00</published><updated>2026-06-09T00:00:00+02:00</updated><author><name>Francesco Cagnin</name></author><id>tag:blog.quarkslab.com,2026-06-09:/extending-llvms-bolt-based-binary-analyser-to-validate-stack-variable-initialisation.html</id><summary type="html">&lt;p&gt;The &lt;a href="https://ostif.org/"&gt;Open Source Technology Improvement Fund&lt;/a&gt; (OSTIF) commissioned Quarkslab to extend the BOLT-based static binary analyser in LLVM to support additional compiler flags for security hardening. This work resulted in the first iteration of a scanner for validating the implementation of &lt;code&gt;-ftrivial-auto-var-init&lt;/code&gt;.&lt;/p&gt;</summary><content type="html">&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://research.facebook.com/publications/bolt-a-practical-binary-optimizer-for-data-centers-and-beyond/"&gt;BOLT&lt;/a&gt;, originally developed at Meta and now &lt;a href="https://github.com/llvm/llvm-project/blob/main/bolt/README.md"&gt;part of the LLVM project.&lt;/a&gt;, is a post-link optimiser that rewrites compiled applications to improve their performance.
In 2024, Kristof Beyls at Arm built on top of BOLT &lt;a href="https://discourse.llvm.org/t/rfc-bolt-based-binary-analysis-tool-to-verify-correctness-of-security-hardening/78148"&gt;a prototype static binary analyser to validate compiler code generation for security-related features.&lt;/a&gt; This tool operated directly at the binary level to "verify that a given hardening feature has been applied correctly across the whole binary," by checking whether the compiled program satisfies the security properties the feature is intended to provide.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/llvm/llvm-project/commit/850b49297615a613ac83adca2c9cf823a4b8ef95"&gt;first scanner implemented for the analyser&lt;/a&gt; targeted the "pac-ret" hardening scheme for AArch64, associated to the compiler flag &lt;code&gt;-mbranch-protection=pac-ret&lt;/code&gt;, seeking to detect unsafe instruction patterns that could weaken the security guarantees expected from code that uses Pointer Authentication correctly.
A second scanner that focuses on code generation mechanisms that prevent &lt;a href="https://blog.qualys.com/vulnerabilities-threat-research/2017/06/19/the-stack-clash"&gt;Stack Clash&lt;/a&gt; attacks (i.e. &lt;code&gt;-fstack-clash-protection&lt;/code&gt;) is in the works.&lt;/p&gt;
&lt;p&gt;With the goal of further developing the BOLT-based binary analyser, OSTIF commissioned Quarkslab to extend it to support additional compiler flags for security hardening. The initial mandate was intentionally broad, leaving it to us to identify which code generation schemes would be appropriate to tackle, balancing relevance, complexity, and the resources available for the project.
Following a preliminary assessment, Quarkslab was then expected to propose one or more hardening features to work on and, upon agreement with OSTIF, implement corresponding scanners for the binary analyser.&lt;/p&gt;
&lt;h1 id="work-summary"&gt;Work Summary&lt;/h1&gt;
&lt;p&gt;The project was carried out between November 2025 and April 2026.&lt;/p&gt;
&lt;p&gt;Candidate compiler hardening options were first reviewed, and &lt;code&gt;-ftrivial-auto-var-init&lt;/code&gt; was selected as the most suitable target. This flag is handled by both GCC and Clang, is relevant to current hardening practice, and has a clear binary-level property to check: automatic variables&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; should be initialised before use.&lt;/p&gt;
&lt;p&gt;Two complementary approaches were then developed for validating the flag statically at the binary level:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a load-oracle approach, which uses stack loads as evidence of automatic variables residing on the stack; and&lt;/li&gt;
&lt;li&gt;a store-witness approach, which checks whether the bytes read by each stack load were written on every relevant control-flow path before the load.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These strategies were implemented in a new BOLT-based scanner for x86-64 binaries, published at &lt;a href="https://github.com/quarkslab/bolt-stackinit-scanner"&gt;quarkslab/bolt-stackinit-scanner&lt;/a&gt;. The scanner recovers direct and derived stack accesses, recognises common block initialisation patterns, verifies initialisation within and across functions, and finally reports stack reads that may read uninitialised memory.
The same scanner can also incidentally be used as a general detector for uninitialised stack reads in binaries not compiled with &lt;code&gt;-ftrivial-auto-var-init&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The scanner was tested on GNU coreutils 9.5 binaries across GCC and Clang x86-64 builds, at several optimisation levels, with and without &lt;code&gt;-ftrivial-auto-var-init=zero&lt;/code&gt;. At this stage, this evaluation was only intended to carry the implementation forward and identify its remaining limits.&lt;/p&gt;
&lt;p&gt;Interested readers are encouraged to consult the full project report, published on Quarkslab's &lt;a href="https://github.com/quarkslab/public-reports/blob/main/Reports/26-04-2682-REP-OSTIF-LLVM-BOLT-validating-automatic-variable-initialisation-V1.1.pdf"&gt;public reports repository&lt;/a&gt;, presenting the theoretical and practical challenges, the limitations of the scanner, and possible ways forward.&lt;/p&gt;
&lt;h1 id="conclusion"&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;This first iteration of the scanner shows that the approach works in principle, though the observed residual reports make apparent the limits of static analysis. Large binaries still generate too many false positives, to the point where manual, unassisted triage becomes too cumbersome. Possible next steps to refine the analysis further include using symbolic execution to prune infeasible control-flow paths, and exploring auxiliary techniques such as DWARF-assisted variable recovery or differential compilation.&lt;/p&gt;
&lt;p&gt;This study proved both challenging and stimulating, and gave us the opportunity to explore another facet of binary analysis. Quarkslab would like to thank Kristof Beyls for putting the project forward and OSTIF for the longstanding trust and collaboration over the years.&lt;/p&gt;
&lt;h1 id="further-reading"&gt;Further Reading&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ostif.org/bolt-security-engagement-complete/"&gt;OSTIF blog post&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnote"&gt;
&lt;hr/&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;The set of variables broadly consisting of block-scope locals that are not declared static, thread local, or extern.&amp;nbsp;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;larrhk;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Program Analysis"></category><category term="OSTIF"></category><category term="automatic initialisation"></category><category term="static analysis"></category><category term="tool"></category><category term="2026"></category></entry></feed>