PR#5707: in AMD64 port, exchange the roles of r10-r11 and r12-r13,

so that r10 and r11 are no longer used for parameter passing,
  and can therefore be destroyed by the dynamic loader without harm.
(Cherry-picked from version/4.00, commit 12907).


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12908 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2012-09-08 16:53:39 +00:00
parent 9d45c49928
commit 9ac1d4937b
6 changed files with 36 additions and 32 deletions

View File

@ -35,6 +35,8 @@ OCaml 4.00.1:
Bug fixes:
- PR#5700: crash with native-code stack backtraces under MacOS 10.8 x86-64
- PR#5707: AMD64 code generator: do not use r10 and r11 for parameter passing,
as these registers can be destroyed by the dynamic loader
- PR#5712: some documentation problems
- PR#5719: ocamlyacc generates code that is not warning 33-compliant
- PR#5742: missing bound checks in Array.sub

View File

@ -109,13 +109,13 @@ let emit_reg = function
let reg_low_8_name =
[| "%al"; "%bl"; "%dil"; "%sil"; "%dl"; "%cl"; "%r8b"; "%r9b";
"%r10b"; "%r11b"; "%bpl"; "%r12b"; "%r13b" |]
"%r12b"; "%r13b"; "%bpl"; "%r10b"; "%r11b" |]
let reg_low_16_name =
[| "%ax"; "%bx"; "%di"; "%si"; "%dx"; "%cx"; "%r8w"; "%r9w";
"%r10w"; "%r11w"; "%bp"; "%r12w"; "%r13w" |]
"%r12w"; "%r13w"; "%bp"; "%r10w"; "%r11w" |]
let reg_low_32_name =
[| "%eax"; "%ebx"; "%edi"; "%esi"; "%edx"; "%ecx"; "%r8d"; "%r9d";
"%r10d"; "%r11d"; "%ebp"; "%r12d"; "%r13d" |]
"%r12d"; "%r13d"; "%ebp"; "%r10d"; "%r11d" |]
let emit_subreg tbl r =
match r.loc with
@ -669,14 +669,13 @@ let emit_profile () =
match Config.system with
| "linux" | "gnu" ->
(* mcount preserves rax, rcx, rdx, rsi, rdi, r8, r9 explicitly
and rbx, rbp, r12-r15 like all C functions.
We need to preserve r10 and r11 ourselves, since OCaml can
use them for argument passing. *)
and rbx, rbp, r12-r15 like all C functions. This includes
all the registers used for argument passing, so we don't
need to preserve other regs. We do need to initialize rbp
like mcount expects it, though. *)
` pushq %r10\n`;
` movq %rsp, %rbp\n`;
` pushq %r11\n`;
` {emit_call "mcount"}\n`;
` popq %r11\n`;
` popq %r10\n`
| _ ->
() (*unsupported yet*)

View File

@ -110,13 +110,13 @@ let emit_reg = function
let reg_low_8_name =
[| "al"; "bl"; "dil"; "sil"; "dl"; "cl"; "r8b"; "r9b";
"r10b"; "r11b"; "bpl"; "r12b"; "r13b" |]
"r12b"; "r13b"; "bpl"; "r10b"; "r11b" |]
let reg_low_16_name =
[| "ax"; "bx"; "di"; "si"; "dx"; "cx"; "r8w"; "r9w";
"r10w"; "r11w"; "bp"; "r12w"; "r13w" |]
"r12w"; "r13w"; "bp"; "r10w"; "r11w" |]
let reg_low_32_name =
[| "eax"; "ebx"; "edi"; "esi"; "edx"; "ecx"; "r8d"; "r9d";
"r10d"; "r11d"; "ebp"; "r12d"; "r13d" |]
"r12d"; "r13d"; "ebp"; "r10d"; "r11d" |]
let emit_subreg tbl pref r =
match r.loc with

View File

