Deutsch   English   Français   Italiano  
<vlrrrc$6pr1$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Thomas Koenig <tkoenig@netcologne.de>
Newsgroups: comp.arch
Subject: Re: Calling conventions (particularly 32-bit ARM)
Date: Fri, 10 Jan 2025 19:19:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <vlrrrc$6pr1$1@dont-email.me>
References: <vlgngv$1ks4a$1@dont-email.me>
 <4903307dfcce354508c9fc016a4c1ea1@www.novabbs.org>
 <jwv34htql17.fsf-monnier+comp.arch@gnu.org>
 <2025Jan8.230846@mips.complang.tuwien.ac.at>
 <jwvr05cq4tx.fsf-monnier+comp.arch@gnu.org>
 <2025Jan9.082357@mips.complang.tuwien.ac.at> <vlrm00$5nlr$1@dont-email.me>
Injection-Date: Fri, 10 Jan 2025 20:19:08 +0100 (CET)
Injection-Info: dont-email.me; posting-host="aa71e41b32e1466f20ae5fbfaad14c66";
	logging-data="223073"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1++7tvdLV3Fz/ON6pgUZ7f4awOcpWqG2X0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:xnY9eVX9dB3/ge4sOUzciCB3rGU=
Bytes: 3482

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.