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
Could someone who knows about Fortran please look at this?
Looking
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.
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
(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?