@ -45,18 +45,18 @@ let masm =
rcx 5
r8 6
r9 7
r10 8
r11 9
r12 8
r13 9
rbp 10
r12 11
r13 12
r10 11
r11 12
r14 trap pointer
r15 allocation pointer
xmm0 - xmm15 100 - 115 *)
(* Conventions:
rax - r11: OCaml function arguments
rax - r13: OCaml function arguments
rax: OCaml and C function results
xmm0 - xmm9: OCaml function arguments
xmm0: OCaml and C function results
@ -70,16 +70,19 @@ let masm =
xmm0 - xmm3: C function arguments
rbx, rbp, rsi, rdi r12-r15 are preserved by C
xmm6-xmm15 are preserved by C
Note (PR#5707): r11 should not be used for parameter passing, as it
can be destroyed by the dynamic loader according to SVR4 ABI.
Linux's dynamic loader also destroys r10.
*)
let int_reg_name =
match Config.ccomp_type with
| "msvc" ->
[| "rax"; "rbx"; "rdi"; "rsi"; "rdx"; "rcx"; "r8"; "r9";
"r10"; "r11"; "rbp"; "r12"; "r13" |]
"r12"; "r13"; "rbp"; "r10"; "r11" |]
| _ ->
[| "%rax"; "%rbx"; "%rdi"; "%rsi"; "%rdx"; "%rcx"; "%r8"; "%r9";
"%r10"; "%r11"; "%rbp"; "%r12"; "%r13" |]
"%r12"; "%r13"; "%rbp"; "%r10"; "%r11" |]
let float_reg_name =
match Config.ccomp_type with
@ -241,12 +244,12 @@ let destroyed_at_c_call =
if win64 then
(* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *)
Array.of_list(List.map phys_reg
[0;4;5;6;7;8;9;
[0;4;5;6;7;11;12;
100;101;102;103;104;105])
else
(* Unix: rbp, rbx, r12-r15 preserved *)
Array.of_list(List.map phys_reg
[0;2;3;4;5;6;7;8;9;
[0;2;3;4;5;6;7;11;12;
100;101;102;103;104;105;106;107;
108;109;110;111;112;113;114;115])

View File

@ -249,11 +249,11 @@ LBL(caml_call_gc):
addq $32768, %rsp
#endif
/* Build array of registers, save it into caml_gc_regs */
pushq %r13; CFI_ADJUST (8);
pushq %r12; CFI_ADJUST (8);
pushq %rbp; CFI_ADJUST (8);
pushq %r11; CFI_ADJUST (8);
pushq %r10; CFI_ADJUST (8);
pushq %rbp; CFI_ADJUST (8);
pushq %r13; CFI_ADJUST (8);
pushq %r12; CFI_ADJUST (8);
pushq %r9; CFI_ADJUST (8);
pushq %r8; CFI_ADJUST (8);
pushq %rcx; CFI_ADJUST (8);
@ -317,11 +317,11 @@ LBL(caml_call_gc):
popq %rcx; CFI_ADJUST(-8)
popq %r8; CFI_ADJUST(-8)
popq %r9; CFI_ADJUST(-8)
popq %r10; CFI_ADJUST(-8)
popq %r11; CFI_ADJUST(-8)
popq %rbp; CFI_ADJUST(-8)
popq %r12; CFI_ADJUST(-8)
popq %r13; CFI_ADJUST(-8)
popq %rbp; CFI_ADJUST(-8)
popq %r10; CFI_ADJUST(-8)
popq %r11; CFI_ADJUST(-8)
/* Return to caller */
ret
CFI_ENDPROC

View File

@ -51,11 +51,11 @@ L105:
mov caml_young_ptr, r15
mov caml_exception_pointer, r14
; Build array of registers, save it into caml_gc_regs
push r13
push r12
push rbp
push r11
push r10
push rbp
push r13
push r12
push r9
push r8
push rcx
@ -113,11 +113,11 @@ L105:
pop rcx
pop r8
pop r9
pop r10
pop r11
pop rbp
pop r12
pop r13
pop rbp
pop r10
pop r11
; Restore caml_young_ptr, caml_exception_pointer
mov r15, caml_young_ptr
mov r14, caml_exception_pointer