[Bug] Declare recovered internal functions before call sites

Open
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, cpp

Research direction

Start with the function emission loop in src/decompiler/project.cpp (lines 316-337) and the call emission in src/decompiler/decompiler.cpp (lines 558-590), then check how analysis.functions is used to name callees. Save the issue's reproducer as C, decompile it, and compile the output with gcc -std=c11 -Wall -Wextra -Werror to see the implicit-declaration error. Done means the reproducer compiles cleanly, and forward and mutually recursive calls also compile with matching prototypes and static linkage.

Written by the indexing model from the issue text.

Description

bug

Summary

Generated C-like output calls recovered internal functions before declaring them. When a caller is located before its callee in the binary, the generated source fails under C11 with -Werror.

Evidence

src/decompiler/project.cpp:316-337 emits recovered function definitions in analysis/address order, while src/decompiler/decompiler.cpp:558-590 emits calls using the recovered callee name. No forward declarations are emitted for functions in analysis.functions.

Reproducer:

int callee(int);
__attribute__((noinline)) int caller(int x) { return callee(x); }
__attribute__((noinline)) int callee(int x) { return x; }
int main(void) { return caller(0); }

After compiling at -O0 -g, decompiling, and compiling the recovered source with gcc -std=c11 -Wall -Wextra -Werror, GCC reports:

error: implicit declaration of function ‘callee’
error: static declaration of ‘callee’ follows non-static declaration

Impact

Whether recovered output compiles depends on the link/order layout of functions. Forward calls, mutually recursive functions, and some stripped binaries fail even when the underlying recovered call is otherwise representable.

Expected behavior

The renderer should emit a consistent prototype for every recovered internal function before any function body, or otherwise order declarations safely while preserving recursion and the static linkage used by generated definitions.

Acceptance criteria

  • The reproducer compiles with -std=c11 -Wall -Wextra -Werror.
  • Forward calls and recursive/mutually recursive calls do not produce implicit-declaration or linkage-conflict diagnostics.
  • Prototypes use the same generated identifiers and compatible parameter/return types as their definitions.
Dominant language
C++
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TiElixir/caraxes

All issues in TiElixir/caraxes

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.