Say, I have compiled a large code base, e.g. gzip/gmp/python/php etc. on Linux. Is there any means to map a high level C construct, e.g. assignment/if-else/for/while/Math expression back in the assembly dump produced by objdump or something similar? Please let me know how far it is possible in both the cases when debug information is present and absent.

  • Do you want to decompile the code or map assembly to original source ? – w s Sep 26 '15 at 12:59
  • 2
    It sounds like what you're asking is, "is it possible to reverse engineer software?" So if I'm understanding you correctly, the answer is, "yes." – Jason Geffner Sep 26 '15 at 13:29
  • Note that just about any of your original "ssignment/if-else/for/while/Math expression" in the C source may be optimized beyond recognition, or even entirely be omitted. I.e., even with the lowest compiler optimization settings, you won't find the "5" of a statement i = 100/5; back in your executable. (Assuming any 21st century compiler was used.) – usr2564301 Sep 27 '15 at 15:07

I'll try to outline a possible ways you can go:

  1. If you compile with debug symbols, you can use objdump to produce a more readable disassembly.
  2. if you give gcc the flag -fverbose-asm, the assembler it emits will be a lot clearer to read.
  3. Use the -S (note: capital S) switch to gcc, and it will emit the assembly code to a file with a .s extension. For example, the following command: gcc -O2 -S -c foo.c will leave the generated assembly code on the file foo.s.

Also, you can generate this in AT&T syntax as well as in Intel syntax: gcc -S -masm=att code.c gcc -S -masm=intel code.c

Frankly, I've digested the info from here. Hope it will help.

EDIT: some useful links:

The info that's more specific to your question

Looks very promising except that the project is abandoned

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.