History

Fix register corruption at function call on ARM

Prior to this commit, params could use some registers that do not appear in the value stack. Therefore when generating function call, one of such register could be reused, leading to wrong parameter content. This happens when a structure is passed via core register, as only the first register would appear in the value stack.

Thomas Preud'homme committed 12 years ago

Commit 41ce3911 parent 1b606d11 file · +16 −6Browse files

Unified · Split

arm-gen.c+16−6
@@ -979,10 +979,12 @@ static int assign_regs(int nb_args, int variadic, struct plan *plan, int *todo) · 978 unmodified lines
979979
980980 nb_args: number of parameters the function take
981981 plan: the overall assignment plan for parameters
982− todo: a bitmap indicating what core reg will hold a parameter */
983−static void copy_params(int nb_args, struct plan *plan, int todo)
982+ todo: a bitmap indicating what core reg will hold a parameter
983+
984+ Returns the number of SValue added by this function on the value stack */
985+static int copy_params(int nb_args, struct plan *plan, int todo)
984986 {
985− int size, align, r, i;
987+ int size, align, r, i, nb_extra_sval = 0;
986988 struct param_plan *pplan;
987989
988990 /* Several constraints require parameters to be copied in a specific order:
@@ -1111,11 +1113,19 @@ static void copy_params(int nb_args, struct plan *plan, int todo) · 122 unmodified lines
11111113 if(todo) {
11121114 o(0xE8BD0000|todo); /* pop {todo} */
11131115 for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) {
1116+ int r;
11141117 pplan->sval->r = pplan->start;
1115− if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG)
1116− pplan->sval->r2 = pplan->end;
1118+ /* TODO: why adding fake param */
1119+ for (r = pplan->start + 1; r <= pplan->end; r++) {
1120+ if (todo & (1 << r)) {
1121+ nb_extra_sval++;
1122+ vpushi(0);
1123+ vtop->r = r;
1124+ }
1125+ }
11171126 }
11181127 }
1128+ return nb_extra_sval;
11191129 }
11201130
11211131 /* Generate function call. The function address is pushed first, then
@@ -1158,7 +1168,7 @@ void gfunc_call(int nb_args) · 36 unmodified lines
11581168 }
11591169 #endif
11601170
1161− copy_params(nb_args, &plan, todo);
1171+ nb_args += copy_params(nb_args, &plan, todo);
11621172 tcc_free(plan.pplans);
11631173
11641174 /* Move fct SValue on top as required by gcall_or_jmp */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t