You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is the C ABI enforced by the toolchaain, the psABI which is the ABI for the particular platform defines things like the calling convention. Then there is another ABI which is kind of the function compatibility ABI that is ill defined and not written down anywhere and this is part of it. One could make an argument that this should be part of the C ABI but C is old, poorly specified, there isn’t much interest in it and therefore few resources dedicated to it so it isn’t likely to move forward. The general sense is C VLAs are a bad part of the language, they are probably under specified and really people shouldn’t use them. This is why C99 VLAs were never adopted into C++ there are better ways to do this kind of thing. That being said there may be some efforts to actually sort out this in C23 but the RH guys are not really hopeful http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0009r10.html
Now so long as we understand that we are not talking about “the C ABI” or the psABI and we are just talking about the “function compatibility ABI” then we can define two rules which should determine if the functions are compatible:
for VLAs the array bounds need to be the same. This means both type and value. In DWARF there are two ways to specify this. One is just to supply the upper bound in which case the lower bound is assumed based upon the language since this is C you can just assume 0. The other explicitly sets both the upper and lower bounds. IIRC LLVM does this in some cases.
when the value of an array bound is not a constant but stored in a variable then both the location of the variable that defines the array bound needs to be in the same location. You can derive this from the DWARF but the information is not in the same DWARF info section it is in the location lists which are pointed to by the DWARF information.
You can tell the difference between:
int get(int m, int n, int a[m][n], int x, int y);
int get(int m, int n, int a[n][m], int x, int y);
but you have to look carefully at the debuginfo. The real difference is in the location lists.
The fact that this a variable means that we have to go dig in the location lists and make sure that the variable that defines the array bounds is in the same location as the function expects it to be.
[ 8a] variable abbrev: 5
type (ref4) [ b2]
artificial (flag_present) yes
location (sec_offset) location list [ 22]
GNU_locviews (sec_offset) location list [ 1e]
Thus we get this difference when we dig through the location lists.
This may crop up in other languages that support different constructs. Luckily C++ is not subject to this problem.
Does this all make sense to everybody? It boils down to: “array bounds types and vaalues must be the same” and “when array bounds are specified in variables their locations must be the same” then we can agree that it would be nice to have this in the C ABI but it isn’t likely going to end up there. VLAs are bad and not perfectly specified but it is 20 years too late to change them. Use C++ with vectors and arrays instead. If that is not good enough use std::span or mdspan https://github.com/kokkos/mdspan
The text was updated successfully, but these errors were encountered:
There is the C ABI enforced by the toolchaain, the psABI which is the ABI for the particular platform defines things like the calling convention. Then there is another ABI which is kind of the function compatibility ABI that is ill defined and not written down anywhere and this is part of it. One could make an argument that this should be part of the C ABI but C is old, poorly specified, there isn’t much interest in it and therefore few resources dedicated to it so it isn’t likely to move forward. The general sense is C VLAs are a bad part of the language, they are probably under specified and really people shouldn’t use them. This is why C99 VLAs were never adopted into C++ there are better ways to do this kind of thing. That being said there may be some efforts to actually sort out this in C23 but the RH guys are not really hopeful http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0009r10.html
Now so long as we understand that we are not talking about “the C ABI” or the psABI and we are just talking about the “function compatibility ABI” then we can define two rules which should determine if the functions are compatible:
This is important because there may be internal checks within the function that aare specified or optimized out based upon the array bounds. One good example of this is statically defined VLAs https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html
You can tell the difference between:
but you have to look carefully at the debuginfo. The real difference is in the location lists.
The fact that this a variable means that we have to go dig in the location lists and make sure that the variable that defines the array bounds is in the same location as the function expects it to be.
Thus we get this difference when we dig through the location lists.
This may crop up in other languages that support different constructs. Luckily C++ is not subject to this problem.
Does this all make sense to everybody? It boils down to: “array bounds types and vaalues must be the same” and “when array bounds are specified in variables their locations must be the same” then we can agree that it would be nice to have this in the C ABI but it isn’t likely going to end up there. VLAs are bad and not perfectly specified but it is 20 years too late to change them. Use C++ with vectors and arrays instead. If that is not good enough use std::span or mdspan https://github.com/kokkos/mdspan
The text was updated successfully, but these errors were encountered: