Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force gcc to pass the parameters on the stack

Is there a way to force gcc to pass the parameters of a function on the stack?

I don't want to use the registers for parameter passing.

Update: I'am using arm-gcc from CodeSourcery

like image 409
cojocar Avatar asked Jan 09 '11 16:01

cojocar


1 Answers

You can try wrapping the parameters in a structure; for example, if your function is int calc_my_sum(int x, int y) {return x+y;} you can change it as follows (ugly):

struct my_x_y {
    int x, y;
    my_x_y(): x(0), y(0) {} // a non-trivial constructor to make the type non-POD
};

int calc_my_sum(my_x_y x_and_y) {
    // passing non-POD object by value forces to use the stack
    return x_and_y.x + x_and_y.y;
}

Alternatively, you can just add 4 dummy parameters to use up the registers, so other parameters will use stack:

struct force_stack_usage {
    int dummy0, dummy1, dummy2, dummy3;
}

int calc_my_sum(force_stack_usage, int x, int y) {
    return x + y;
}
like image 73
anatolyg Avatar answered Sep 21 '22 20:09

anatolyg