CC=gcc
DEBUG = -g
CFLAGS=-c -Wall $(DEBUG) -I../build/include/
LDFLAGS=-L../build/lib/
LDLIBS=-lrte_cfgfile -lrte_eal
SOURCES=test_cfg.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=test_cfg
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
# $(CC) $(LDFLAGS) $(OBJECTS) -o $@
# $(CC) $(OBJECTS) -o $@ $(LDFLAGS)
$(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -rf *.o $(EXECUTABLE)
Thursday, February 23, 2017
stack-frame-layout-on-x86-64
Argument passing on Linux x64
I'm going to simplify the discussion here on purpose and focus on integer/pointer arguments [3]. According to the ABI, the first 6 integer or pointer arguments to a function are passed in registers. The first is placed in rdi, the second in rsi, the third in rdx, and then rcx, r8 and r9. Only the 7th argument and onwards are passed on the stack.
The stack frame
With the above in mind, let's see how the stack frame for this C function looks:
long myfunc(long a, long b, long c, long d,
long e, long f, long g, long h)
{
long xx = a * b * c * d * e * f * g * h;
long yy = a + b + c + d + e + f + g + h;
long zz = utilfunc(xx, yy, xx % yy);
return zz + 20;
}
This is the stack frame:
referenced from:
stack-frame-layout-on-x86-64
I'm going to simplify the discussion here on purpose and focus on integer/pointer arguments [3]. According to the ABI, the first 6 integer or pointer arguments to a function are passed in registers. The first is placed in rdi, the second in rsi, the third in rdx, and then rcx, r8 and r9. Only the 7th argument and onwards are passed on the stack.
The stack frame
With the above in mind, let's see how the stack frame for this C function looks:
long myfunc(long a, long b, long c, long d,
long e, long f, long g, long h)
{
long xx = a * b * c * d * e * f * g * h;
long yy = a + b + c + d + e + f + g + h;
long zz = utilfunc(xx, yy, xx % yy);
return zz + 20;
}
This is the stack frame:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG2oBg6CnkCXNGtq2uz3JayCEUkAbCfbfUMgce3PKJrATxJqHFEcyXPDxqIFXwMO6cL54DY-R0BoGt7y4MdD_2SxG9A4O1Uq2Rkcz1BIanGoxPBx9_FLiCKJ5Tf28XkgkQ92s92LWYCscV/s320/x64_frame_nonleaf.png)
stack-frame-layout-on-x86-64
Subscribe to:
Posts (Atom)