long long on 32-bit machines
Hi all,
Does anyone happen to know if there are *any* 32-bit architectures (on which Linux runs) for which the ABI for a "long long" is different from passing two "longs" in the appropriate order, i.e. (hi,lo) for bigendian or (lo,hi) for littleendian?
I'd like to switch klibc to use the 64-bit file ABI thoughout, but it's a considerable porting effort, and I'm trying to figure out how to best manage it.
-hpa
Quoted 6 lines · H. Peter Anvin
Hi all,
Does anyone happen to know if there are *any* 32-bit architectures (on which Linux runs) for which the ABI for a "long long" is different from passing two "longs" in the appropriate order, i.e. (hi,lo) for bigendian or (lo,hi) for littleendian?
I'd like to switch klibc to use the 64-bit file ABI thoughout, but it's a considerable porting effort, and I'm trying to figure out how to best manage it.
I don't know how it is for GCC, but when using the Sun compiler, "long long" for 32-bit is low-high, while "long long" (or just long) for 64-bit is high-low. This has been an annoyance to me. :)
Quoted 3 lines · On Wed, 28 Jan 2004 14:12:50 -0500 Timothy Miller <[email protected]> wrote:
I don't know how it is for GCC, but when using the Sun compiler, "long long" for 32-bit is low-high, while "long long" (or just long) for 64-bit is high-low. This has been an annoyance to me. :)
For 64-bit it goes into a single 64-bit register. And for 32-bit the sequence is high 32-bits low 32-bits. At least on Sparc.
extern void foo(long long a);
void bar(void)
{
foo(1);
}
/* gcc -m32 -S -o bar.s bar.c */
bar:
!#PROLOGUE# 0
save %sp, -104, %sp
!#PROLOGUE# 1
mov 0, %o0
mov 1, %o1
call foo, 0
nop
nop
ret
restore
/* gcc -m64 -S -o bar.s bar.c */
bar:
!#PROLOGUE# 0
save %sp, -192, %sp
!#PROLOGUE# 1
mov 1, %o0
call foo, 0
nop
nop
return %i7+8Quoted 4 lines · H. Peter Anvin
Does anyone happen to know if there are *any* 32-bit architectures (on which Linux runs) for which the ABI for a "long long" is different from passing two "longs" in the appropriate order, i.e. (hi,lo) for bigendian or (lo,hi) for littleendian?
Are you are talking about passing arguments to a function? PPC32 passes long long arguments in two registers in the order you would expect (hi, lo), BUT you have to use an odd/even register pair. In other words, if you have a function like this:
int foo(int a, long long b)
then a will be passed in r3 and b will be passed in r5 and r6, and r4 will be unused.
Regards,
Paul.
Quoted 11 lines · Paul Mackerras
Quoted 1 line · H. Peter Anvin
Does anyone happen to know if there are *any* 32-bit architectures (on which Linux runs) for which the ABI for a "long long" is different from passing two "longs" in the appropriate order, i.e. (hi,lo) for bigendian or (lo,hi) for littleendian?
Are you are talking about passing arguments to a function? PPC32 passes long long arguments in two registers in the order you would expect (hi, lo), BUT you have to use an odd/even register pair. In other words, if you have a function like this:
Quoted 5 lines
int
foo(int a, long long b)then a will be passed in r3 and b will be passed in r5 and r6, and r4 will be unused.
Does system calls follow the same convention?
-hpa
Quoted 1 line · H. Peter Anvin
Does system calls follow the same convention?
I have just looked up in glibc what architectures need this kind of handling and found that there is no easy rule. The good news is that none of (hppa m68k s390 sparc x86_64 alpha cris i386 sparc64 arm ia64) are doing this.
AFAICS, the padding is done for exactly these system calls:
ppc: truncate64, ftruncate64, pread64, pwrite64
mips: truncate64, ftruncate64, pread64, pwrite64
sh: pread64, pwrite64
fadvise64_64 is another story:
mips does no padding, ppc32 reorders the arguments (int fd, int advise, off64_t offset, off64_t len) and s390 passes a struct, for the reason Uli already explained.
Arnd <><
Quoted 11 lines · Arnd Bergmann
Quoted 1 line · H. Peter Anvin
Does system calls follow the same convention?
I have just looked up in glibc what architectures need this kind
of handling and found that there is no easy rule. The good news
is that none of (hppa m68k s390 sparcx86_64alpha cris i386 sparc64 arm ia64) are doing this.AFAICS, the padding is done for exactly these system calls:
Quoted 8 lines
ppc: truncate64, ftruncate64, pread64, pwrite64
mips: truncate64, ftruncate64, pread64, pwrite64
sh: pread64, pwrite64
fadvise64_64is another story: mips does no padding, ppc32 reorders the arguments (int fd, int advise,off64_toffset,off64_tlen) and s390 passes a struct, for the
reason Uli already explained.
<BARF>
I hate ad hockery :( Yet more evidence for the need of a formal description of the ABI in the kernel.
-hpa
Quoted 1 line · H. Peter Anvin
Does system calls follow the same convention?
Yes. A system call with a long long argument will be handled by a C routine in the kernel. The system call arguments in r3 - r8 are unchanged by the system call exception entry code and end up being the arguments to the C routine.
Paul.