arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2412.20258cs.SE
收藏

在 WebAssembly 中复用遗留代码:交叉编译与代码语义保持的关键挑战

Reusing Legacy Code in WebAssembly: Key Challenges of Cross-Compilation and Code Semantics Preservation

University of Southern California(南加州大学)

Sara Baradaran, Liyan Huang, Mukund Raghothaman, Weihang Wang

AI总结:

本文通过研究115个开源代码库,系统揭示了将遗留C/C++代码交叉编译为WebAssembly时面临的关键挑战,并开发WasmChecker差分测试框架验证语义等价性,发现Emscripten工具链中11个新缺陷。

摘要:

WebAssembly(Wasm)已成为一种强大的技术,用于在 Web 浏览器中执行高性能代码并复用遗留代码。随着其采用率不断提高,确保 WebAssembly 代码的可靠性变得至关重要。本文研究了 WebAssembly 编译器在多大程度上实现了代码可复用性。具体而言,我们探讨了两个问题:(1)将高级语言代码库交叉编译为 WebAssembly 时会遇到哪些挑战;(2)WebAssembly 编译器在这种新二进制格式中能在多大程度上忠实地保持代码语义。通过对 115 个开源代码库的研究,我们识别了将遗留 C/C++ 代码交叉编译为 WebAssembly 的关键挑战,并强调了静默错误编译和编译时错误的风险。我们根据这些挑战的根本原因对其进行了分类,并提出了相应的解决方案。随后,我们引入了一种差分测试方法,并在名为 WasmChecker 的框架中加以实现,以研究原生 x86-64 二进制与 WebAssembly 二进制之间代码的语义等价性。利用 WasmChecker,我们提供了证据表明,由于标准库的不同实现、不支持的系统调用/API、WebAssembly 的独特特性以及编译器缺陷,WebAssembly 编译器在将高级语言代码交叉编译为 WebAssembly 时并不一定保持代码语义。此外,我们在 Emscripten 编译器工具链中发现了 11 个新缺陷,这些缺陷均已得到 Emscripten 开发者的确认。作为概念验证,我们公开了所开发的框架和收集的开源代码库数据集。

英文摘要:

WebAssembly (Wasm) has emerged as a powerful technology for executing high-performance code and reusing legacy code in web browsers. With its increasing adoption, ensuring the reliability of WebAssembly code becomes paramount. In this paper, we investigate how well WebAssembly compilers fulfill code reusability. Specifically, we inquire (1) what challenges arise when cross-compiling a high-level language codebase into WebAssembly and (2) how faithfully WebAssembly compilers preserve code semantics in this new binary. Through a study on 115 open-source codebases, we identify the key challenges in cross-compiling legacy C/C++ code into WebAssembly, highlighting the risks of silent miscompilation and compile-time errors. We categorize these challenges based on their root causes and propose corresponding solutions. We then introduce a differential testing approach, implemented in a framework named WasmChecker, to investigate the semantics equivalency of code between native x86-64 and WebAssembly binaries. Using WasmChecker, we provide a witness that WebAssembly compilers do not necessarily preserve code semantics when cross-compiling high-level language code into WebAssembly due to different implementations of standard libraries, unsupported system calls/APIs, WebAssembly's unique features, and compiler bugs. Furthermore, we have identified 11 new bugs in the Emscripten compiler toolchain, all confirmed by Emscripten developers. As proof of concept, we make our framework and the collected dataset of open-source codebases publicly available.

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

↑