From: Jeremie Courreges-Anglas Subject: gcc/11 libestdc++: drop sprintf ld warnings To: ports@openbsd.org Cc: Pascal Stumpf Date: Sun, 14 Sep 2025 17:51:17 +0200 ld.bfd spots it with a "hello, world!" program, ld.lld doesn't. The sprintf_ld() change is adapted from code already in lang/gcc/15. Since that function is internal, it's not a problem. With this, eg++ (-fuse-ld=bfd) doesn't warn about the sprintf use. This matters for some overly picky ports that fail to find a working C++ compiler when ld(1) spits any warning. Diff for gcc/15 to follow. ok? Index: Makefile =================================================================== RCS file: /home/cvs/ports/lang/gcc/11/Makefile,v diff -u -p -r1.52 Makefile --- Makefile 13 Sep 2025 14:45:15 -0000 1.52 +++ Makefile 14 Sep 2025 15:41:14 -0000 @@ -17,7 +17,7 @@ USE_NOEXECONLY = Yes V = 11.2.0 FULL_VERSION = $V FULL_PKGVERSION = $V -REVISION = 18 +REVISION = 19 ADASTRAP-amd64 = adastrap-amd64-$V-5.tar.xz ADASTRAP-i386 = adastrap-i386-$V-4.tar.xz Index: patches/patch-libstdc++-v3_src_c++17_floating_to_chars_cc =================================================================== RCS file: patches/patch-libstdc++-v3_src_c++17_floating_to_chars_cc diff -N patches/patch-libstdc++-v3_src_c++17_floating_to_chars_cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libstdc++-v3_src_c++17_floating_to_chars_cc 13 Sep 2025 18:02:43 -0000 @@ -0,0 +1,44 @@ +Avoid using sprintf, aside from its unsafety it triggers ld(1) +warnings leading to broken feature detection when linking test +programs with libestdc++. + +Index: libstdc++-v3/src/c++17/floating_to_chars.cc +--- libstdc++-v3/src/c++17/floating_to_chars.cc.orig ++++ libstdc++-v3/src/c++17/floating_to_chars.cc +@@ -879,7 +879,8 @@ namespace + #pragma GCC diagnostic ignored "-Wabi" + template + inline int +- sprintf_ld(char* buffer, const char* format_string, T value, Extra... args) ++ sprintf_ld(char* buffer, size_t length __attribute__((unused)), ++ const char* format_string, T value, Extra... args) + { + int len; + +@@ -894,7 +895,7 @@ namespace + len = __sprintfieee128(buffer, format_string, args..., value); + else + #endif +- len = sprintf(buffer, format_string, args..., value); ++ len = snprintf(buffer, length, format_string, args..., value); + + #if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) + if (saved_rounding_mode != FE_TONEAREST) +@@ -1040,7 +1041,7 @@ template + // digit, and carefully compute and write the last digit + // ourselves. + char buffer[expected_output_length+1]; +- const int output_length = sprintf_ld(buffer, "%.0Lf", value); ++ const int output_length = sprintf_ld(buffer, sizeof(buffer), "%.0Lf", value); + __glibcxx_assert(output_length == expected_output_length); + memcpy(first, buffer, output_length); + return {first + output_length, errc{}}; +@@ -1227,7 +1228,7 @@ template + // Do the sprintf into the local buffer. + char buffer[output_length_upper_bound+1]; + int output_length +- = sprintf_ld(buffer, output_specifier, value, effective_precision); ++ = sprintf_ld(buffer, sizeof(buffer), output_specifier, value, effective_precision); + __glibcxx_assert(output_length <= output_length_upper_bound); + + if (effective_precision > 0) -- jca