A Compiler-Driven Approach for Static Dependency Injection in Embedded Software

  • Thiago Borges de Oliveira UFJ
  • Ariadne de Andrade Costa UFJ

Resumo


Developing embedded software is challenging due to the need to strike a balance between writing loosely coupled and maintainable code while coping with the microcontroller’s limitations in memory, storage, and processing power. While object-oriented programming can lead to improved abstractions and cohesive, easier-to-maintain software, traditional low-level implementation of polymorphism often introduces runtime overhead that hinders its adoption. This paper proposes a compiler-driven dependency injection (DI) technique that enables the compiler to resolve dependencies and replace bound interfaces with concrete implementations in the AST tree to reduce the burden of virtual dispatch in embedded software. We compared five implementations of a breakout game written with object-oriented language features, C++20 concepts, and our proposed method. Results show that the language features allow clear interface definitions and centralized binding configurations, enhancing maintainability and portability. Furthermore, our compiler-driven approach enables optimizations beyond interface boundaries, improving code inlining, constant propagation, interprocedural optimization, and dead code elimination, producing 41.9% smaller and up to 73.3% faster firmware than equivalent versions with compile-time injection.

Palavras-chave: Compiler-driven dependency injection, Embedded software, Hardware Abstraction, Optimization

Referências

Hudson Ayers, Evan Laufer, Paul Mure, Jaehyeon Park, Eduardo Rodelo, Thea Rossman, Andrey Pronin, Philip Levis, and Johnathan Van Why. 2022. Tighten rust’s belt: shrinking embedded Rust binaries. In Proceedings of the 23rd ACM SIGPLAN/SIGBED International Conference on Languages, Compilers, and Tools for Embedded Systems (San Diego, CA, USA) (LCTES 2022). Association for Computing Machinery, New York, NY, USA, 121–132. DOI: 10.1145/3519941.3535075

Markus Bauer and Christian Rossow. 2021. NoVT: Eliminating C++ Virtual Calls to Mitigate Vtable Hijacking. In 2021 IEEE European Symposium on Security and Privacy (EuroS&P). 650–666. DOI: 10.1109/EuroSP51992.2021.00049

Giorgio Buttazzo. 2006. Research trends in real-time computing for embedded systems. SIGBED Rev. 3, 3 (July 2006), 1–10. DOI: 10.1145/1164050.1164052

Marlin Community. 2025. Marlin Firmware. [link]. Accessed: 2025-04-27.

Keith D. Cooper and Linda Torczon. 2021. Engineering a Compiler (3 ed.). Morgan Kaufmann.

Thaís Damásio, Vinícius Pacheco, Fabrício Goes, Fernando Pereira, and Rodrigo Rocha. 2021. Inlining for Code Size Reduction. In Proceedings of the 25th Brazilian Symposium on Programming Languages (Joinville, Brazil) (SBLP ’21). Association for Computing Machinery, New York, NY, USA, 17–24. DOI: 10.1145/3475061.3475081

Thiago Borges de Oliveira. 2023. Robotis Language: A prototype language for embedded systems with compile-time dependency injection. [link]. Accessed: 2025-06-08.

Michael D. Ernst, Greg J. Badros, and David Notkin. 2002. An Empirical Analysis of C Preprocessor Use. IEEE Trans. Softw. Eng. 28, 12 (Dec. 2002), 1146–1170. DOI: 10.1109/TSE.2002.1158288

Vahid Garousi, Michael Felderer, and Feyza Nur Kılıçaslan. 2019. A survey on software testability. Information and Software Technology 108 (2019), 35–64. DOI: 10.1016/j.infsof.2018.12.003

Marcell Ferenc Juhász. 2023. Modern C++ in embedded systems-Utilization of modern C++ language features for creating zero-overhead firmware architectures for resource-constrained embedded systems. Ph. D. Dissertation. Institute of Computer Technology, Technische Universität Wien.

Kris Jusiak. 2018. boost-ext.di: C++14 Dependency Injection Library. [link]. Accessed: 2025-05-20.

Gregory Kick. 2025. Dagger Framework. [link]. Accessed: 2025-04-27.

Chris Lattner and Vikram Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. In Proceedings of the 2004 International Symposium on Code Generation and Optimization (CGO). 75–86. DOI: 10.1109/CGO.2004.1281665

Microchip Technology Inc. 2015. ATmega328P Datasheet: 8-bit AVR Microcontroller with 32K Bytes In-System Programmable Flash. [link]. Accessed: 2025-06-08.

Brent Pappas and Paul Gazzillo. 2024. Semantic Analysis of Macro Usage for Portability. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering (Lisbon, Portugal) (ICSE ’24). Association for Computing Machinery, New York, NY, USA. DOI: 10.1145/3597503.3623323

Robbie Vanbrabant Schaefer. 2008. Google Guice: Agile Lightweight Dependency Injection Framework. Apress.

Felix Schuster, Thomas Tendyck, Christopher Liebchen, Lucas Davi, Ahmad-Reza Sadeghi, and Thorsten Holz. 2015. Counterfeit Object-oriented Programming: On the Difficulty of Preventing Code Reuse Attacks in C++ Applications. In 2015 IEEE Symposium on Security and Privacy. 745–762. DOI: 10.1109/SP.2015.51

Michael L. Scott. 2016. Programming Language Pragmatics (4 ed.). Morgan Kaufmann, Boston, MA.

Mark Seemann and Steven van Deursen. 2019. Dependency Injection Principles, Practices, and Patterns. Manning Publications.

Solomon Systech Limited. 2008. SSD1306: 128 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller. [link]. Accessed: 2025-04-02.

Bjarne Stroustrup. 1994. The Design and Evolution of C++. Addison-Wesley.

Steven Varoumas, Basile Pesin, Benoît Vaugon, and Emmanuel Chailloux. 2023. Programming microcontrollers through highlevel abstractions: The OMicroB project. Journal of Computer Languages 77 (2023), 101228. DOI: 10.1016/j.cola.2023.101228

Craig Walls. 2022. Spring in action. Manning Publications.
Publicado
22/09/2025
OLIVEIRA, Thiago Borges de; COSTA, Ariadne de Andrade. A Compiler-Driven Approach for Static Dependency Injection in Embedded Software. In: SIMPÓSIO BRASILEIRO DE LINGUAGENS DE PROGRAMAÇÃO (SBLP), 29. , 2025, Recife/PE. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2025 . p. 19-27. DOI: https://doi.org/10.5753/sblp.2025.10519.