Bug 79484 - Segfault when executing a test in Power8
Summary: Segfault when executing a test in Power8
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-13 08:56 UTC by smateo
Modified: 2017-03-08 07:37 UTC (History)
3 users (show)

See Also:
Host:
Target: powerpc64le
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test (748 bytes, application/gzip)
2017-02-13 08:56 UTC, smateo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description smateo 2017-02-13 08:56:20 UTC
Created attachment 40723 [details]
test

Hi,

I'm getting a segfault every time that I execute a simple testcase (attached to this ticket) compiled and linked with gfortran in a Power8 machine.
The same test, compiled and linked also with gfortran, runs fine in x86_64 architectures. I also detected that changing the optimizations flags from -O0 to -O2 makes it work.

These are the versions of gfortran I tested (none of them worked when compiling with -O0):
* GNU Fortran (GCC) 4.9.3
* GNU Fortran (GCC) 5.1.0
* GNU Fortran (GCC) 7.0.1 20170209 (experimental)


About the test: what I'm doing is capturing the addresses of some variables in a derived type variable and calling a Fortran subroutine with this derived type variable as an argument (among others).
This Fortran subroutine calls to a C function, passing all the addresses captured in the derived type variable  and also a pointer to a Fortran subroutine as arguments (note that everything is passed by value).
Finally, this C function calls to the function passed as an argument with all the other parameters as arguments.


About the crash: I have been debugging this application for a while and I detected that some variables are corrupted as soon as we enter to the last Fortran function (the one that it's called from a C function).

Thanks,

Sergi Mateo
Comment 1 Segher Boessenkool 2017-03-07 16:56:03 UTC
Could someone who knows about Fortran please look at this?
Comment 2 Jerry DeLisle 2017-03-07 21:03:04 UTC
Looking
Comment 3 Jerry DeLisle 2017-03-07 21:50:47 UTC
Using LOC is not the right way to do these things. You should use bind(c) on the fortran side.

I think you can google help with this.

Power8 systems are less forgiving then others. I dont get any errors on my system here which is x86_64 linux.

Also ask on comp.lang.fortran and explain what you are actually trying to do. You do not need your derived type at all to pass arguments to a C function.
Comment 4 smateo 2017-03-08 07:02:11 UTC
Hi Jerry,

This code is a simplification of a code that our tool generates to support a tasking programming model. I know that I don't need a derived type to call a C function. If I recall correctly, I needed to reproduce this problem.

Of course using the ISO_C_BINDINGS interoperability module and BIND(C) would be a more appropriate way of doing it, but they were introduced in F2003. I guess that a code like the one I attached should work in the pre-interoperability era (we may need to remove the VALUE attributes since this attribute was introduced also in F2003).

I decided to open this ticket because, as you said, this code works nicely in x86_64 (I also tried in some ARM machines and also worked), and because changing the optimization level flags made it work.

I also tried to compile this code with XLF and works nicely.

Best regards,
Sergi
Comment 5 kargls 2017-03-08 07:37:09 UTC
(In reply to smateo from comment #4)

> 
> Of course using the ISO_C_BINDINGS interoperability module and BIND(C) would
> be a more appropriate way of doing it, but they were introduced in F2003. I
> guess that a code like the one I attached should work in the
> pre-interoperability era (we may need to remove the VALUE attributes since
> this attribute was introduced also in F2003).

Using ISO C binding is the only appropriate way to interface
Fortran and C  All other methods require the user to understand
what they are doing on any particular architecture.  It should
be noted that 2017-2003 is 14 years.  It's not as-if Fortran 
2003 was released 6 month ago.

> I decided to open this ticket because, as you said, this code works nicely
> in x86_64 (I also tried in some ARM machines and also worked), and because
> changing the optimization level flags made it work.

Your code worked because it aligns with a specific target model.
Does power8 have the exact architecture as x86-64?