Bug 1225995

Summary: ppc64le: ocaml calls from ocaml to C fail with more than 8 parameters
Product: Red Hat Enterprise Linux 7 Reporter: Richard W.M. Jones <rjones>
Component: ocamlAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Václav Kadlčík <vkadlcik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: huzhan, lagarcia, normand, qe-baseos-tools-bugs, vkadlcik
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ocaml-4.01.0-22.5.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 04:49:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1224675, 1224676    
Attachments:
Description Flags
call.ml
none
print.c
none
Makefile
none
Makefile none

Description Richard W.M. Jones 2015-05-28 17:07:01 UTC
Description of problem:

The OCaml compiler on ppc64le miscompiles calls from OCaml to C which
have more than 8 parameters.

The example program prints:

$ ./test
-1
-1 -2
-1 -2 -3
-1 -2 -3 -4
-1 -2 -3 -4 -5
-1 -2 -3 -4 -5 -6
-1 -2 -3 -4 -5 -6 -7
-1 -2 -3 -4 -5 -6 -7 -8
-1 -2 -3 -4 -5 -6 -7 -8 0
-1 -2 -3 -4 -5 -6 -7 -8 0 70366595657576
                        ^^^^^
                        note incorrect values here

Version-Release number of selected component (if applicable):

ocaml-4.01.0-22.4.ael7b.ppc64le

How reproducible:

100%

Steps to Reproduce:
1. Save the attached files into a directory.
2. Type 'make'
3. Type './test'

Comment 1 Richard W.M. Jones 2015-05-28 17:07:54 UTC
Created attachment 1031348 [details]
call.ml

Comment 2 Richard W.M. Jones 2015-05-28 17:08:16 UTC
Created attachment 1031349 [details]
print.c

Comment 3 Richard W.M. Jones 2015-05-28 17:08:33 UTC
Created attachment 1031350 [details]
Makefile

Comment 4 Richard W.M. Jones 2015-05-28 17:11:42 UTC
On x86-64 the output is as expected:

$ ./test 
-1
-1 -2
-1 -2 -3
-1 -2 -3 -4
-1 -2 -3 -4 -5
-1 -2 -3 -4 -5 -6
-1 -2 -3 -4 -5 -6 -7
-1 -2 -3 -4 -5 -6 -7 -8
-1 -2 -3 -4 -5 -6 -7 -8 -9
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10

Comment 6 Richard W.M. Jones 2015-05-28 18:06:59 UTC
The bug does NOT occur on ppc64 big endian
(I tested ocaml-4.01.0-22.2.el7.ppc64).

Comment 7 Richard W.M. Jones 2015-05-28 18:11:07 UTC
Created attachment 1031359 [details]
Makefile

Improved Makefile - adds a 'make clean' rule and enables -g option.

Comment 8 Richard W.M. Jones 2015-05-28 18:11:58 UTC
Stack trace for a call with 10 parameters:

#0  args10 (i1v=268699820, i2v=268699844, i3v=268699868, i4v=268699892, 
    i5v=268699916, i6v=268699940, i7v=268699964, i8v=268699988, 
    i9v=70368744172768, i10v=70367536164736) at print.c:179
#1  0x000000001001c734 in caml_c_call ()
#2  0x0000000010002b0c in camlCall__entry ()
#3  0x00000000100022f0 in caml_program ()
#4  0x000000001001c8b8 in caml_start_program ()
#5  0x000000001001cff8 in caml_main ()
#6  0x000000001000209c in main ()

Comment 9 Richard W.M. Jones 2015-05-28 20:13:08 UTC
Fix is:

diff --git a/asmcomp/power64le/proc.ml b/asmcomp/power64le/proc.ml
index 9b98577..30d4cdc 100644
--- a/asmcomp/power64le/proc.ml
+++ b/asmcomp/power64le/proc.ml
@@ -188,7 +188,7 @@ let poweropen_external_conventions first_int last_int
 let loc_external_arguments =
   match Config.system with
   | "rhapsody" -> poweropen_external_conventions 0 7 100 112
-  | "elf" | "bsd" -> calling_conventions 0 7 100 107 outgoing 48
+  | "elf" | "bsd" -> calling_conventions 0 7 100 107 outgoing 32
   | _ -> assert false
 
 let extcall_use_push = false

Comment 10 Richard W.M. Jones 2015-05-28 20:22:40 UTC
Could I have QA ack on this bug please.

Comment 11 Hu Zhang 2015-05-29 09:23:26 UTC
Reproduced this bug with 
ocaml-4.01.0-22.4.ael7b.ppc64le
kernel-3.10.0-244.ael7b.ppc64le

Reproduce step:
1. get the attachments.
2. # make
   # ./test
-1
-1 -2
-1 -2 -3
-1 -2 -3 -4
-1 -2 -3 -4 -5
-1 -2 -3 -4 -5 -6
-1 -2 -3 -4 -5 -6 -7
-1 -2 -3 -4 -5 -6 -7 -8
-1 -2 -3 -4 -5 -6 -7 -8 0
-1 -2 -3 -4 -5 -6 -7 -8 0 70366973604056

Comment 14 Richard W.M. Jones 2015-06-02 13:29:32 UTC
Test case looks good, thanks.

Comment 17 errata-xmlrpc 2015-11-19 04:49:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2185.html