[PATCH] i386: Cleanup i386/i386elf.h and align it's return convention with the SVR4 ABI

Uros Bizjak ubizjak@gmail.com
Wed Nov 4 07:59:17 GMT 2020


On Fri, Oct 30, 2020 at 9:05 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> > As observed a number of years ago in the following thread, i386/i386elf.h has not been
> > kept up to date:
> >
> > https://gcc.gnu.org/pipermail/gcc/2013-August/209981.html
> >
> > This patch does the following cleanup:
> >
> > 1. The return convention now follows the i386 and x86_64 SVR4 ABIs again. As discussed
> > in the above thread, the current return convention does not match any other target or
> > existing ABI, which is problematic since the current approach is inefficient (particularly on
> > x86_64-elf) and confuses other tools like GDB (unfortunately that thread did not lead to any
> > fix at the time).
> >
> > 2. The default version of ASM_OUTPUT_ASCII from elfos.h is used. As mentioned in the
> > cleanup of i386/sysv4.h [1] the ASM_OUTPUT_ASCII implementation then used by sysv4.h,
> > and currently used by i386elf.h, has a significantly higher computation complexity than the
> > default version provided by elfos.h.
> >
> > The patch has been tested on i386-elf and x86_64-elf hosted on x86_64-linux, fixing a
> > number failing tests that were expecting the SVR4 ABI return convention. It has also been
> > bootstrapped and tested on x86_64-pc-linux-gnu without regression.
> >
> > If approved, I'll need a maintainer to kindly commit on my behalf.
> >
> > Thanks,
> >
> > Pat Bernardi
> > Senior Software Engineer, AdaCore
> >
> > [1] https://gcc.gnu.org/pipermail/gcc-patches/2011-February/305559.html
>
> Looking at the [1], it looks that i386elf.h suffered some bitrot.
> Probably nobody cares much for {i386,x86_64}-elf nowadays.
>
> So, I think, uder reasons explained in [1], and based on your testing,
> that the patch should be committed to the mainline to fix the ABI
> issues. However, I wonder if the ABI change is severe enough to
> warrant a compile-time warning?

The difference is with the following testcase:

--cut here--
typedef int v2si __attribute__((__vector_size__(8)));

v2si test2 (void)
{
  v2si z = { 123, 456 };

  return z;
}
--cut here--

currently gcc for i386-elf target crashes when compiled w/o -mmx, and
returns in memory when compiled w/ -mmx. The latter violates i386
psABI, which specifies %mm0 as a return location for _m64 values.

The compiler, patched with your patch returns in %mm0 when compiled w/
-mmx and returns in memory when compiled w/o -mmx in the same way as
unpatched compiler, but also emits a warning about psABI violation.

So, since the unpatched compiler crashes with an example that would
make a difference, I think the patch is OK as it is.

Thanks,
Uros.


More information about the Gcc-patches mailing list