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.

Good fit Investigating miscompiles and crashes involving GCC's optimize attribute or optimization pragmas.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/chen3feng/agent-skills/per-function-optimize-attribute-abi-mismatch
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.

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/github.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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for per-function-optimize-attribute-abi-mismatch

Your own site · 80×15
<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="Reviewed on agentmods" width="80" 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. A grade says what 26 rules found in the file — not that it is safe.
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.5 $0.00016 $0.00680
Sonnet 5.5 $0.00008 $0.00340
Haiku 4.5 $0.00004 $0.00170

Measured 3mo ago against content hash 4abeb8b6573e, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 3mo 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. 3mo 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 6mo 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.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

per-function-optimize-attribute-abi-mismatch compared with skills from other repositories

per-function-optimize-attribute-abi-mismatch next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
per-function-optimize-attribute-abi-mismatchchen3feng/agent-skillsSkill56mo agoApache-2.0A41Claude Code, Codex
cpp-proJeffallan/claude-skillsSkill13ktodayMITA79Claude Code
memory-safety-patternsrmyndharis/antigravity-skillsSkill2.1k23d agoMITA45Claude Code, Codex
memory-modelmohitmishra786/low-level-dev-skillsSkill30410d agoMITA113Claude Code, Codex
gccmohitmishra786/low-level-dev-skillsSkill30410d agoMITA85Claude Code, Codex
cuda-c-optimizationmindspore-ai/akgSkill269yesterdayApache-2.0A20Claude Code, Codex
cppcrazyguitar/cppcheatsheetSkill2976d agoMITA0Claude Code