< Home

In my previous post (pwnable.kr series – fd) I noticed something at the end. While our assembly code calls the library function puts, the original source-code was making use of printf.

Now, this is a gcc compiler optimization and I’ve used Godbolt to showcase some of these printf optimizations.

Compiler optimizations of printf

Open code in Godbolt

So as you can see, or read from the compiler source. When printf only contains one char it will change to putchar, if it contains a string literal ending with it becomes puts. A normal string without just stays printf (why? a question answered on stack-overflow) and when you do printf(“”) it will just not compile it.

< Home