Description
[Describe the bug
When I decompile a call to a variadic function, it references the wrong registers.
To Reproduce
Steps to reproduce the behavior:
- Use this program:
#include <stdio.h>
#include <stdarg.h>
int main(int argc, char ** argv)
{
printf("foo %d bar %s\n",1234,"quux");
return 0;
}
-
Compile:
$ gcc main.c -o test-vargs
-
In Ghidra, import file and do default analysis
-
Edit entry function to look like main() should:
int entry(int param_1,char **param_2)
- See call to _printf contains reference to param_1 (which is register x1) and in_x2.
Expected behavior
I'd expect it to get the functions to
_fprintf() is properly labelled as a variadic function.
Using the _cdecl calling convention, it seems to be expecting args in x1 and x2, but entry() has them set up in x8 and x9.
Screenshots
If applicable, add screenshots to help explain your problem.
Attachments
If applicable, please attach any files that caused problems or log files generated by the software.
Environment (please complete the following information):
- OS: macOS Sequoia 15.3.2
- Java Version: 23.0.1
- Ghidra Version: 11.3.1
- Ghidra Origin: official GitHub distro
Additional context
Maybe I need a different calling convention for aarch64? I'd expect cdecl to do this properly.