Skip to content

fix(ghidra): clear wrong no-return flags before serving a session - #1419

Merged
morluto merged 4 commits into
morluto:mainfrom
JonahSimon:fix/ghidra-wrong-noreturn-flags
Oct 10, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
JonahSimon:fix/ghidra-wrong-noreturn-flags

Conversation

@JonahSimon

@JonahSimon JonahSimon commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Ghidra's default auto-analysis can flag ordinary functions as no-return. In libpl2.so (Android x86 ELF, Ghidra 12.1.2) it flagged about 63 functions that all contain a real RET (stream readers, __cxa_guard_acquire, __release_weak). Every caller then treats the call as a terminator, so procedure_pseudo_code returns a body that stops at the first such call, often a thunk plus "Subroutine does not return". About 7,900 functions at 38,900 call sites were truncated.

Change

A new postScript, ReaGhidraNoReturnFix.java, runs before the bridge script:

  1. Clear the no-return flag on functions that contain a real RET (terminal, non-jump, non-call).
  2. Re-disassemble call sites that are still CALL_TERMINATOR but whose callee is no longer no-return.
  3. Rebuild the owning functions.

It does nothing when no function is wrongly flagged. It only edits the ephemeral analysis database, so executable bytes and the read-only import are unchanged.

Verification

  • tests/boundary/providers/ghidra/ghidraLauncher.test.ts updated (fix script ordered before the bridge); focused run passes.
  • Real provider: libpl2.so, decompile of the ZoneCompleteMessage deserializer before the change ended after the first stream-reader call. After the change it shows the full body (stat table loop and the 0x4c-byte reward loop). Other binaries and Windows were not tested.
  • The script is also packaged (package.json#files) and listed in the Windows packaged-script collision check.

Caveat: the scan covers all functions, and the re-disassembly runs only when wrong flags exist. I did not time the added cost.

🤖 Generated with Claude Code

Auto-analysis can flag ordinary functions as no-return (stream readers,
__cxa_guard_acquire, ...). Their callers then end at the call and the
decompiler truncates them. Run a postScript before the bridge that clears the
flag on functions containing a real RET and re-disassembles the call sites that
were terminators.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on a small test program. The code after the bad call comes back. But it has two side effects. The functions it rebuilds lose their debug types. And calls that truly end a function now run on into the next one. On a copy of ls it did nothing, which is right. It cost about 10 ms there.

What I tried

I ran REA with real Ghidra on Linux, on a small C file. Its report_error(status, msg) returns on 0 and exits otherwise. Four callers pass a non-zero status, then __builtin_unreachable(). gnulib's error.in.h does the same with gl_unreachable(). One caller, warn_then_work, passes 0 and goes on. At -O2, Ghidra flags report_error as no-return, though it has a real ret.

Results (noret.c, clang -O2)

Check Base Head
report_error no-return yes (wrong) no
warn_then_work body 15 bytes, ends at call 47 bytes, full
warn_then_work callees report_error report_error, puts
warn_then_work pseudocode "Subroutine does not return" full body
fail_a pseudocode ends at report_error(2, …) runs on into fail_b … uses_wrap_exit
wrap_exit, wrap_abort no-return yes yes
-g build: warn_then_work type int warn_then_work(int x) undefined warn_then_work()

The -O0 build had no wrong flags. Nor did a copy of /usr/bin/ls. On both, the fix cleared nothing. The base and head flag dumps match line for line.

Changed test 22.23.1 24.18.0 26.11.1
ghidraLauncher.test.ts, head 7 pass, 1 skip 7 pass, 1 skip 7 pass, 1 skip

The skip is the Windows-only case. Head's test on base fails 1 of 8, on the script order (Node 24 only).

npm run verify:ghidra on head passed. It said ok: true and cleanup: complete. It took 344 s.

Things to look at

  1. Types are lost. removeFunction then createFunction(e, null) keeps the name. But it drops the DWARF signature and calling convention. fail_a to fail_d lose theirs too. In a scratch copy, I swapped those two lines for CreateFunctionCmd.fixupFunctionBody(currentProgram, f, monitor). warn_then_work still got its full body. All 19 named types matched base. I did not check if it helps point 2.
  2. Real end calls now run on. In fail_a, the call is the last code before padding. Ghidra had put a CALL_RETURN flow override on it. The fix clears it and disassembles again. So the decompiler falls through into fail_b. Code built on gnulib's error() may hit this. One idea: skip a site when the bytes after it are padding or a function start.
  3. The site scan is wide. It found 16 sites for 5 calls. PLT stubs (puts, printf, fprintf, fwrite) count too. So does the frame_dummy tail jump. Those get rebuilt and lose the override. main decompiles the same, so I saw no harm from it.
  4. Restored code has no refs. The string "code after the warning" shows in the head pseudocode. It is missing from referenced_strings and outgoing_references. Analysis does not run on the new code.
  5. Quiet when idle. The println only runs when it clears a flag. On ls the log shows nothing. So you can't tell it ran.
  6. The test checks order only. Nothing runs the Java. My repro runs in about 8 s through REA, if a fixture would help.

Not run

Edit: results are in the follow-up. Six lanes ran on base and head, the suite passes, and the fix cleared nothing on the verifier's fixtures. Still not run: Windows, Android, libpl2.so and the four lanes that need macOS, Windows or extra files.

  • Windows, Android, and libpl2.so. I don't have them.
  • verify:ghidra on base, and the other verify:ghidra:* lanes. Six ran. Four need macOS, Windows or extra files.
  • The full test suite. Only the changed test ran. Head only, on Node 24.
  • rea decompile of main in ls fails on base and head alike. Ghidra says "Unable to find unique hash for varnode". It is not from this PR.
  • I don't know if the fix did anything on the verifier's own fixtures. It logs nothing when idle. The new log line says cleared=0 in every lane session.
  • The PR links no issue, so there was none to read.

Thanks, JonahSimon, for a clear write-up and a fix that is easy to test.

Timing

I put System.nanoTime() stamps around the script. Ghidra had already built the bridge folder by then. The fix added about 10 ms on ls. It added about 20 ms on the repro. A full rea analyze on ls took 14.27 s on base and 14.41 s on head. That is one run each, so it is within noise.

Commands
git -C rea.git fetch origin pull/1419/head
git -C rea.git archive c3e1db89 | tar -x -C head
git -C rea.git archive 8550913c | tar -x -C base
npm ci && npm run build            # Node 24.18.0, each tree
npx vitest run tests/boundary/providers/ghidra/ghidraLauncher.test.ts

clang -O2 noret.c -o noret-O2
clang -O2 -g noret.c -o noret-O2g
clang -O0 noret.c -o noret-O0
cp /usr/bin/ls ls

# Flag dump: base = DumpNoReturn only, head = fix, then DumpNoReturn
analyzeHeadless proj p -import noret-O2 -readOnly -deleteProject \
  -scriptPath "head/bridge/ghidra;scripts" \
  -postScript ReaGhidraNoReturnFix.java -postScript DumpNoReturn.java

# REA CLI, from each tree
node scripts/rea.mjs decompile noret-O2 warn_then_work --provider ghidra --format json
node scripts/rea.mjs function noret-O2 warn_then_work --provider ghidra --format json
node scripts/rea.mjs decompile noret-O2 fail_a --provider ghidra --format json
node scripts/rea.mjs function noret-O2g warn_then_work --provider ghidra --format json
node scripts/rea.mjs analyze ls --provider ghidra --format json

npm run verify:ghidra              # head only
Repro C file
#include <stdio.h>
#include <stdlib.h>

#define NOINLINE __attribute__((noinline))

volatile int sink;

NOINLINE void report_error(int status, const char *msg) {
  fprintf(stderr, "error: %s\n", msg);
  if (status != 0)
    exit(status);
}

NOINLINE void wrap_exit(int code) {
  fprintf(stderr, "bye %d\n", code);
  exit(code);
}

NOINLINE void wrap_abort(void) {
  fputs("abort\n", stderr);
  abort();
}

NOINLINE void maybe_exit(int code) {
  if (code > 100)
    exit(code);
  sink = code;
}

NOINLINE int fail_a(int x) {
  if (x > 3) {
    report_error(2, "a");
    __builtin_unreachable();
  }
  return x + 1;
}

NOINLINE int fail_b(int x) {
  if (x > 4) {
    report_error(3, "b");
    __builtin_unreachable();
  }
  return x + 2;
}

NOINLINE int fail_c(int x) {
  if (x > 5) {
    report_error(4, "c");
    __builtin_unreachable();
  }
  return x + 3;
}

NOINLINE int fail_d(int x) {
  if (x > 6) {
    report_error(5, "d");
    __builtin_unreachable();
  }
  return x + 4;
}

NOINLINE int warn_then_work(int x) {
  report_error(0, "just a warning");
  sink = x * 7;
  puts("code after the warning");
  return x + 42;
}

NOINLINE int uses_wrap_exit(int x) {
  if (x > 1000)
    wrap_exit(9);
  return x - 1;
}

NOINLINE int uses_maybe_exit(int x) {
  maybe_exit(x);
  puts("after maybe_exit");
  return x * 2;
}

int main(int argc, char **argv) {
  (void)argv;
  int r = warn_then_work(argc);
  r += fail_a(argc) + fail_b(argc) + fail_c(argc) + fail_d(argc);
  r += uses_wrap_exit(argc) + uses_maybe_exit(argc);
  if (argc > 50)
    wrap_abort();
  printf("%d\n", r);
  return 0;
}
Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

Keep function types by refitting the owning functions with fixupFunctionBody
instead of removing and recreating them. Only redo call sites whose callee was
actually cleared (including thunks to it), skip sites followed by a function
start or x86 padding so real end calls do not run on, and always log the result.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@JonahSimon

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, CassieFox23. Pushed 7b5e36c.

Addressed:

  1. Types lost. The owning functions are now refit with CreateFunctionCmd.fixupFunctionBody instead of remove and create, as you suggested. I could not check the DWARF case myself (see below).
  2. Real end calls running on. A site is skipped when the next address is a function entry or, on x86, a padding byte (0xcc, 0x90, 0x00).
  3. Wide site scan. Only call sites whose callee was actually cleared are redone, plus thunks that forward to a cleared function (their flag is cleared too). PLT stubs and unrelated calls are no longer touched.
  4. Quiet when idle. It always logs cleared / sites / refit.

Not changed:
4. No references for restored code. I tried analyzeChanges(currentProgram) after the refit. On libpl2.so (Android x86, 63 wrong flags, 19,370 call sites, 8,172 functions refit) the script goes from about 12 s to about 79 s, and the whole session then misses REA's 330 s startup deadline (analysis itself is about 260 s). So I left it out and noted why in a comment. If you know a cheaper way to analyze only the touched ranges, I will take it.

Verification: libpl2.so through the REA CLI, decompile of a deserializer that was cut after its first stream-reader call before the change; it now shows the full body. Launcher test passes (7 passed, 1 skipped).

Not verified: I could not reproduce your noret.c case. My clang -O2 does not flag report_error as no-return, so the script clears nothing there (it logs cleared=0). If you can share the exact build line and compiler version, or a small fixture, I will run the type and fall-through checks against it.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The new push fixes three of my points. Types stay now. The scan is small. The log always prints. But the real end calls still run on. Clang pads with long NOPs, not 0x90. And the skip also hides some real code. Your build may have put ud2 after each call. Then Ghidra had nothing to go on. A fixture is below. A scoped pass works too, and I timed it.

Your two questions

1. The fixture. I built on Linux x86-64 with clang 22.1.8:

clang -O2 noret_min.c -o noret_min

The analyzer that flags report_error is Non-Returning Functions - Discovered. It counts calls followed by the next function. NOP padding between does not stop the count. Three such calls hit the default threshold of 3. It is not DWARF or an attribute. I checked this two ways. With that analyzer off, the log says cleared=0. With the threshold at 4, it says cleared=0 too.

On macOS, clang puts ud2 right after each call. On Windows it puts int3. On Linux it puts nothing. I checked that with clang -S for each target. I did not run Ghidra on Mach-O or PE files. On Linux, I forced the same trap with -mllvm -trap-unreachable. Then the log says cleared=0. So your build may be the macOS kind. I don't know your setup, so that part is a guess. Ghidra does count int3 as evidence. So a Windows build should still flag it. I did not run that.

To rule out the compiler, I also made pad.s. It is hand-written assembly with no libc. Its bytes stay the same on any host.

Fixture c3e1db89 7b5e36c0
noret_min cleared=1 sites=10 rebuilt=7 cleared=1 sites=4 refit=4
pad cleared=1 sites=14 rebuilt=14 cleared=1 sites=5 refit=5

cleared=1 is the part that matters. Your site counts may differ.

2. A cheaper scoped pass (tested, direct Ghidra only). I skip the queue. I keep the set each DisassembleCommand makes. Then I call added() on two analyzers over just that set. They are Reference and x86 Constant Reference Analyzer. The code is in a fold below.

I also tried your analyzeChanges(currentProgram) step. It does more than cost time. It runs that same no-return analyzer again. That took 1.77 s of the 3.3 s. It flags every cleared function again and cuts the callers back.

Run Fix time Flags left Callers with string ref
7b5e36c0 as is 1.35 s 0 / 60 0 / 6000
+ analyzeChanges 4.72 s 60 / 60 0 / 6000
+ scoped pass 3.22 s 0 / 60 6000 / 6000

That table is a made-up 1 MB binary. It has 60 wrong flags and 6,240 sites. The scoped step took 1.64 s of that. On noret-O2 it took 3 ms. Then "code after the warning" gets its ref back. I could not test libpl2.so, so I can't say what it costs there.

Retest at 7b5e36c0

My earlier point Now
1. Types lost on rebuild Fixed. All -g types match base.
2. Real end calls run on Not fixed on my build. See below.
3. Scan too wide Fixed. 16 sites went to 5 on noret-O2.
4. No refs for restored code Same. The string ref is still missing.
5. Quiet when idle Fixed. -O0 logs cleared=0 sites=0 refit=0.
6. Test checks order only Same. The test file did not change.

The launcher test passes on Node 22.23.1, 24.18.0 and 26.11.1. It shows 7 passed and 1 skipped each time. Through the REA CLI, the script log says cleared=1 sites=5 refit=5. The warn_then_work pseudocode is full. referenced_strings still lacks "code after the warning".

The padding skip

Point 2 is still there because of the bytes. Clang pads with long NOPs like 66 0f 1f 44 00 00. Those don't start with 0xcc, 0x90 or 0x00. So fail_a still runs on through four more functions.

The skip also hides some real code. Code that starts with 00 03, 90 or cc now stays cut, with no warning. Data after a call and a call at the end of .text both end in halt_baddata. The byte table is in the fold.

One idea, not tested: step over the NOPs the way the analyzer does. Ghidra's FindNoReturnFunctionsAnalyzer.skipNOPS already does this. Then skip when you land on a function entry or unmapped memory.

Not run

Edit: results are in the follow-up. Still not run: Mach-O, PE, libpl2.so, Android and analyzeChanges before the refit.

  • Ghidra on Mach-O or PE files. I only checked what clang emits there.
  • libpl2.so, Android, and the verify:ghidra lanes. Six lanes ran on Linux. Four need macOS, Windows or extra files.
  • The scoped pass through the REA CLI. I ran it in analyzeHeadless only. Ran by swapping the script file in a scratch copy.
  • Running analyzeChanges before the refit. That is just an idea.
  • Callees that live in another library, like glibc's error(). The fix only clears functions with a body.
  • The full test suite. Head only, on Node 24.

Thanks, JonahSimon, for the quick turn and the clear notes.

Padding skip, byte by byte

Point 2 is still there because of the bytes. After fail_a's call come 66 0f 1f 44 00 00. After fail_b come 0f 1f 44 00 00. Both are NOPs. Neither starts with 0xcc, 0x90 or 0x00. So fail_a still runs on through four more functions.

pad.s puts known bytes after each call. Here is what 7b5e36c0 does.

After the call Call really ends? Result
next function, 90, cc cc, 00 00 yes skipped, good
0f 1f 40 00 or 66 2e 0f 1f … yes runs on into next functions
data bytes (.quad) yes runs into data, halt_baddata
mov eax, 3 or 0f 1f 40 00 then code no fixed, good
00 03 (add byte ptr [rbx], al) no skipped, still cut
90 then code no skipped, still cut
cc (int3) then code no skipped, still cut

The last three are now cut without a warning. The pseudocode shows report_error(0); return;.

Three more things came up:

  • Calls at the end of a section. In noret_min, fail_c's call is the last byte of .text. The next address is not mapped. getByte throws, so isX86Padding says no. The site is redone. fail_c then decompiles to halt_baddata.
  • Compiler flags. Most of my builds still run on. That covers clang -O1, -O2, -O3, -fPIE -pie, -fcf-protection=full, -falign-functions=32 and lld. It covers gcc -O2 too. Clang -Os and -Oz put no padding there. They come out right, apart from the section case.
  • aarch64. The padding check is x86 only. At the default 4-byte alignment, functions touch, so it works. With -falign-functions=16, fail_a runs on.

A PseudoDisassembler could decode the NOPs without touching the listing. That might also let you drop the 0x00 and 0x90 byte checks.

Fixture: noret_min.c
#include <stdio.h>
#include <stdlib.h>

#define NOINLINE __attribute__((noinline))

volatile int sink;

/* Returns when status is 0, exits otherwise. Not a no-return function. */
NOINLINE void report_error(int status, const char *msg) {
  fprintf(stderr, "error: %s\n", msg);
  if (status != 0)
    exit(status);
}

/* Three callers end in the call, so Ghidra sees code for the next
   function right after each one. Three is Ghidra's default threshold. */
NOINLINE int fail_a(int x) {
  if (x > 3) {
    report_error(2, "a");
    __builtin_unreachable();
  }
  return x + 1;
}

NOINLINE int fail_b(int x) {
  if (x > 4) {
    report_error(3, "b");
    __builtin_unreachable();
  }
  return x + 2;
}

NOINLINE int fail_c(int x) {
  if (x > 5) {
    report_error(4, "c");
    __builtin_unreachable();
  }
  return x + 3;
}

/* The victim: the call returns here, so the code after it is real. */
NOINLINE int warn_then_work(int x) {
  report_error(0, "just a warning");
  sink = x * 7;
  puts("code after the warning");
  return x + 42;
}

int main(int argc, char **argv) {
  (void)argv;
  return warn_then_work(argc) + fail_a(argc) + fail_b(argc) + fail_c(argc);
}
$ objdump -d -M intel noret_min   (fail_a)
  400545: e8 56 fe ff ff        call   4003a0 <report_error>
  40054a: 66 0f 1f 44 00 00     nop    WORD PTR [rax+rax*1+0x0]
0000000000400550 <fail_b>:
Fixture: pad.s (no libc, same bytes on any host)
clang --target=x86_64-linux-gnu -c pad.s -o pad.o
ld.lld -static -o pad pad.o
        .intel_syntax noprefix
        .text
        .globl report_error
        .type report_error,@function
report_error:
        test edi, edi
        jne 1f
        ret
1:      mov eax, 60
        syscall
        ud2
        .size report_error, .-report_error

# ev1..ev3: real end calls, next function right after (Ghidra's evidence)
        .globl ev1
        .type ev1,@function
ev1:    push rax
        mov edi, 1
        call report_error
        .size ev1, .-ev1
        .globl ev2
        .type ev2,@function
ev2:    push rax
        mov edi, 2
        call report_error
        .size ev2, .-ev2
        .globl ev3
        .type ev3,@function
ev3:    push rax
        mov edi, 3
        call report_error
        .size ev3, .-ev3

# t_*: real end calls, then filler, then the next function
        .globl t_nop90
        .type t_nop90,@function
t_nop90: push rax
        mov edi, 4
        call report_error
        .byte 0x90
        .size t_nop90, .-t_nop90
        .globl t_int3
        .type t_int3,@function
t_int3: push rax
        mov edi, 5
        call report_error
        .byte 0xcc, 0xcc
        .size t_int3, .-t_int3
        .globl t_nop4
        .type t_nop4,@function
t_nop4: push rax
        mov edi, 6
        call report_error
        .byte 0x0f, 0x1f, 0x40, 0x00
        .size t_nop4, .-t_nop4
        .globl t_nop10
        .type t_nop10,@function
t_nop10: push rax
        mov edi, 7
        call report_error
        .byte 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
        .size t_nop10, .-t_nop10
        .globl t_zero
        .type t_zero,@function
t_zero: push rax
        mov edi, 8
        call report_error
        .byte 0x00, 0x00, 0x00, 0x00
        .size t_zero, .-t_zero
        .globl t_data
        .type t_data,@function
t_data: push rax
        mov edi, 9
        call report_error
        .size t_data, .-t_data
        .globl t_table
        .type t_table,@object
t_table: .quad 0x4142434445464748
        .size t_table, .-t_table

# v_*: wrong flag victims; report_error returns here and real code follows
        .globl v_plain
        .type v_plain,@function
v_plain: push rbx
        xor edi, edi
        call report_error
        mov eax, 3
        pop rbx
        ret
        .size v_plain, .-v_plain
        .globl v_add00
        .type v_add00,@function
v_add00: push rbx
        mov rbx, rsi
        xor edi, edi
        call report_error
        add byte ptr [rbx], al
        mov eax, 4
        pop rbx
        ret
        .size v_add00, .-v_add00
        .globl v_nop90
        .type v_nop90,@function
v_nop90: push rbx
        xor edi, edi
        call report_error
        .byte 0x90
        mov eax, 5
        pop rbx
        ret
        .size v_nop90, .-v_nop90
        .globl v_int3
        .type v_int3,@function
v_int3: push rbx
        xor edi, edi
        call report_error
        int3
        mov eax, 6
        pop rbx
        ret
        .size v_int3, .-v_int3
        .globl v_nop4
        .type v_nop4,@function
v_nop4: push rbx
        xor edi, edi
        call report_error
        .byte 0x0f, 0x1f, 0x40, 0x00
        mov eax, 7
        pop rbx
        ret
        .size v_nop4, .-v_nop4

        .globl _start
        .type _start,@function
_start: call v_plain
        call v_add00
        call v_nop90
        call v_int3
        call v_nop4
        call ev1
        call ev2
        call ev3
        call t_nop90
        call t_int3
        call t_nop4
        call t_nop10
        call t_zero
        call t_data
        xor edi, edi
        mov eax, 60
        syscall
        .size _start, .-_start
Scoped pass, as tested

This replaces disassemble(s) in the site loop and the comment after the refit.

// in the site loop, instead of disassemble(s):
DisassembleCommand dc = new DisassembleCommand(s, null, true);
dc.enableCodeAnalysis(false);
dc.applyTo(currentProgram, monitor);
restored.add(dc.getDisassembledAddressSet());

// after the refit loop:
AutoAnalysisManager mgr = AutoAnalysisManager.getAnalysisManager(currentProgram);
Options opts = currentProgram.getOptions(Program.ANALYSIS_PROPERTIES);
MessageLog log = new MessageLog();
for (String name : new String[] {"Reference", "x86 Constant Reference Analyzer"}) {
  Analyzer a = mgr.getAnalyzer(name);
  if (a == null || restored.isEmpty()) continue;
  a.optionsChanged(opts.getOptions(a.getName()), currentProgram);
  a.added(currentProgram, restored, monitor, log);
}

The constant analyzer's name starts with the processor name. Check the list in your Ghidra log. I only ran x86-64.

One catch: the change events still queue up. Headless runs that queue after the last post-script. That pass runs the no-return analyzer too. I did not check what it flags. In REA, the bridge serves inside its own script. So that pass should come after the session ends. I read that in the bridge source but did not test it.

Raw decompile

fail_a, base:

int fail_a(int param_1)
{
  if (param_1 < 4) {
    return param_1 + 1;
  }
                    /* WARNING: Subroutine does not return */
  report_error(2,&DAT_004012ea);
}

fail_a, c3e1db89 and 7b5e36c0 (identical):

int fail_a(int param_1)
{
  int iVar1;

  if (param_1 < 4) {
    return param_1 + 1;
  }
  iVar1 = 2;
  report_error(2,&DAT_004012ea);
  if (iVar1 < 5) {
    return iVar1 + 2;
  }
  iVar1 = 3;
  report_error(3,&DAT_004012ec);
  if (iVar1 < 6) {
    return iVar1 + 3;
  }
  iVar1 = 4;
  report_error(4,&DAT_004012ee);
  if (iVar1 < 7) {
    return iVar1 + 4;
  }
  iVar1 = 5;
  report_error(5,&DAT_004012f0);
  if (iVar1 < 0x3e9) {
    return iVar1 + -1;
  }
                    /* WARNING: Subroutine does not return */
  wrap_exit(9);
}

warn_then_work, base to 7b5e36c0:

-void warn_then_work(void)
+int warn_then_work(int param_1)
 {
-                    /* WARNING: Subroutine does not return */
   report_error(0,"just a warning");
+  sink = param_1 * 7;
+  puts("code after the warning");
+  return param_1 + 0x2a;
 }

noret-O2g signatures:

Function base c3e1db89 7b5e36c0
warn_then_work int warn_then_work(int x) undefined warn_then_work(void) int warn_then_work(int x)
fail_a to fail_d int fail_a(int x) undefined fail_a(void) int fail_a(int x)
Compiler matrix
build                     log                            fail_a runs on?
clang -O0                 cleared=0 sites=0 refit=0      no flag
clang -O1                 cleared=1 sites=4 refit=4      yes
clang -O2                 cleared=1 sites=4 refit=4      yes
clang -O3                 cleared=1 sites=4 refit=4      yes
clang -Os                 cleared=1 sites=1 refit=1      no
clang -Oz                 cleared=1 sites=2 refit=2      no (fail_c halt_baddata)
clang -O2 -fPIE -pie      cleared=1 sites=4 refit=4      yes
clang -O2 -fcf-protection=full  cleared=1 sites=3 refit=3  yes (66 90)
clang -O2 -falign-functions=32  cleared=1 sites=4 refit=4  yes
clang -O2 -fuse-ld=lld    cleared=1 sites=3 refit=3      yes
clang -O2 -mllvm -trap-unreachable  cleared=0 sites=0 refit=0  no flag
gcc -O2                   cleared=1 sites=4 refit=4      yes
gcc -O2 -fcf-protection=full    cleared=1 sites=4 refit=4  yes
gcc -Os                   cleared=0 sites=0 refit=0      no flag
aarch64 -O2 (lld, freestanding)        cleared=1 sites=1 refit=1  no
aarch64 -O2 -falign-functions=16       cleared=1 sites=4 refit=4  yes
Commands
git -C rea.git fetch origin pull/1419/head
git -C rea.git archive 7b5e36c0 | tar -x -C h2      # also c3e1db89, 8550913c
npm ci && npm run build                             # Node 24.18.0, each tree
node node_modules/vitest/vitest.mjs run tests/boundary/providers/ghidra/ghidraLauncher.test.ts

# Direct Ghidra: fix, then a probe script (flags, bodies, refs, decompile)
analyzeHeadless proj p -import <bin> -readOnly -deleteProject \
  -scriptPath "h2/bridge/ghidra;scripts" \
  -postScript ReaGhidraNoReturnFix.java -postScript Probe.java out/

# Analyzer check: pre-script calling setAnalysisOption(...)
#   "Non-Returning Functions - Discovered" = false            -> cleared=0
#   "...Discovered.Function Non-return Threshold" = 4         -> cleared=0

# What clang emits after the calls, per target
clang --target=x86_64-apple-macos14 -O2 -S noret_min_nohdr.c   # also windows-msvc, linux, android

node scripts/rea.mjs function noret-O2 warn_then_work --provider ghidra --format json
Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Every Ghidra lane acts the same on base and head, and the full suite passes. The fix can't help when the bad flag sits on a PLT stub, like glibc's error() under gcc. On coreutils sort, it makes some functions better and some worse.

Ghidra lanes

Lane Base Head Head log
verify:ghidra pass, 344 s pass, 365 s 40 × cleared=0
:cross-format fail, 352 s fail, 349 s 42 × cleared=0
:aarch64-jump-table pass, 364 s pass, 365 s 44 × cleared=0
:switch pass, 293 s pass, 296 s 28 × cleared=0
:dos pass, 75 s pass, 75 s 10 × cleared=0
:com pass, 51 s pass, 51 s 7 × cleared=0

Cross-format fails the same way on base. So that is not from this PR. The error reads did not recover the multi-block callee. #1382 merged a fix for that name after this base. I have not rerun the lane on main.

Full suite

npm test on head, Node 24.18.0: 691 files pass, 11 skip. 6,294 tests pass, 89 skip, none fail. It took 564 s.

Scoped pass through the CLI

The PR has no hook for it. The launcher runs ReaGhidraNoReturnFix.java by a fixed path, with no args. So I swapped that one file in a scratch copy. No TypeScript changed.

function noret-O2 warn_then_work Head Head + scoped
Log cleared=1 sites=5 refit=5 same, plus restored=57 ms=2
Outgoing refs 4 5
Strings "just a warning" adds "code after the warning"
Wall 8.3 s 8.1 s

Callees in another library

With gcc -O2, glibc's header turns error(2, …) into a no-return call. Three of those make Ghidra flag the error PLT stub. Then error(0, …) callers get cut. The fix only clears a function with a ret, so it logs cleared=0. A stub into my own .so does the same.

A real binary: sort

sort from coreutils 9.10 (GPL-3.0-or-later) has its own error(). The fix clears it: cleared=1 sites=40 refit=20. key_warnings gets better: 7 "does not return" notes drop to 1. But badfieldspec and sort_die really never return. Now one runs on, and one turns into an endless loop.

Still not run

Edit: :cross-format ran on main, in the #1382 check. The fix for the multi-block error holds. A schema check from #1433 now stops the lane first.

Edit: the cross-format lane now passes on main at 40f73f6 (#3735). Results are in my new comment. It opened a Mach-O object and a PE file. Lint passes too. Still not run: :swift, :windows, :nativeaot, libpl2.so, Android and the suite on base or on Node 22 and 26.

  • Mach-O and PE through Ghidra. Cross-format fails before it gets there. Ran on main. The Mach-O is an object file, not a linked program.
  • :cross-format on main, after fix(ghidra): keep the cross-format branch callee multi-block #1382. Passed with a one-line local fix to the schema check.
  • :swift, :windows and :windows:package. They need macOS or Windows.
  • :nativeaot. It needs fixtures and a jar I don't have.
  • libpl2.so and Android.
  • The suite on base, or on Node 22 and 26. Lint. Lint ran on main, exit 0.
  • analyzeChanges before the refit.

Thanks, JonahSimon, for the new log line. It made the lane check easy.

Lane details
  • Each lane ran with npm run <lane> in each tree, one at a time.
  • Every head log line reads cleared=0 sites=0 refit=0. That is one line per Ghidra session.
  • Cross-format error, base and head: cross-arm64-elf did not recover the multi-block callee.
  • A poller copied every rea-ghidra-*/script.log before REA removed it.
  • verify:ghidra on head had 41 sessions and 40 log lines. The 41st is the lane's own startup-cancel check. Its log stops before any script runs.
  • :dos and :com load as x86:LE:16:Real. The fix runs there too.
  • No Ghidra error mentions the fix in any head log.
  • Cross-format imported 40 x86-64 ELF and 2 AArch64 ELF before it failed. I did not dig into why.
  • Lanes I could not run: :swift is macOS only. :windows and :windows:package are Windows only. :nativeaot needs _reference/nativeaot-integration/generated/linux-x64 and REA_GHIDRA_NATIVEAOT_JAR.
sort: base vs head

Body sizes in bytes, as Ghidra sees them:

Function Base Head Effect
main 13,372 13,563 21 → 11 "does not return"
key_warnings 2,640 2,750 7 → 1, warnings go on
__xargmatch_internal 458 712 grows
badfieldspec 97 112 runs on, 15 → 57 lines
incompatible_options 51 64 runs on, 11 → 51 lines
link_failure 33 48 11 → 111 lines
xalloc_die 61 66 now shows abort() after error()

sort_die on head:

  if (*piVar1 == 0x20) goto LAB_0010874a;
  if (param_2 == 0) goto LAB_00108758;
  do {
    do {
      uVar2 = quotearg_n_style_colon_constprop_0(param_2);
      error(2,*piVar1,"%s: %s",param_1,uVar2);
LAB_0010874a:
    } while (param_2 != 0);
    ...
LAB_00108758:
    param_2 = dcgettext(0,"standard output",5);
  } while( true );

On base it ended at that error(2, …) with "Subroutine does not return".

On ls from the same package, the fix cleared nothing.

The libc test files
/* glibc_error.c (trimmed; the file also has a report() wrapper): error() returns when status is 0 */
#include <error.h>
#include <stdio.h>

__attribute__((noinline)) int fail_a(int x) {
  if (x > 3) { error(2, 0, "fail_a %d", x); }
  return x + 1;
}
__attribute__((noinline)) int fail_b(int x) {
  if (x > 4) { error(3, 0, "fail_b %d", x); }
  return x + 2;
}
__attribute__((noinline)) int fail_c(int x) {
  if (x > 5) { error(4, 0, "fail_c %d", x); }
  return x + 3;
}
__attribute__((noinline)) int warn_then_work(int x) {
  error(0, 0, "just a warning %d", x);
  puts("code after the warning");
  return x * 7;
}
int main(int argc, char **argv) {
  (void)argv;
  return (warn_then_work(argc) + fail_a(argc) + fail_b(argc) + fail_c(argc)) & 1;
}

uses_libnr.c is the same shape with report_error(status, msg) from a libnr.so. It calls exit only when status is not 0. Its callers add __builtin_unreachable() after the call.

Build Flagged on base Head log warn_then_work
as shown, gcc -O2 error stub cleared=0 cut, same as base
as shown, clang -O2 none (head run only) cleared=0 full
plus __builtin_unreachable(), clang / gcc -O2 error stub cleared=0 cut, same as base
plus __builtin_unreachable(), clang -O0 none cleared=0 full
libnr.so, clang / gcc -O2 report_error stub cleared=0 cut, same as base
die() → exit(), clang / gcc -O2 exit, die cleared=0 n/a, right as is

Clang skips glibc's inline error() path. error.h only pulls it in when __va_arg_pack exists, and clang lacks it.
-D_FORTIFY_SOURCE=2 gave a byte-identical binary.

Commands
# lanes, once per tree (base = git archive 8550913c, head = clone at 7b5e36c0)
GHIDRA_INSTALL_DIR=... JAVA_HOME=... TMPDIR=/tmp/short npm run verify:ghidra   # and each :lane

# suite, head, no Ghidra env
TMPDIR=/tmp/short npm test

# scoped pass via CLI: swap the script in a scratch copy, run, restore
cp ReaGhidraNoReturnFix.scoped.java bridge/ghidra/ReaGhidraNoReturnFix.java
node scripts/rea.mjs function noret-O2 warn_then_work --provider ghidra --format json
# the analysis profile digest stayed a4517e7f... with either script: the script is not part of it

# libc fixtures
gcc -O2 glibc_error.c -o err-gcc-O2
clang -O2 -fPIC -shared libnr.c -o libnr.so
clang -O2 uses_libnr.c -L. -lnr -o nr-clang-O2
Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto
morluto merged commit 162f9bf into morluto:main Oct 10, 2026
@morluto

morluto commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thanks @JonahSimon for tackling incorrect Ghidra no-return flags and the truncated analysis they cause! Squash merged with the review fixes. Welcome to REA, and thank you for your first PR.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The cross-format Ghidra lane now passes on main. It opened a Mach-O object, a PE file and an ARM64 ELF on a main that still has the no-return fix. Lint passes too. Windows, Android and the other lanes that need extra files are still not run.

This pull request merged as 162f9bf (#1419) on 2026-10-10. This comment is a record. It runs items from my last comment that I had not run. I ran them on main at 40f73f6 (#3735).

Results

Check Result
npm run verify:ghidra:cross-format Exit 0 in 444 s. The report says ok: true.
Targets it opened An ARM64 ELF, an x86-64 PE file and an x86-64 Mach-O object, plus four x86-64 ELF fixtures.
oxlint (npm run lint:details) Exit 0. 0 errors, 1,469 warnings.

In my last comment this lane failed on base and on head with did not recover the multi-block callee. #1382 fixed that. Then a schema check from #1433 stopped the lane before it began. It now runs from start to end with no local change. I did not need the one-line fix I used before.

Ghidra 12.1.4 loaded each target. The lane builds the PE with lld-link. It builds the Mach-O only as an object file, with clang --target=x86_64-apple-darwin -c. So this is Mach-O code, not a linked macOS program.

GhidraLauncher.ts on main still names ReaGhidraNoReturnFix.java. The lane's report does not show the cleared= log line. So I can't say what the fix did on these targets. I can only say the lane passes on this main.

Not run

  • :swift. It needs macOS.
  • :windows and :windows:package. They need Windows.
  • :nativeaot. It needs fixtures and a jar I don't have.
  • libpl2.so and Android.
  • The suite on base, or on Node 22 and 26. The box forbids whole suites.
  • analyzeChanges before the refit. That was an idea, not a check.

Thanks, JonahSimon, for the fix and the log line.

Commands
export GHIDRA_INSTALL_DIR=~/.local/opt/ghidra_12.1.4_PUBLIC
export JAVA_HOME=~/.local/opt/jdk-21.0.12.1+1
npm run verify:ghidra:cross-format     # Node 24, under an 8 GB memory cap
npm run lint:details

The lane needs clang, ld.lld and lld-link on the path. All three were there.

Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto morluto added area: cli CLI adapter and one-shot commands provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants