j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

Require ABI compatibility in ISO_Fortran_binding.h #247

Open awvwgk opened 2 years ago

awvwgk commented 2 years ago

Following a discussion on the Fortran-lang discourse (https://fortran-lang.discourse.group/t/2652) about ABI compatibility with ISO_Fortranbinding.h, I want to open this thread to discuss whether it is possible / feasible to require ABI compatibility for the `CFI*` procedures and descriptors in a future revision on the standard.

Motivation

Proposed changes

This is my first time contributing here. I'm looking forward to your feedback.

klausler commented 2 years ago

You would also need to:

See https://github.com/llvm/llvm-project/blob/main/flang/include/flang/ISO_Fortran_binding.h for a complete example.

awvwgk commented 2 years ago
  • convince vendors to make necessary incompatible changes to their products
  • convince their users to recompile their codes

Indeed, this is an issue. It would be ABI breakage rather than API breakage, given that ABI compatibility is not guaranteed at the moment it might be feasible and still be a backwards compatible change in the standard. Correct?

klausler commented 2 years ago
  • convince vendors to make necessary incompatible changes to their products
  • convince their users to recompile their codes

Indeed, this is an issue. It would be ABI breakage rather than API breakage, given that ABI breakage is not guaranteed at the moment it might be feasible and still be a backwards compatible change in the standard. Correct?

I don't understand your question; but changing any of the values, types, or component orders in a compiler's ISO_Fortran_binding.h file is going to be a change that would prevent previously-compiled code from successfully linking with newly-compiled code when C interoperability is being used. (Or even when it is not -- f18 uses this "interoperable" descriptor as its only Fortran data descriptor as well.)

If J3 had done a better job defining ISO_Fortran_binding.h with specific types, values, and struct layouts, we would have be able to use interoperable interfaces to link Fortran code compiled with different Fortran compilers, not just with C. So what you propose would be great, had it been done 14 year ago. At this point, though, it seems vanishingly unlikely that you would be able to convince any vendor to change their ISO_Fortran_binding.h file.

ivan-pi commented 9 months ago

Here's how the CFI_cdesc_t struct looks like in a few major compilers:

// gfortran                 // flang                    // NAG                      // Intel         
void *base_addr;            void *base_addr;            void *base_addr;            void * base_addr;
size_t elem_len;            size_t elem_len;            size_t elem_len;            size_t elem_len;
int version;                int version;                int version;                int version;
CFI_rank_t rank;            CFI_rank_t rank;            CFI_rank_t rank;            CFI_attribute_t attribute;
CFI_attribute_t attribute;  CFI_type_t type;            CFI_type_t type;            CFI_rank_t rank;
CFI_type_t type;            CFI_attribute_t attribute;  CFI_attribute_t attribute;  CFI_type_t type;
CFI_dim_t dim[];            unsigned char f18Addendum;  size_t len,offset;          intptr_t intel_flags;
                            CFI_dim_t dim[];            int64_t *dtp;               intptr_t intel_reserved1;
                                                        void *sig;                  intptr_t intel_reserved2;
                                                        void *reserved;             CFI_dim_t dim[];
                                                        int64_t ireserved;
                                                        CFI_dim_t dim[];

Essentially none of them are compatible.

reinh-bader commented 6 months ago

Also there is a fundamental roadblock here in that different Fortran compilers might have different C companion processors that might be non-compatible.