* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
@ 2024-04-02 11:29 ` rguenth at gcc dot gnu.org
2024-04-02 11:45 ` jakub at gcc dot gnu.org
` (16 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-02 11:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ABI
CC| |jakub at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The question is whether the caller misbehaves according to the ABI here?
There's likely a known alignment present we could re-instantiate with a
__builtin_assume_aligned?
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
2024-04-02 11:29 ` [Bug libquadmath/114533] " rguenth at gcc dot gnu.org
@ 2024-04-02 11:45 ` jakub at gcc dot gnu.org
2024-04-02 12:04 ` schwab@linux-m68k.org
` (15 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-02 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
From what I can see, glibc uses there the same thing as libquadmath does, so
why is it ok on the glibc side and not on the libquadmath side?
I mean
https://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/printf_fp.c;h=e75706f089bba3baabbcfb6bcf41514bad0a9dcb;hb=HEAD#l222
and
https://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/printf_fp.c;h=e75706f089bba3baabbcfb6bcf41514bad0a9dcb;hb=HEAD#l191
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
2024-04-02 11:29 ` [Bug libquadmath/114533] " rguenth at gcc dot gnu.org
2024-04-02 11:45 ` jakub at gcc dot gnu.org
@ 2024-04-02 12:04 ` schwab@linux-m68k.org
2024-04-02 12:36 ` fw at gcc dot gnu.org
` (14 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: schwab@linux-m68k.org @ 2024-04-02 12:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
Is the stack properly aligned at this point?
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (2 preceding siblings ...)
2024-04-02 12:04 ` schwab@linux-m68k.org
@ 2024-04-02 12:36 ` fw at gcc dot gnu.org
2024-04-02 13:21 ` schwab@linux-m68k.org
` (13 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: fw at gcc dot gnu.org @ 2024-04-02 12:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #4 from Florian Weimer <fw at gcc dot gnu.org> ---
This looks like a glibc bug to me.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (3 preceding siblings ...)
2024-04-02 12:36 ` fw at gcc dot gnu.org
@ 2024-04-02 13:21 ` schwab@linux-m68k.org
2024-04-02 13:41 ` schwab@linux-m68k.org
` (12 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: schwab@linux-m68k.org @ 2024-04-02 13:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2024-04-02
Ever confirmed|0 |1
--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
Without a test case it is hard to tell.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (4 preceding siblings ...)
2024-04-02 13:21 ` schwab@linux-m68k.org
@ 2024-04-02 13:41 ` schwab@linux-m68k.org
2024-04-02 17:02 ` jsm28 at gcc dot gnu.org
` (11 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: schwab@linux-m68k.org @ 2024-04-02 13:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |UNCONFIRMED
Ever confirmed|1 |0
--- Comment #6 from Andreas Schwab <schwab@linux-m68k.org> ---
Looks like the issue is that args_pa_user is not kept aligned. On the other
hand, flt128_va already uses memcpy, so it does not expect the memory to be
aligned.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (5 preceding siblings ...)
2024-04-02 13:41 ` schwab@linux-m68k.org
@ 2024-04-02 17:02 ` jsm28 at gcc dot gnu.org
2024-04-02 17:08 ` jakub at gcc dot gnu.org
` (10 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2024-04-02 17:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #7 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
Note also that in glibc, _Float128 support in printf code can only be used in
limited circumstances: either on powerpc64le, as one of the multiple supported
long double formats there, or through the sharing of the printf code with the
implementation of strfromf128.
In particular, there are no glibc printf formats corresponding directly to
_FloatN / _FloatNx types. There was support in principle at the WG14 meeting in
Strasbourg in January for having some form of printf/scanf support for such
types in C2y, but major work is still needed on the wording that was proposed
in N3184.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (6 preceding siblings ...)
2024-04-02 17:02 ` jsm28 at gcc dot gnu.org
@ 2024-04-02 17:08 ` jakub at gcc dot gnu.org
2024-04-02 17:30 ` jvdelisle at gcc dot gnu.org
` (9 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-02 17:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I guess we should go with the above patch after fixing formatting, but it isn't
enough,
printf_fphex.c has similar code.
Even in glibc which doesn't support printing _Float128 nor any other type which
would require similar alignment, the hooks only register a function to fill in
some mem and allows specification of size, but can't specify alignment.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (7 preceding siblings ...)
2024-04-02 17:08 ` jakub at gcc dot gnu.org
@ 2024-04-02 17:30 ` jvdelisle at gcc dot gnu.org
2024-04-02 17:34 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-02 17:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jvdelisle at gcc dot gnu.org
--- Comment #9 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Adding myself here as I need hex format for gfortran EX format specifiers.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (8 preceding siblings ...)
2024-04-02 17:30 ` jvdelisle at gcc dot gnu.org
@ 2024-04-02 17:34 ` jakub at gcc dot gnu.org
2024-04-02 18:26 ` doko at gcc dot gnu.org
` (7 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-02 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57853
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57853&action=edit
gcc14-pr114533.patch
Untested fix. Unfortunately, we don't have any testsuite for libquadmath, hope
it will be tested during libgfortran testing.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (9 preceding siblings ...)
2024-04-02 17:34 ` jakub at gcc dot gnu.org
@ 2024-04-02 18:26 ` doko at gcc dot gnu.org
2024-04-03 8:14 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: doko at gcc dot gnu.org @ 2024-04-02 18:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #11 from Matthias Klose <doko at gcc dot gnu.org> ---
while not a test case, that was seen when running autopkg tests of the evolver
package against glibc 2.39 packages.
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2052929
the failing evolver test is:
echo "g 5; v; r ; g 10; v;" | evolver-nox-q cube
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (10 preceding siblings ...)
2024-04-02 18:26 ` doko at gcc dot gnu.org
@ 2024-04-03 8:14 ` cvs-commit at gcc dot gnu.org
2024-04-21 4:08 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-03 8:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:8455d6f6cd43b7b143ab9ee19437452fceba9cc9
commit r14-9769-g8455d6f6cd43b7b143ab9ee19437452fceba9cc9
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Apr 3 10:02:35 2024 +0200
libquadmath: Don't assume the storage for __float128 arguments is aligned
[PR114533]
With the
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided
with
a callback to fetch the argument from va_list using va_arg into C library
provided
memory. The C library isn't told what alignment requirement it has, but we
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.
The following patch fixes that by using memcpy instead.
I haven't been able to reproduce an actual crash, tried
#include <quadmath.h>
#include <stdlib.h>
#include <stdio.h>
int main ()
{
__float128 r;
int prec = 20;
int width = 46;
char buf[128];
r = 2.0q;
r = sqrtq (r);
int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
quadmath_snprintf (buf, sizeof buf, "%Qa", r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
if (n > -1)
{
char *str = malloc (n + 1);
if (str)
{
quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
printf ("%s\n", str);
/* Prints: +1.41421356237309504880e+00 */
}
free (str);
}
printf ("%+-#*.20Qe\n", width, r);
printf ("%Qa\n", r);
printf ("%+-#46.*Qe\n", prec, r);
printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
return 0;
}
In any case, I think memcpy for loading from it is right.
2024-04-03 Simon Chopin <simon.chopin@canonical.com>
Jakub Jelinek <jakub@redhat.com>
PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.
Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (11 preceding siblings ...)
2024-04-03 8:14 ` cvs-commit at gcc dot gnu.org
@ 2024-04-21 4:08 ` cvs-commit at gcc dot gnu.org
2024-04-23 6:45 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-21 4:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:cc39bd532d4de1ba0b2785246fb6fdd63ec2e92c
commit r13-8625-gcc39bd532d4de1ba0b2785246fb6fdd63ec2e92c
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Apr 3 10:02:35 2024 +0200
libquadmath: Don't assume the storage for __float128 arguments is aligned
[PR114533]
With the
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided
with
a callback to fetch the argument from va_list using va_arg into C library
provided
memory. The C library isn't told what alignment requirement it has, but we
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.
The following patch fixes that by using memcpy instead.
I haven't been able to reproduce an actual crash, tried
#include <quadmath.h>
#include <stdlib.h>
#include <stdio.h>
int main ()
{
__float128 r;
int prec = 20;
int width = 46;
char buf[128];
r = 2.0q;
r = sqrtq (r);
int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
quadmath_snprintf (buf, sizeof buf, "%Qa", r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
if (n > -1)
{
char *str = malloc (n + 1);
if (str)
{
quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
printf ("%s\n", str);
/* Prints: +1.41421356237309504880e+00 */
}
free (str);
}
printf ("%+-#*.20Qe\n", width, r);
printf ("%Qa\n", r);
printf ("%+-#46.*Qe\n", prec, r);
printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
return 0;
}
In any case, I think memcpy for loading from it is right.
2024-04-03 Simon Chopin <simon.chopin@canonical.com>
Jakub Jelinek <jakub@redhat.com>
PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.
Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
(cherry picked from commit 8455d6f6cd43b7b143ab9ee19437452fceba9cc9)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (12 preceding siblings ...)
2024-04-21 4:08 ` cvs-commit at gcc dot gnu.org
@ 2024-04-23 6:45 ` jakub at gcc dot gnu.org
2024-06-11 10:37 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-23 6:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 13.3 too.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (13 preceding siblings ...)
2024-04-23 6:45 ` jakub at gcc dot gnu.org
@ 2024-06-11 10:37 ` cvs-commit at gcc dot gnu.org
2024-06-11 10:51 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-11 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:9987fe67cf6211515d8ebf6528cc83c77dfb5bf3
commit r12-10517-g9987fe67cf6211515d8ebf6528cc83c77dfb5bf3
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Apr 3 10:02:35 2024 +0200
libquadmath: Don't assume the storage for __float128 arguments is aligned
[PR114533]
With the
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided
with
a callback to fetch the argument from va_list using va_arg into C library
provided
memory. The C library isn't told what alignment requirement it has, but we
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.
The following patch fixes that by using memcpy instead.
I haven't been able to reproduce an actual crash, tried
#include <quadmath.h>
#include <stdlib.h>
#include <stdio.h>
int main ()
{
__float128 r;
int prec = 20;
int width = 46;
char buf[128];
r = 2.0q;
r = sqrtq (r);
int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
quadmath_snprintf (buf, sizeof buf, "%Qa", r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
if (n > -1)
{
char *str = malloc (n + 1);
if (str)
{
quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
printf ("%s\n", str);
/* Prints: +1.41421356237309504880e+00 */
}
free (str);
}
printf ("%+-#*.20Qe\n", width, r);
printf ("%Qa\n", r);
printf ("%+-#46.*Qe\n", prec, r);
printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
return 0;
}
In any case, I think memcpy for loading from it is right.
2024-04-03 Simon Chopin <simon.chopin@canonical.com>
Jakub Jelinek <jakub@redhat.com>
PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.
Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
(cherry picked from commit 8455d6f6cd43b7b143ab9ee19437452fceba9cc9)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (14 preceding siblings ...)
2024-06-11 10:37 ` cvs-commit at gcc dot gnu.org
@ 2024-06-11 10:51 ` jakub at gcc dot gnu.org
2024-06-20 13:22 ` cvs-commit at gcc dot gnu.org
2024-06-20 13:39 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-11 10:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed for 12.4+ too.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (15 preceding siblings ...)
2024-06-11 10:51 ` jakub at gcc dot gnu.org
@ 2024-06-20 13:22 ` cvs-commit at gcc dot gnu.org
2024-06-20 13:39 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-20 13:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
--- Comment #17 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:df41dbfd22528b1241668af21a979204b876fb67
commit r11-11500-gdf41dbfd22528b1241668af21a979204b876fb67
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Apr 3 10:02:35 2024 +0200
libquadmath: Don't assume the storage for __float128 arguments is aligned
[PR114533]
With the
register_printf_type/register_printf_modifier/register_printf_specifier
APIs the C library is just told the size of the argument and is provided
with
a callback to fetch the argument from va_list using va_arg into C library
provided
memory. The C library isn't told what alignment requirement it has, but we
were
using direct load of a __float128 value from that memory which assumes
__alignof (__float128) alignment.
The following patch fixes that by using memcpy instead.
I haven't been able to reproduce an actual crash, tried
#include <quadmath.h>
#include <stdlib.h>
#include <stdio.h>
int main ()
{
__float128 r;
int prec = 20;
int width = 46;
char buf[128];
r = 2.0q;
r = sqrtq (r);
int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: +1.41421356237309504880e+00 */
quadmath_snprintf (buf, sizeof buf, "%Qa", r);
if ((size_t) n < sizeof buf)
printf ("%s\n", buf);
/* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
if (n > -1)
{
char *str = malloc (n + 1);
if (str)
{
quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
printf ("%s\n", str);
/* Prints: +1.41421356237309504880e+00 */
}
free (str);
}
printf ("%+-#*.20Qe\n", width, r);
printf ("%Qa\n", r);
printf ("%+-#46.*Qe\n", prec, r);
printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r);
return 0;
}
In any case, I think memcpy for loading from it is right.
2024-04-03 Simon Chopin <simon.chopin@canonical.com>
Jakub Jelinek <jakub@redhat.com>
PR libquadmath/114533
* printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy
__float128 out of args.
* printf/printf_fphex.c (__quadmath_printf_fphex): Likewise.
Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
(cherry picked from commit 8455d6f6cd43b7b143ab9ee19437452fceba9cc9)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args
2024-03-30 12:48 [Bug libquadmath/114533] New: libquadmath: printf: fix misaligned access on args doko at gcc dot gnu.org
` (16 preceding siblings ...)
2024-06-20 13:22 ` cvs-commit at gcc dot gnu.org
@ 2024-06-20 13:39 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-20 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114533
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |11.5
--- Comment #18 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.5 as well.
^ permalink raw reply [flat|nested] 19+ messages in thread