Hi! The following testcase FAILs when configured with --with-long-double-format=ieee . Only happens in the -std=c* modes, not the GNU modes; while the glibc headers have __asm redirects of vsnprintf and __vsnprinf_chk to __vsnprintfieee128 and __vsnprintf_chkieee128, the vsnprintf fortification extern inline gnu_inline always_inline wrapper calls __builtin_vsnprintf_chk and we actually emit a call to __vsnprinf_chk (i.e. with IBM extended long double) instead of __vsnprintf_chkieee128.
rs6000_mangle_decl_assembler_name already had cases for *printf and *scanf, so this just adds another case for *printf_chk. *scanf_chk doesn't exist. __ prefixing isn't done because *printf_chk already starts with __. Bootstrapped/regtested on powerpc64le-linux, ok for trunk? 2022-02-04 Jakub Jelinek <ja...@redhat.com> PR target/104380 * config/rs6000/rs6000.cc (rs6000_mangle_decl_assembler_name): Also adjust mangling of __builtin*printf_chk. * gcc.dg/pr104380.c: New test. --- gcc/config/rs6000/rs6000.cc.jj 2022-01-28 10:01:41.224837656 +0100 +++ gcc/config/rs6000/rs6000.cc 2022-02-04 12:31:27.651715472 +0100 @@ -28228,6 +28228,7 @@ rs6000_mangle_decl_assembler_name (tree { size_t printf_len = strlen ("printf"); size_t scanf_len = strlen ("scanf"); + size_t printf_chk_len = strlen ("printf_chk"); if (len >= printf_len && strcmp (name + len - printf_len, "printf") == 0) @@ -28237,6 +28238,10 @@ rs6000_mangle_decl_assembler_name (tree && strcmp (name + len - scanf_len, "scanf") == 0) newname = xasprintf ("__isoc99_%sieee128", name); + else if (len >= printf_chk_len + && strcmp (name + len - printf_chk_len, "printf_chk") == 0) + newname = xasprintf ("%sieee128", name); + else if (name[len - 1] == 'l') { bool uses_ieee128_p = false; --- gcc/testsuite/gcc.dg/pr104380.c.jj 2022-02-04 12:51:50.152643364 +0100 +++ gcc/testsuite/gcc.dg/pr104380.c 2022-02-04 12:53:25.092317741 +0100 @@ -0,0 +1,32 @@ +/* PR target/104380 */ +/* This test needs runtime that provides __*_chk functions. */ +/* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */ +/* { dg-options "-O2 -std=c99" } */ + +#define FORTIFY_SOURCE 2 +#include <stdio.h> +#include <stdarg.h> + +static char buf[4096]; +static char gfmt[] = "%Lg"; + +static int __attribute__ ((noipa)) +foo (char *str, const char *fmt, ...) +{ + int ret; + va_list ap; + va_start (ap, fmt); + ret = vsnprintf (str, 4096, fmt, ap); + va_end (ap); + return ret; +} + +int +main () +{ + long double dval = 128.0L; + int ret = foo (buf, gfmt, dval); + if (ret != 3 || __builtin_strcmp (buf, "128") != 0) + __builtin_abort (); + return 0; +} Jakub