Developing a Clang-Based Safe Compiler
https://doi.org/10.15514/ISPRAS-2024-36(4)-3
Abstract
Due to the use of aggressive optimizations by modern C/C++ compilers that exploit undefined behavior, there is a need for a safe compiler that does not perform such optimizations and prevents developers from using unsafe statements and expressions. Such a safe compiler based on GCC has been developed in ISP RAS, but some developers prefer Clang instead of GCC, which has mainly the same problems of exploiting undefined behavior. This paper examines the capabilities of Clang to perform safe compilation and describes the implementation of a safe compiler based on it. For the created safe compiler, the applicability in practice is shown and the impact on program performance is evaluated.
About the Authors
Pavel Dmitrievich DUNAEVRussian Federation
Senior Laboratory technician at Ivannikov Institute for System Programming of the Russian Academy of Sciences, 2nd year Master’s student at Saratov State University. Research interests: compilers, operating systems, discrete mathematics.
Artem Aleksandrovich SINKEVICH
Russian Federation
Senior Laboratory technician at Ivannikov Institute for System Programming of the Russian Academy of Sciences, 1st year Master’s student at Saratov State University. Research interests: compilers, discrete mathematics, neural networks
Artemiy Maksimovich GRANAT
Russian Federation
Laboratory technician at Ivannikov Institute for System Programming of the Russian Academy of Sciences, 4th year Bachelor’s student at Saratov State University. Research interests: compilers, operating systems, computer networks.
Inna Aleksandrovna BATRAEVA
Russian Federation
Candidate of Science in Physics and Mathematics, Associate Professor, Head of the Department of Programming Technologies. Research interests: discrete mathematics, automata theory, theory of formal languages and grammars, information systems in theoretical and applied linguistics.
Sergei Vladimirovich MIRONOV
Russian Federation
Nikita Yurievich SHUGALEY
Russian Federation
Senior Laboratory technician at Ivannikov Institute for System Programming of the Russian Academy of Sciences, 2st year Master’s student at the Moscow Institute of Physics and Technology, Phystech School of Radio Engineering and Computer Technology, field of Applied Physics and Mathematics.
References
1. Clang, Available at: https://clang.llvm.org/, accessed 24.04.2024.
2. Jetbrains Developer Ecosystem: C++, Available at: https://www.jetbrains.com/lp/devecosystem-2023/cpp/, accessed 24.04.2024.
3. GCC, Available at: https://gcc.gnu.org/, accessed 24.04.2024.
4. LLVM Developer Policy, Available at: https://llvm.org/docs/DeveloperPolicy.html, accessed 24.04.2024.
5. LLVM, Available at: https://llvm.org/, accessed 24.04.2024.
6. Скворцов Л.В., Баев Р.В., Долгорукова К.Ю., Шарыгин Е.Ю. Разработка компилятора для стековой процессорной архитектуры TF16 на основе LLVM. Труды ИСП РАН, том 33, вып. 5, 2021 г., стр. 137-154. DOI: 10.15514/ISPRAS–2021–33(5)–8./ Skvortsov L.V., Baev R.V., Dolgorukova K.Y., Sharygin E.Y. Developing an LLVM-based compiler for stack based TF16 processor architecture. Trudy ISP RAN/Proc. ISP RAS, vol. 33, issue 5, 2021, pp. 137-154 (in Russian). DOI: 10.15514/ISPRAS–2021–33(5)–8.
7. Мельник Д., Курмангалеев Ш., Аветисян А., Белеванцев А., Плотников Д., Варданян М. Оптимизация приложений для заданных статических компиляторов и целевых архитектур: методы и инструменты. Труды ИСП РАН, том 26, вып. 1, 2014 г., стр. 343-356. DOI: 10.15514/ISPRAS-2014-26(1)-13./ Melnik D., Kurmangaleev S., Avetisyan A., Belevantsev A., Plotnikov D., Vardanyan M. Optimizing programs for given hardware architectures with static compilation: methods and tools. Trudy ISP RAN/Proc. ISP RAS, vol. 26, issue 1, 2014, pp. 343-356 (in Russian). DOI: 10.15514/ISPRAS-2014-26(1)-13.
8. Иванников В., Курмангалеев Ш., Белеванцев А., Нурмухаметов А., Савченко В., Матевосян Р., Аветисян А. Реализация запутывающих преобразований в компиляторной инфраструктуре LLVM. Труды ИСП РАН, том 26, вып. 1, 2014 г., стр. 327-342. DOI: 10.15514/ISPRAS-2014-26(1)-12./ Ivannikov V., Kurmangaleev S., Belevantsev A., Nurmukhametov A., Savchenko V., Matevosyan H., Avetisyan A. Implementing Obfuscating Transformations in the LLVM Compiler Infrastructure. Trudy ISP RAN/Proc. ISP RAS, vol. 26, issue 1, 2014, pp. 327-342 (in Russian). DOI: 10.15514/ISPRAS-2014-26(1)-12.
9. Гайсарян С.С., Курмангалеев Ш.Ф., Долгорукова К.Ю., Савченко В.В., Саргсян С.С. Применение метода двухфазной компиляции на основе LLVM для распространения приложений с использованием облачного хранилища. Труды ИСП РАН, том 26, вып. 1, 2014 г., стр. 315-326. DOI: 10.15514/ISPRAS-2014-26(1)-11./ Gaissaryan S., Kurmangaleev S., Dolgorukova K., Savchenko V., Sargsyan S. Applying two-stage LLVM-based compilation approach to application deployment via cloud storage. Trudy ISP RAN/Proc. ISP RAS, vol. 26, issue 1, 2014, pp. 315-326 (in Russian). DOI: 10.15514/ISPRAS-2014-26(1)-11.
10. Wang X., Chen H. et al. Undefined behavior: what happened to my code? In Proc. of the Asia-Pacific Workshop on Systems, 2012, pp. 1-7.
11. Баев Р.В., Скворцов Л.В., Кудряшов Е.А., Бучацкий Р.А., Жуйков Р.А. Предотвращение уязвимостей, возникающих в результате оптимизации кода с неопределенным поведением. Труды ИСП РАН, том 33, вып. 4, 2021 г., стр. 195-210. DOI: 10.15514/ISPRAS–2021–33(4)–14./ Baev R.V., Skvortsov L.V., Kudryashov E.A., Buchatskiy R.A., Zhuykov R.A. Prevention of vulnerabilities arising from optimization of code with Undefined Behavior. Trudy ISP RAN/Proc. ISP RAS, vol. 33, issue 4, 2021. pp. 195-210 (in Russian). DOI: 10.15514/ISPRAS–2021–33(4)–14.
12. Безопасный компилятор SAFEC. Доступно по ссылке: https://www.ispras.ru/technologies/safecomp/, доступ осуществлён 24.04.2024.
13. Clang: Language Compatibility, Available at: https://clang.llvm.org/compatibility.html, accessed 24.04.2024.
14. ГОСТ Р 71206-2024 «Защита информации. Разработка безопасного программного обеспечения. Безопасный компилятор языков C/C++. Общие требования». М., Российский институт стандартизации, 2024, 20 с.
15. UndefinedBehaviourSanitizer, Available at: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html, accessed 24.04.2024.
16. TableGen Overview, Available at: https://llvm.org/docs/TableGen/, accessed 24.04.2024.
17. IEEE 754-2019, Standard for Floating-Point Arithmetic, 2019. pp. 1-84. DOI: 10.1109/IEEESTD.2019.8766229.
18. Missing pointer overflow detection with -fsanitize=pointer-overflow, Available at: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82079, accessed 24.04.2024.
19. Alpine Linux, Available at: https://www.alpinelinux.org/, accessed 24.04.2024.
Review
For citations:
DUNAEV P.D., SINKEVICH A.A., GRANAT A.M., BATRAEVA I.A., MIRONOV S.V., SHUGALEY N.Yu. Developing a Clang-Based Safe Compiler. Proceedings of the Institute for System Programming of the RAS (Proceedings of ISP RAS). 2024;36(4):27-40. (In Russ.) https://doi.org/10.15514/ISPRAS-2024-36(4)-3