Sujet : Re: Calling conventions (particularly 32-bit ARM)
De : tkoenig (at) *nospam* netcologne.de (Thomas Koenig)
Groupes : comp.archDate : 10. Jan 2025, 20:19:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlrrrc$6pr1$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : slrn/1.0.3 (Linux)
David Brown <
david.brown@hesbynett.no> schrieb:
How many people actually want to use code where some functions are
called with an incorrect number of parameters? Such code is /broken/.
Agreed (at least in priciple).
If it ever gave results that the original users were happy with, it is
by luck - no matter what ABI you have for your new architecture and new
tools, it's pure luck whether things work or not in any sense.
It gets worse when the code in question has been around for decades,
and is widely used. Some ABIs, such as the x86-64 psABI, are very
forgiving of errors.
So the best you can do for your prospective customers is tell them that
you prioritise the results for correct code and help them with tools to
find mistakes in their ancient broken code.
Now, you can also tell them to use LTO for checks for any old
software.
Example:
$ cat main.c
#include <stdio.h>
int foo(int);
int main()
{
printf ("%d\n", foo(42));
}
$ cat foo.c
int foo (int a, int b)
{
return a + 2;
}
$ gcc -O2 -flto main.c foo.c
main.c:3:5: warning: type of 'foo' does not match original declaration [-Wlto-type-mismatch]
3 | int foo(int);
| ^
foo.c:1:5: note: type mismatch in parameter 2
1 | int foo (int a, int b)
| ^
foo.c:1:5: note: type 'int' should match type 'void'
foo.c:1:5: note: 'foo' was previously declared here
This also works when the declaration is hidden (for example when
the violating code is emitted by a compiler for another language
in the same compiler collection):
$ cat main.f90
program main
implicit none
interface
function foo(a) result(ret) bind(c)
use, intrinsic :: iso_c_binding, only: c_int
integer(c_int), value :: a
integer(c_int) :: ret
end function foo
end interface
print *,foo(42)
end program main
$ gfortran -O2 -flto main.f90 foo.c
main.f90:10:17: warning: type of 'foo' does not match original declaration [-Wlto-type-mismatch]
10 | print *,foo(42)
| ^
foo.c:1:5: note: type mismatch in parameter 2
1 | int foo (int a, int b)
| ^
foo.c:1:5: note: type 'int' should match type 'void'
foo.c:1:5: note: 'foo' was previously declared here
Excuses are running out.