Repository navigation
fix(ghidra): clear wrong no-return flags before serving a session - #1419
Conversation
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]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
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 What I triedI ran REA with real Ghidra on Linux, on a small C file. Its Results (
|
| 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
- Types are lost.
removeFunctionthencreateFunction(e, null)keeps the name. But it drops the DWARF signature and calling convention.fail_atofail_dlose theirs too. In a scratch copy, I swapped those two lines forCreateFunctionCmd.fixupFunctionBody(currentProgram, f, monitor).warn_then_workstill got its full body. All 19 named types matched base. I did not check if it helps point 2. - Real end calls now run on. In
fail_a, the call is the last code before padding. Ghidra had put aCALL_RETURNflow override on it. The fix clears it and disassembles again. So the decompiler falls through intofail_b. Code built on gnulib'serror()may hit this. One idea: skip a site when the bytes after it are padding or a function start. - The site scan is wide. It found 16 sites for 5 calls. PLT stubs (
puts,printf,fprintf,fwrite) count too. So does theframe_dummytail jump. Those get rebuilt and lose the override.maindecompiles the same, so I saw no harm from it. - Restored code has no refs. The string "code after the warning" shows in the head pseudocode. It is missing from
referenced_stringsandoutgoing_references. Analysis does not run on the new code. - Quiet when idle. The
printlnonly runs when it clears a flag. Onlsthe log shows nothing. So you can't tell it ran. - 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. Six ran. Four need macOS, Windows or extra files.verify:ghidraon base, and the otherverify:ghidra:*lanes.The full test suite. Only the changed test ran.Head only, on Node 24.rea decompileofmaininlsfails 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 sayscleared=0in 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 onlyRepro 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
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 22.23.1, 24.18.0, 26.11.1
- Head / base:
c3e1db89/8550913c - Ghidra: 12.1.4 (Apache-2.0)
- JDK: Temurin JDK 21 (GPLv2 with Classpath Exception)
- Compiler: clang 22.1.8 (Apache 2.0 with LLVM exception)
- Binary:
lsfrom GNU coreutils 9.10 (GPL-3.0-or-later)
🤖 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]>
|
Thanks for the detailed review, CassieFox23. Pushed 7b5e36c. Addressed:
Not changed: Verification: Not verified: I could not reproduce your |
|
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 Your two questions1. The fixture. I built on Linux x86-64 with clang 22.1.8: clang -O2 noret_min.c -o noret_minThe analyzer that flags On macOS, clang puts To rule out the compiler, I also made
2. A cheaper scoped pass (tested, direct Ghidra only). I skip the queue. I keep the set each I also tried your
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 Retest at
|
| 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. Six lanes ran on Linux. Four need macOS, Windows or extra files.verify:ghidralanesThe scoped pass through the REA CLI. I ran it inRan by swapping the script file in a scratch copy.analyzeHeadlessonly.- Running
analyzeChangesbefore the refit. That is just an idea. Callees that live in another library, like glibc'serror(). 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.getBytethrows, soisX86Paddingsays no. The site is redone.fail_cthen decompiles tohalt_baddata. - Compiler flags. Most of my builds still run on. That covers clang
-O1,-O2,-O3,-fPIE -pie,-fcf-protection=full,-falign-functions=32and lld. It covers gcc-O2too. Clang-Osand-Ozput 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_aruns 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, .-_startScoped 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 jsonTest setup
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 22.23.1, 24.18.0, 26.11.1
- Head / base:
7b5e36c0/8550913c(alsoc3e1db89) - Ghidra: 12.1.4 (Apache-2.0)
- JDK: Temurin 21.0.12.1+1 (GPLv2 with Classpath Exception)
- Compiler: clang 22.1.8, Fedora build (Apache-2.0 with LLVM exception)
- Linker: LLD 22.1.8 (Apache-2.0 with LLVM exception), GNU ld 2.46.1 (GPL-3.0-or-later)
- Also: GCC 16.2.1 (GPL-3.0-or-later)
🤖 Generated with Claude Code (Opus 5.5) 🦊
|
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 Ghidra lanes
Cross-format fails the same way on base. So that is not from this PR. The error reads Full suite
Scoped pass through the CLIThe PR has no hook for it. The launcher runs
Callees in another libraryWith gcc A real binary:
|
| 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-O2Test setup
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 24.18.0
- Head / base:
7b5e36c0/8550913c - Ghidra: 12.1.4 (Apache-2.0)
- JDK: Temurin 21.0.12.1+1 (GPL-2.0 with Classpath Exception)
- Compilers: clang 22.1.8 (Apache-2.0 WITH LLVM-exception)
- GCC 16.2.1 (GPL-3.0-or-later)
- Linkers: LLD 22.1.8 (Apache-2.0 WITH LLVM-exception)
- GNU ld 2.46.1 (GPL-3.0-or-later)
- libc: glibc 2.43 (LGPL-2.1-or-later)
- Real binaries:
sortandlsfrom coreutils 9.10 (GPL-3.0-or-later)
🤖 Generated with Claude Code (Opus 5.5) 🦊
|
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. |
|
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
In my last comment this lane failed on base and on head with Ghidra 12.1.4 loaded each target. The lane builds the PE with
Not run
Thanks, JonahSimon, for the fix and the log line. Commandsexport 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:detailsThe lane needs Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
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 realRET(stream readers,__cxa_guard_acquire,__release_weak). Every caller then treats the call as a terminator, soprocedure_pseudo_codereturns 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:RET(terminal, non-jump, non-call).CALL_TERMINATORbut whose callee is no longer no-return.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.tsupdated (fix script ordered before the bridge); focused run passes.libpl2.so, decompile of theZoneCompleteMessagedeserializer 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.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