gcc-darwin-arm64
gcc-darwin-arm64 copied to clipboard
darwinpcs d.3 is not yet implemented.
from the README " D.3 From [2] : The general ABI specifies that it is the callee’s responsibility to sign or zero-extend arguments having fewer than 32 bits, and that unused bits in a register are unspecified. In iOS, however, the caller must perform such extensions, up to 32 bits.
This apparently conflicts with the D.2 above and thus can only be applied to values passed in registers? " [it would appear that the trailing comment is correct, this is only applied to values passed in registers]
following test-case demonstrates (comparing the codegen for clang c.f. gcc). GCC is generating self-consistent code - but according to the general ABI which means that when calling clang-built functions (e.g. the system) we will not be extending the small values appropriately.
__attribute__((__noinline__))
int
foo (char a, unsigned char b)
{
return a == b ? 1 : 0;
}
__attribute__((__noinline__))
int
bar (short a, unsigned short b)
{
return a == b ? 1 : 0;
}
void pop (char *, unsigned char *, short *, unsigned short *);
int main ()
{
char a;
unsigned char b;
short c;
unsigned short d;
pop (&a, &b, &c, &d);
int result = foo (a, b);
result += bar (c, d);
return result;
}
$ cat clang.c
int
foo (char a, unsigned char b)
{
return a == b ? 1 : 0;
}
int
bar (short a, unsigned short b)
{
return a == b ? 1 : 0;
}
void pop (char *a, unsigned char *b, short *c, unsigned short *d)
{
;
}
$ cat gcc.c
int foo (char, unsigned char);
int bar (short, unsigned short);
int main ()
{
char a = -42;
unsigned char b = -42;
short c = -42;
unsigned short d = -42;
int result = foo (a, b);
result += bar (c, d);
return result;
}
$ clang -c clang.c -O1 && gcc gcc.c clang.o && ./a.out ; echo $?
2
I'm surprised we haven't seen it in the wild so far…
I'm surprised we haven't seen it in the wild so far…
Most likely because most C library function takes either an int, a pointer, or size_t due to historical K&R C unprototyped functions. So most C code will just work correctly.
initial implementation https://github.com/iains/gcc-darwin-arm64/commit/fe2fb746c8029a87567ce95eb8fa9fbbd4892832