libgo patch committed: Use a C function to call mmap

1 view
Skip to first unread message

Ian Lance Taylor

unread,
Jun 20, 2023, 12:57:54 PM6/20/23
to gcc-patches, gofrontend-dev, Sören Tempel
This libgo patches changes the runtime pacakge to use a C function to call mmap.

The final argument to mmap, of type off_t, varies. In
https://go.dev/cl/445375
(https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html)
we changed it to always use the C off_t type, but that broke 32-bit
big-endian Linux systems. On those systems, using the C off_t type
requires calling the mmap64 function. In C this is automatically
handled by the <sys/mman.h> file. In Go, we would have to change the
magic //extern comment to call mmap64 when appropriate. Rather than
try to get that right, we instead go through a C function that uses C
implicit type conversions to pick the right type.

This fixes https://gcc.gnu.org/PR110297.

Bootstrapped and tested on x86_64-pc-linux-gnu and
powerpc-pc-linux-gnu (32-bit and 64-bit). Committed to trunk and GCC
13 branch.

Ian
patch.txt

Andreas Schwab

unread,
Jun 20, 2023, 2:35:30 PM6/20/23
to Ian Lance Taylor via Gcc-patches, gofrontend-dev, Ian Lance Taylor, Sören Tempel
On Jun 20 2023, Ian Lance Taylor via Gcc-patches wrote:

> This libgo patches changes the runtime pacakge to use a C function to call mmap.
>
> The final argument to mmap, of type off_t, varies. In
> https://go.dev/cl/445375
> (https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html)
> we changed it to always use the C off_t type, but that broke 32-bit
> big-endian Linux systems.

This has nothing to do with big-endian, armv7 isn't big-endian.

--
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."

Ian Lance Taylor

unread,
Jun 20, 2023, 3:37:16 PM6/20/23
to Andreas Schwab, Ian Lance Taylor via Gcc-patches, gofrontend-dev, Sören Tempel
On Tue, Jun 20, 2023 at 11:35 AM Andreas Schwab <sch...@linux-m68k.org> wrote:
>
> On Jun 20 2023, Ian Lance Taylor via Gcc-patches wrote:
>
> > This libgo patches changes the runtime pacakge to use a C function to call mmap.
> >
> > The final argument to mmap, of type off_t, varies. In
> > https://go.dev/cl/445375
> > (https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html)
> > we changed it to always use the C off_t type, but that broke 32-bit
> > big-endian Linux systems.
>
> This has nothing to do with big-endian, armv7 isn't big-endian.

OK, but I think that it does have something to do with big-endian.
The bug was that on some 32-bit systems it was passing a 64-bit value
to a function that expected a 32-bit value. The problem didn't show
up on 32-bit x86 because it is little-endian, and did show up on
32-bit PPC because it is big-endian. I guess the armv7 case was
failing for a different reason.

Ian

Andreas Schwab

unread,
Jun 20, 2023, 5:21:12 PM6/20/23
to Ian Lance Taylor, Ian Lance Taylor via Gcc-patches, gofrontend-dev, Sören Tempel
On Jun 20 2023, Ian Lance Taylor wrote:

> OK, but I think that it does have something to do with big-endian.
> The bug was that on some 32-bit systems it was passing a 64-bit value
> to a function that expected a 32-bit value. The problem didn't show
> up on 32-bit x86 because it is little-endian, and did show up on
> 32-bit PPC because it is big-endian. I guess the armv7 case was
> failing for a different reason.

Not failing is no proof for correctness. It fails everywhere for the
same reason.

Cherry Mui

unread,
Jun 20, 2023, 11:33:59 PM6/20/23
to Ian Lance Taylor, Andreas Schwab, Ian Lance Taylor via Gcc-patches, gofrontend-dev, Sören Tempel
I think there is a calling convention issue. On 32-bit ARM, for the case of mmap, if the last argument is 32-bit, it is passed 4 bytes at sp+4. If it is 64-bit, the offset is aligned and it is stored as 8 bytes at sp+8. So if the callee tries to read at sp+4, it gets the wrong value, even for little endian. On 32-bit x86 it doesn't seem to have that alignment padding.
 
Reply all
Reply to author
Forward
0 new messages