Skip to content

Add --extern-globals: try a global's definition as extern and back - #5

Merged
MrSapps merged 1 commit into
claude/blissful-johnson-1w5a5vfrom
claude/extern-global
Oct 4, 2026
Merged

MrSapps merged 1 commit into
claude/blissful-johnson-1w5a5vfrom
claude/extern-global

Conversation

@MrSapps

@MrSapps MrSapps commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

VC6 can code a read of a global differently depending on whether the file defines it or only declares it extern. In gta2_re, a 2-byte global defined in the same file got 32-bit loads. The original's 16-bit loads came back once the definition moved to another file: Weapon_30::dual_pistol_5DDA70 matched, and four Wolfy_30 functions went from 181 and 226 diff lines to 32 and 20.

What --extern-globals does

  • New regions: each global the target function names becomes a region holding its declaration line in the source file. Region::alt holds the other form.
    • A definition, DEFINE_GLOBAL...(type, name, ...), can become EXTERN_GLOBAL(type, name);, or EXTERN_GLOBAL_ARRAY(type, name, size); for arrays.
    • An extern can become its definition, copied from another .cpp in the source's directory.
  • Other macros: --global-macros DEFINE=EXTERN names other macros with the same argument layout. The default is gta2_re's Function.hpp macros.
  • Search:
    • Exhaustive mode adds one candidate per global: that global's declaration switched (extern_global in the stats).
    • Random mode switches a random global in one mutation in eight; the rest go to the function regions as before.
  • Scoring: only the candidate's object is compiled, so a missing definition doesn't matter. A winning switch has to be applied by hand: move the definition to another .cpp, or into this one.

Tests

  • New integration case (extern_global, --dry-run): the definition gets an extern candidate, the extern gets the definition from other.cpp, and a global the function doesn't read isn't offered. clang codes both forms the same, so the case checks the candidates, not a match.
  • Unit and integration suites: they pass under ctest.
  • With VC6 on gta2_re:
    • Setup: word_706D5E's definition was put back into Weapon_30.cpp, so dual_pistol_5DDA70 scored 245.
    • Run: -m exhaustive -p incdec --extern-globals.
    • Result: it found the match (score 0) at candidate 6: +EXTERN_GLOBAL(Ang16, word_706D5E);.

🤖 Generated with Claude Code

Each global the target function names gets a region holding its
declaration line in the source file: a DEFINE_GLOBAL... definition can
become its EXTERN_GLOBAL declaration, and an extern can become its
definition, copied from another .cpp in the same directory. VC6 can code
a read of a global defined in the same file differently (gta2_re: 32-bit
loads of a 2-byte global). Exhaustive mode tries each switch, random mode
switches a global in one mutation in eight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MrSapps
MrSapps merged commit 7ff2fd1 into claude/blissful-johnson-1w5a5v Oct 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants