per-function-optimize-attribute-abi-mismatch

per-function-optimize-attribute-abi-mismatch is a skill for Claude Code, Codex from chen3feng/agent-skills. It costs 41 tokens per session (1,699 once invoked), scanned A, original, Apache-2.0.

A troubleshooting guide for a GCC compiler setting that lowers optimization for one C or C++ function. ABI means the rules callers and functions use to exchange arguments, returns, and stack data.

In plain words
What is it for?
Investigating miscompiles and crashes involving GCC's optimize attribute or optimization pragmas.
Why use it?
It explains why mixing per-function optimization settings can cause crashes or other calling-convention problems.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch
Any agent
npx skills add chen3feng/agent-skills --skill per-function-optimize-attribute-abi-mismatch
Clone the repo
git clone --depth 1 https://github.com/chen3feng/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for per-function-optimize-attribute-abi-mismatch

README.md
[![agentmods](https://agentmods.dev/badge/skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch.svg)](https://agentmods.dev/skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch)
Your own site
<a href="https://agentmods.dev/skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch"><img src="https://agentmods.dev/badge/skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch.svg" alt="Measured on agentmods" height="20"></a>
Per session 41 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,699 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00041 $0.01699
Opus 5 $0.00020 $0.00849
Sonnet 5 $0.00008 $0.00340
Haiku 4.5 $0.00004 $0.00170

Measured 6d ago against content hash 4abeb8b6573e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

per-function-optimize-attribute-abi-mismatch scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/per-function-optimize-attribute-abi-mismatch/SKILL.md · 170 lines

How it starts

The opening of the file, as written. The whole thing — 170 lines — stays where its author put it; the contents beside it link to each section on GitHub.

__attribute__((optimize("O0"))) silently breaks the ABI on GCC

When to use

You're trying to isolate a miscompile in a single helper function by forcing it to lower optimization, using one of these forms inside a translation unit that is otherwise built at -O2 or higher:

__attribute__((optimize("O0")))
static void Helper(uint8_t* Dst, const uint8_t* Src, int N) { ... }

or equivalently:

#pragma GCC push_options
#pragma GCC optimize("O0")
static void Helper(...) { ... }
#pragma GCC pop_options

and the program now crashes — usually SIGSEGV — on the first call into Helper, before any of its body runs, even though the same code worked at -O2.

Problem

GCC's per-function optimize attribute changes the optimization level of the callee, but it does not re-align the ABI between that callee and its -O2 caller. Concretely:

  • -O0 GCC emits a full stack frame with a frame pointer, spills all arguments to memory, and does not use the x86-64 SysV red zone.
  • -O2 GCC elides the frame pointer, keeps arguments in registers, and may use the red zone.
  • The caller, built at -O2, passes arguments and return address under -O2 assumptions. The callee reads them under -O0 assumptions. The mismatch shows up as reading 0 or garbage from a pointer argument, or a segfault on return (frame pointer mismatch).

Crucially, there is no compiler warning. The attribute silently produces a working-looking binary that crashes at runtime.

On Clang, __attribute__((optnone)) exists and is better-behaved about this, but it's also more restrictive (disables all opts, not just some) and is not a fix-by-dropping-level tool.

Solution

If you really need one function at a lower optimization level, pick one of these, in order of preference:

  1. Don't. If you reached for optimize("O0") to diagnose a miscompile, see stop-chasing-the-optimizer-reduce-instead — reduce the repro and fix the real bug (usually UB) instead.
  2. Isolate the function in its own TU, compiled at -O1. Move Helper into helper.cpp and add a per-file flag in the build system:

Read the full file on GitHub · 170 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 170 lines · 0 tokens per session scan A 4abeb8b6573e

Subscribe to this mod's changes

per-function-optimize-attribute-abi-mismatch is a skill published in the GitHub repository chen3feng/agent-skills (5 stars, last pushed 4mo ago), licensed Apache-2.0. It adds 41 tokens to every session and 1,699 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

cpp-pro

Writes, optimizes, and debugs C++ applications using modern C++20/23 features, template metaprogramming, and high-performance systems techniques. Use when building or refactoring C++ code requiring concepts, ranges, coroutines, SIMD optimization, or careful memory management — or when addressing performance…

Jeffallan/claude-skills · 79 tokens

memory-safety-patterns

Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs.

rmyndharis/antigravity-skills · 45 tokens

cpp

Comprehensive C/C++ programming reference covering everything from C11-C23 and C++11-C++23, system programming, CUDA GPU computing, debugging tools, Rust interop, and advanced topics. Use for: C/C++ questions, C/C++ interview preparation, modern language features, RAII/memory management, templates/generics, CUDA…

crazyguitar/cppcheatsheet · 0 tokens

fix-cppheaders

Use when hl2sdkcs2 C++ headers must be repaired to match the latest vtable or record-layout YAML references. Runs runcpptests.py to obtain layout diffs, maps failing cpptests entries to their configured headers, edits only those headers, and repeats validation until the differences are resolved. Triggers: fix cpp…

HLND2T/CS2_VibeSignatures · 91 tokens

cuda-c-optimization

CUDA C 性能优化、数值稳定性和调试排查.

mindspore-ai/akg · 20 tokens

cpp-debugging

Use when a C++ failure involves memory lifetime, undefined behavior, native crashes, or debugger-only state — debug with symbols, sanitizers, and platform-native debuggers before patching symptoms.

drvoss/everything-copilot-cli · 42 tokens