question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to identify call spec of `printf` for some compiler

See original GitHub issue

Describe the bug wrong FuncCallSpec of printf for some file compiled with clang-10

To Reproduce Steps to reproduce the behavior:

  1. compile the following file with clang-10
#include <stdio.h>
#include <stdlib.h>
void foo() {
    int ****a = malloc(10 * sizeof(int**));
    for (int i = 0; i < 10; i++) {
        a[i] = malloc(10 * sizeof(int**));
        for(int j = 0; j < 10; j++) {
            a[i][j] = malloc(sizeof(int*));
            *a[i][j] = malloc(sizeof(int));
            **a[i][j] = i;
            printf("%d", **a[i][j]);
        }
    }
}

int main() {
    foo();
    return 0;
}
  1. decompile it with ghidra

Expected behavior function printf should be called correctly in function foo.

Screenshots image

Attachments 0x13_ptr4.zip

Environment (please complete the following information):

  • OS: Arch Linux
  • Java Version: java-18-openjdk
  • Ghidra Version: 10.1.2-1
  • Ghidra Origin: archlinux community/ghidra 10.1.2-1

Additional context Executable compiled with clang-13 can be decompiled properly.

The assembly of that bb for clang-10 version: image

The assembly of that bb for clang-13 version: image

and the decompilation result image

Why is the result different for those almost identical codes?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
astrelskycommented, Apr 14, 2022

https://user-images.githubusercontent.com/46897303/163356907-fa7ebce1-dec2-4bf9-afcb-3c2dc47ab0a5.mp4

Has the function signature for printf been properly set? You can also run the variadic function signature analyzer (I forget its name) which should automatically apply overrides to functions like printf to specify the parameter types in the call deduced from the format string.

0reactions
Katharsascommented, Jun 2, 2022

@ghidracadabra I managed to fix it in my case by running the Variadic Function Signature analyzer ONLY on the function containing the calls (via Select -> Function, Analysis -> One Shot -> …). Before i always recomputed analysis for the whole executable. I now get basically the same result as with the other exe. Not entirely sure why this worked (i had both the Lookup and Printf functions commited even before that), but it works now, so thanks a lot!

And manual override would have worked, but it would have been a massive pain without scripting because i have these situations with lookup+printf a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why exactly does printf not compile? - Stack Overflow
This violates the specs of the language for literal string, so the compiler should produce some error message for failing the compilation.
Read more >
printf() not working - _write() never gets called - ST Community
Hello,. as the title suggest, I can't get printf() to work. I implemented _write() in my main() but during debugging the program never...
Read more >
Printf() - an overview | ScienceDirect Topics
The printf() function sends a formatted string to the standard output (the display). This string can display formatted variables and special control ...
Read more >
std::printf, std::fprintf, std::sprintf, std::snprintf - cppreference.com
If a call to sprintf or snprintf causes copying to take place between objects that overlap, the behavior is undefined (e.g. sprintf(buf, ...
Read more >
printf() — Print Formatted Characters - IBM
Format specifications, beginning with a percent sign (%), determine the output ... format specification cannot be mixed in the same call to printf()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found