语义具体化:如何生成不包含未定义行为(UB)的任意控制流代码?
Semantic reification: how to generate UB-free code with arbitrary control flow?

原始链接: https://github.com/connglli/Reify

**Reify** 是一个基于语义具体化(semantic reification)的随机程序生成器,旨在生成不包含未定义行为(UB)的 C 程序。通过确保执行过程不触发 UB,Reify 为测试编译器提供了一个强大的框架,目前已在 GCC 和 LLVM 中发现了 59 个漏洞。 该工具支持生成单个“叶”函数以及复杂的多函数程序。它通过 *symlang* SymIR 对更多类型、指针/向量运算提供了实验性支持,并支持生成 Java (JVM) 和 eBPF 字节码。这些早期的实验性工作已在 OpenJ9 和 Linux eBPF 运行时中发现了漏洞。 Reify 提供了一个用于模糊测试(fuzzing)的模块化命令行界面,用户可以轻松生成制品、对编译器进行压力测试并执行跨平台测试。目前,该工具正在扩展中,以增强类型支持并提升测试能力。 对于有兴趣进行研究或集成的用户,Reify 采用 MIT 许可证开源,并在 PLDI '26 会议上发表(Chopra 等人)。

```Hacker News新帖 | 过往 | 评论 | 提问 | 展示 | 招聘 | 投稿登录语义具体化:如何生成具有任意控制流且无未定义行为(UB)的代码?(github.com/connglli)3 分 由 zsu 1 小时前发布 | 隐藏 | 过往 | 收藏 | 1 条评论 帮助 zsu 1 小时前 [–] - PLDI'26 论文:https://connglli.github.io/pdfs/reify_pldi26.pdf- 衍生项目 symlang:https://github.com/connglli/symlang回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索: ```
相关文章

原文

Reify is a random program generator based on semantic reification. It generates C functions and programs free of undefined behaviors (UBs), making it suitable for testing C compilers and, potentially, other language virtual machines. Using Reify, 59 bugs have been discovered and reported in GCC and LLVM.

Currently, Reify supports only i32, i32 arrays, and i32 structs. We are extending it to support additional primitive and aggregate types. We are also experimenting with generating Java bytecode and eBPF bytecode. Even in their early stages, these experimental attempts have already revealed one JIT compiler bug in OpenJ9 and two bugs in Linux's eBPF runtime.

Additionally, we are experiment with a full-fledged SymIR called symlang, based on which Reify has a re-implementation with richer feature support such as pointers, vectors, and intrinsics.

Prerequisites:

Start fuzzing C compilers:

make -j8 all
python scripts/fuzz.py -j 8 'gcc -O3 -fno-tree-slsr -fno-tree-ch'

Reify is capable of generating leaf functions that does not call other functions and whole programs composed of multiple functions.

Use the following script to generate 512 leaf functions:

python scripts/rysmith.py --output generated --limit 512

The script rotates through the recommended function-generation configurations (number of basic blocks per function, etc.) so that the 512 functions expose various shapes.

The output directory (given by the --output option) includes multiple sub-directories, each for an individual function:

  • func_<uuid>_<sno>: Contains all artifacts for an individual leaf function, including:
    • func.c: Generated function in C (not compilable alone).
    • inout.jsonl: Input-output mappings ensuring UB-free execution.
    • func.sexp: S-expression of the generated function.
    • main.c: A driver program to test the function (compilable with func.c).
    • func.log: Generation logs.

Or use the following command to generate an individual leaf function:

timeout 3s ./build/bin/rysmith -A -U -m -S --output generated --Xbitwuzla-threads 4 --sno 0 $(uuidgen)

Note that generating leaf functions may (1) take a long time due to complicated constraints or (2) fail due to unsatisfiable constraints. This is why the above command is prefixed with timeout 3s.

Experimental: Leaf functions can be generated from existing control flow graphs (CFGs). This feature is experimental.

First install Clang:

Then extract 512 CFGs from other programs such as those generated by Csmith or YARPGen:

python scripts/ggen.py -l /path/to/clang -L 512 -g csmith --csmith /path/to/csmith /path/to/csmith_db.jsonl

Finally integrate the generated CFG database into leaf function generation:

python scripts/rysmith.py ... --extra '--unstable-graphdb /path/to/csmith_db.jsonl' ...

Use the following script to generate 512 whole programs from a set of previously generated leaf functions (in particular, their S expressions, given by the --input option):

python scripts/rylink.py --input generated --limit 512

The script rotates through the recommended program-generation configurations (number of functions per program) so that the 512 programs span a range of sizes.

The generated programs are placed alongside the input functions in --input. Each program has its own directory:

  • prog_<uuid>_<sno>: Contains all artifacts for a whole program, including:
    • main.c: The entry point.
    • chksum.c: Checksum utilities.
    • proto.h: Prototypes of used leaf functions.
    • func_*.c: Individual function files.

Or use the following command to generate programs in a single invocation:

./build/bin/rylink --input generated --limit 512 --Xfunction-depth 10 $(uuidgen)

GCC and Clang/LLVM can be tested with one command with scripts/fuzz.py. Start fuzzing with:

python scripts/fuzz.py -o fuzzdir -j 10 -s 0 'gcc -O3 -fno-tree-slsr -fno-tree-ch'
  • -o fuzzdir: Output directory
  • -j 10: Run 10 jobs in parallel
  • -s 0: Seed for random number generator

Experimental: Fuzzing JVM

Use the following command to fuzz a Java virtual machine:

./scripts/fuzz_jvm.sh --nproc 8 --java-home /path/to/java/home

This process adapted leaf function generation to generate Java bytecode. An individual Java class can also be generated via --unstable-javaclass into build/bin/rysmith:

timeout 3s ./build/bin/rysmith ... --unstable-javaclass ...

The generated Java class is placed inside the javaclasses subdirectory.

Navigate to bugs.

If you found this work helpful, please consider citing our work:

@inproceedings{reify,
  title={Semantic Reification: A New Paradigm for Random Program Generation},
  author={Kavya Chopra and Cong Li and Thodoris Sotiropoulos and Zhendong Su},
  year={2026},
  booktitle={Proceedings of the 2026 ACM SIGPLAN Conference on Programming Language Design and Implementation},
  series={PLDI '26},
  doi={10.1145/3808268},
}
MIT License

Copyright (c) 2025

Kavya Chopra ([email protected])
Cong Li ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
联系我们 contact @ memedata.com