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
979 979
980 nb_args: number of parameters the function take980 nb_args: number of parameters the function take
981 plan: the overall assignment plan for parameters981 plan: the overall assignment plan for parameters
982 todo: a bitmap indicating what core reg will hold a parameter */982 todo: a bitmap indicating what core reg will hold a parameter
983static void copy_params(int nb_args, struct plan *plan, int todo)983
984 Returns the number of SValue added by this function on the value stack */
985static int copy_params(int nb_args, struct plan *plan, int todo)
984{986{
985 int size, align, r, i;987 int size, align, r, i, nb_extra_sval = 0;
986 struct param_plan *pplan;988 struct param_plan *pplan;
987 989
988 /* Several constraints require parameters to be copied in a specific order:990 /* 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
1111 if(todo) {1113 if(todo) {
1112 o(0xE8BD0000|todo); /* pop {todo} */1114 o(0xE8BD0000|todo); /* pop {todo} */
1113 for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) {1115 for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) {
1116 int r;
1114 pplan->sval->r = pplan->start;1117 pplan->sval->r = pplan->start;
1115 if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG)1118 /* TODO: why adding fake param */
1116 pplan->sval->r2 = pplan->end;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 }
1117 }1126 }
1118 }1127 }
1128 return nb_extra_sval;
1119}1129}
1120 1130
1121/* Generate function call. The function address is pushed first, then1131/* Generate function call. The function address is pushed first, then
@@ -1158,7 +1168,7 @@ void gfunc_call(int nb_args) · 36 unmodified lines
1158 }1168 }
1159#endif1169#endif
1160 1170
1161 copy_params(nb_args, &plan, todo);1171 nb_args += copy_params(nb_args, &plan, todo);
1162 tcc_free(plan.pplans);1172 tcc_free(plan.pplans);
1163 1173
1164 /* Move fct SValue on top as required by gcall_or_jmp */1174 /* 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