* Jeff Law:

> This is best addressed by changing GCC itself to know about the
> different ABIs.  Trying to tackle in ASMs is going to be painful,
> particularly since your asms change the stack pointer and that's
> generally verboten for an ASM.

Standard practice is to use generic assembler trampolines for the thorny
cases.  We use them in glibc for those system calls which have
incompatible calling conventions, and I believe UEFI and WINE use them,
too.

It would be nice to teach GCC about these calling conventions, but even
for much larger use cases, that simply does not happen in practice. 8-(
For example, on POWER, the condition register is used to indicate
errors.  Instead of using that directly, we need to store that in a
register, via mfcr:

0000000000000000 <__GI___getdents64>:
   0:   addis   r2,r12,0
                        0: R_PPC64_REL16_HA     .TOC.
   4:   addi    r2,r2,0
                        4: R_PPC64_REL16_LO     .TOC.+0x4
   8:   li      r0,202
   c:   sc      
  10:   mfcr    r0
  14:   andis.  r9,r0,4096
  18:   beqlr   
  1c:   addis   r9,r2,0
                        1c: R_PPC64_GOT_TPREL16_HA      __libc_errno
  20:   ld      r9,0(r9)
                        20: R_PPC64_GOT_TPREL16_LO_DS   __libc_errno
  24:   add     r9,r9,r13
                        24: R_PPC64_TLS __libc_errno
  28:   stw     r3,0(r9)
  2c:   li      r3,-1
  30:   blr

Ideally, the mfcr, andis, beqlr instructions would just be a bclr
instruction.

Thanks,
Florian

Reply via email to