arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.10422cs.SE
收藏

面向可移植性的宏使用语义分析

Semantic Analysis of Macro Usage for Portability

Brent Pappas, Paul Gazzillo

AI总结:

针对C代码移植中宏抽象易丢失的问题,提出含26项属性的宏可移植性分析框架及工具Maki,并在大规模真实程序中验证其能有效识别和指导宏移植。

摘要:

C是一种不安全的语言。研究人员一直在开发将C移植到Rust、Checked C或Go等更安全语言的工具。然而,现有工具会先对源文件进行预处理,然后再移植所得代码,这导致代码几乎难以辨认,并丢失了宏抽象。为保留宏的使用方式,移植工具需要通过理解宏行为的分析,将其移植为等价结构。但宏的语义不同于普通函数,因此无法通过简单的语法转换完成移植。我们提出首个用于分析宏使用可移植性的综合框架。该框架将宏行为分解为26个细粒度属性,并实现了名为Maki的程序分析工具,可在真实代码中识别这些属性,准确率达94%。我们将Maki应用于21个程序,这些程序共包含86,199个宏定义。结果发现,真实世界中的宏比此前已知的更容易移植:超过三分之一(37%)属于易于移植的宏,且Maki可为移植更复杂的宏提供提示。与先前工作相比,我们平均发现2倍数量的易于移植宏,最佳情况下最多可达7倍。在Maki输出的指导下,我们在四个真实世界程序中发现并手工移植了宏。我们向Linux维护者提交了转换11个宏的补丁,其中9个已被接受。

英文摘要:

C is an unsafe language. Researchers have been developing tools to port C to safer languages such as Rust, Checked C, or Go. Existing tools, however, resort to preprocessing the source file first, then porting the resulting code, leaving barely recognizable code that loses macro abstractions. To preserve macro usage, porting tools need analyses that understand macro behavior to port to equivalent constructs. But macro semantics differ from typical functions, precluding simple syntactic transformations to port them. We introduce the first comprehensive framework for analyzing the portability of macro usage. We decompose macro behavior into 26 fine-grained properties and implement a program analysis tool, called Maki, that identifies them in real-world code with 94% accuracy. We apply Maki to 21 programs containing a total of 86,199 macro definitions. We found that real-world macros are much more portable than previously known. More than a third (37%) are easy-to-port, and Maki provides hints for porting more complicated macros. We find, on average, 2x more easy-to-port macros and up to 7x more in the best case compared to prior work. Guided by Maki's output, we found and hand-ported macros in four real-world programs. We submitted patches to Linux maintainers that transform eleven macros, nine of which have been accepted.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