Tuesday, 3 January 2012

Function Calling Conventions on x86_64 -- Order of arguments and registers

I have been struggling with a memory corruption issue, and the need was to figure out the values of the arguments passed to a function. GDB would somehow not print the values of those arguments, and I set out to figure out through the registers. Through a trivial test program on a x86_64, I can see that the order of the arguments stored in registers is like this. If the called function is func1(int i, int j, int k, int l, int m, int n), the registers I found to be storing the values are like this --
%rdi --> i
%rsi --> j
%rdx --> k
%rcx --> l
%r8 --> m
%r9 --> n

My confusion was the order of the storage of the arguments, specifically, if %rdi would store the value of i, or the value of n.
My system configuration is this --
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 3
AND
'uname -r' shows --
2.6.16.60-0.54.5-smp

No comments:

Post a Comment