AMAZINGINDEX.COM 日报快照
52.8
VOL. 2026.08
2026.08.16
← 返回 2026.08.16 日报
日报快照 · Daily Snapshot
NO. 010

GCC 16 宽指针替代栈上跳板

#ARTICLE HackerNews 2026.08.16
推荐指数 53.0 NO. 010 · 2026.08.16
发布2026/08/15Score69Comments35

GCC 16 正式支持用宽指针替代嵌套函数的栈上跳板(trampoline),彻底消除可执行栈的安全隐患。对需要高安全性 C/C++ 编译环境的 AI 基础设施团队是刚需升级。

嵌套函数跳板问题在嵌入式和系统编程中潜伏多年,Rust 和 Go 等现代语言通过闭包设计完全规避了这个问题,但 C 生态的存量代码无法迁移。GCC 此前的堆分配方案只是权宜之计,longjmp 时的内存泄漏在实时系统中是致命缺陷。

宽指针方案本质上是用 fat pointer 携带静态链信息,运行时开销接近零,但需要 ABI 变更,这意味着与旧版 GCC 编译的库不兼容。做 AI 推理框架底层优化的团队如果依赖自定义算子的嵌套回调,升级 GCC 16 前需要评估链接边界。

安全审计趋严的背景下,可执行栈已经是 PCI-DSS 和 FedRAMP 的否决项,这个补丁的落地速度会比预期快。

意见分歧 32 条评论

核心争论:宽指针方案是否优于标签指针,以及C/C++语言设计中对嵌套函数的不同取舍

mananaysiempre

What about your older patch where -fno-trampolines meant a function pointer could either be a code pointer or a closure (descriptor) pointer, distinguished by a tag?

uecker

My old patch from 2018? This was not accepted to GCC because it relied on function pointers being aligned and there were concerns with this. But I prefer this approach anyhow, as it does not impose any run-time cost for checking the tag, and is easier to optimize.

tpoacher

What's a "trampoline"?

替代方案: 标签指针(tagged pointer)std::functionstd::function_refstatic函数C++ lambda模块系统
查看原文 →