calling 32-bit printf from 64-bit binary?
I have this simple C code -
Code:
#include <stdio.h>
int main() {
printf("asdf");
}
And decided to look at the assembly output by gcc and found something strange.
The relevant section -
Code:
main:
pushq %rbp
movq %rsp, %rbp
movl $.LC0, %edi
movl $0, %eax
call printf
leave
ret
The thing is, this is on 64-bit Linux, and this is apparently a 64-bit binary (since it's using all those r registers), but the call to printf is 32-bit (address of the format string via edi, and "number of SSE registers used" via eax, both 32-bit registers).
Quote:
cyberfish@cyberfish-desktop:/tmp$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
Any clue what is going on?
Many thanks