qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Fix const qualifier build errors with recent glibc
@ 2025-12-09 17:43 Cédric Le Goater
  2025-12-09 18:56 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Cédric Le Goater @ 2025-12-09 17:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Philippe Mathieu-Daudé, Markus Armbruster, Peter Maydell,
	Daniel P . Berrangé, Laurent Vivier, Cédric Le Goater

A recent change in glibc 2.42.9000 [1] changes the return type of
strstr() and other string functions to be 'const char *' when the
input is a 'const char *'.

This breaks the build in various files with errors such as :

  error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
    208 |         char *pidstr = strstr(filename, "%");
        |                        ^~~~~~

Fix this by changing the type of the variables that store the result
of these functions to 'const char *'.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---

 Most changes are straight forward apart from vubr_parse_host_port.
 Please check.

 Thanks,

 C.

 backends/tpm/tpm_passthrough.c | 2 +-
 block/vmdk.c                   | 2 +-
 block/vvfat.c                  | 2 +-
 gdbstub/gdbstub.c              | 2 +-
 qga/commands-linux.c           | 7 ++++---
 tests/vhost-user-bridge.c      | 2 +-
 ui/ui-hmp-cmds.c               | 2 +-
 util/log.c                     | 2 +-
 8 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/backends/tpm/tpm_passthrough.c b/backends/tpm/tpm_passthrough.c
index b7c7074c2aa3b0d7c1ed70cbcdb83b78fbd7dce8..a9f35ab7d606c79e148620b1a3e6b1d2bde63b7f 100644
--- a/backends/tpm/tpm_passthrough.c
+++ b/backends/tpm/tpm_passthrough.c
@@ -211,7 +211,7 @@ static size_t tpm_passthrough_get_buffer_size(TPMBackend *tb)
 static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)
 {
     int fd = -1;
-    char *dev;
+    const char *dev;
     char path[PATH_MAX];
 
     if (tpm_pt->options->cancel_path) {
diff --git a/block/vmdk.c b/block/vmdk.c
index 3b35b63cb5982364f40192eeb2c8585a0265ee40..89e89cd10e3594ad5be044b819ef4b875614e60a 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1089,7 +1089,7 @@ vmdk_open_vmdk4(BlockDriverState *bs, BdrvChild *file, int flags,
 static int vmdk_parse_description(const char *desc, const char *opt_name,
         char *buf, int buf_size)
 {
-    char *opt_pos, *opt_end;
+    const char *opt_pos, *opt_end;
     const char *end = desc + strlen(desc);
 
     opt_pos = strstr(desc, opt_name);
diff --git a/block/vvfat.c b/block/vvfat.c
index 814796d9185f14183194e0421b8c3ef052c81543..e334b9febb16056b3549558666e20bfddc3a22d6 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1826,7 +1826,7 @@ cluster_was_modified(BDRVVVFATState *s, uint32_t cluster_num)
 
 static const char* get_basename(const char* path)
 {
-    char* basename = strrchr(path, '/');
+    const char *basename = strrchr(path, '/');
     if (basename == NULL)
         return path;
     else
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index dd5fb5667ccd3bd4a303fb3f1b442f230cb44ffb..5b2fc06e58dffeabc9ef3b949d95b583c197e5fd 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -362,7 +362,7 @@ static const char *get_feature_xml(const char *p, const char **newp,
      * qXfer:features:read:ANNEX:OFFSET,LENGTH'
      *                     ^p    ^newp
      */
-    char *term = strchr(p, ':');
+    const char *term = strchr(p, ':');
     *newp = term + 1;
     len = term - p;
 
diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 4a09ddc760cc794be52e0d28fb6e3574d3827442..c639a60a9415c46abe5a2c8ca46dff5669cfdc43 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -403,7 +403,8 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
     int i, offset, nhosts = 0, pcilen;
     GuestPCIAddress *pciaddr = disk->pci_controller;
     bool has_ata = false, has_host = false, has_tgt = false;
-    char *p, *driver = NULL;
+    const char *p;
+    char *driver = NULL;
     bool ret = false;
 
     p = strstr(syspath, "/devices/pci");
@@ -543,7 +544,7 @@ static bool build_guest_fsinfo_for_nonpci_virtio(char const *syspath,
                                                  Error **errp)
 {
     unsigned int tgt[3];
-    char *p;
+    const char *p;
 
     if (!strstr(syspath, "/virtio") || !strstr(syspath, "/block")) {
         g_debug("Unsupported virtio device '%s'", syspath);
@@ -575,7 +576,7 @@ static bool build_guest_fsinfo_for_ccw_dev(char const *syspath,
                                            Error **errp)
 {
     unsigned int cssid, ssid, subchno, devno;
-    char *p;
+    const char *p;
 
     p = strstr(syspath, "/devices/css");
     if (!p || sscanf(p + 12, "%*x/%x.%x.%x/%*x.%*x.%x/",
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index a5c711b1de8e9c164dd1614f4329b8e3c05d0402..019424c2be8df8c8b5c8b6670574bb74cc7ba927 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -744,7 +744,7 @@ vubr_run(VubrDev *dev)
 }
 
 static int
-vubr_parse_host_port(const char **host, const char **port, const char *buf)
+vubr_parse_host_port(const char **host, const char **port, char *buf)
 {
     char *p = strchr(buf, ':');
 
diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c
index 980a8bbc518c72d000873d63d06dff9ab7b41395..6c93d452c9c43fe72561f036ebc41ab080a83285 100644
--- a/ui/ui-hmp-cmds.c
+++ b/ui/ui-hmp-cmds.c
@@ -418,7 +418,7 @@ err_out:
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     int i;
-    char *sep;
+    const char *sep;
     size_t len;
 
     if (nb_args != 2) {
diff --git a/util/log.c b/util/log.c
index 41f78ce86b2522b8b7072c8b76d8e18603142db6..c44d66b5ce78338cf1b2cd26b7503cb94d4570cb 100644
--- a/util/log.c
+++ b/util/log.c
@@ -203,7 +203,7 @@ static ValidFilenameTemplateResult
 valid_filename_template(const char *filename, bool per_thread, Error **errp)
 {
     if (filename) {
-        char *pidstr = strstr(filename, "%");
+        const char *pidstr = strstr(filename, "%");
 
         if (pidstr) {
             /* We only accept one %d, no other format strings */
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-09 17:43 [PATCH v3] Fix const qualifier build errors with recent glibc Cédric Le Goater
@ 2025-12-09 18:56 ` Peter Maydell
  2025-12-09 19:17 ` Philippe Mathieu-Daudé
  2025-12-10 10:35 ` Michael Tokarev
  2 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2025-12-09 18:56 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf,
	Hanna Reitz, Alex Bennée, Kostiantyn Kostiuk,
	Marc-André Lureau, Philippe Mathieu-Daudé,
	Markus Armbruster, Daniel P . Berrangé, Laurent Vivier

On Tue, 9 Dec 2025 at 17:43, Cédric Le Goater <clg@redhat.com> wrote:
>
> A recent change in glibc 2.42.9000 [1] changes the return type of
> strstr() and other string functions to be 'const char *' when the
> input is a 'const char *'.
>
> This breaks the build in various files with errors such as :
>
>   error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>     208 |         char *pidstr = strstr(filename, "%");
>         |                        ^~~~~~
>
> Fix this by changing the type of the variables that store the result
> of these functions to 'const char *'.
>
> [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>
>  Most changes are straight forward apart from vubr_parse_host_port.
>  Please check.

> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -744,7 +744,7 @@ vubr_run(VubrDev *dev)
>  }
>
>  static int
> -vubr_parse_host_port(const char **host, const char **port, const char *buf)
> +vubr_parse_host_port(const char **host, const char **port, char *buf)
>  {
>      char *p = strchr(buf, ':');

The other changes are all fine; this one's a little trickier.

The callers of this function pass the getopt() global 'optarg' as the
buf argument. That library interface is not specific about whether
modifying the string is permitted. In practice the strings will
be from the argv[] array, which you apparently are allowed to
modify per C99.

So I think this change is OK, but given that all we're doing
here is splitting the string on ':' we could also rewrite this
function (untested!):

static int
vubr_parse_host_port(const char **host, const char **port, const char *buf)
{
    g_auto(GStrv) tokens = g_strsplit(buf, ":", 2);
    if (!tokens[0] || !tokens[1])) {
        return -1;
    }
    *host = g_steal_pointer(&tokens[0]);
    *port = g_steal_pointer(&tokens[1]);
    return 0;
}

There's also a more minimal tweak we could do instead where instead
of writing a '\0' purely so we can use strdup() to copy the part
before the ':' we instead use strndup(). But I figured that using
the glib string-splitting routine was neater.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-09 17:43 [PATCH v3] Fix const qualifier build errors with recent glibc Cédric Le Goater
  2025-12-09 18:56 ` Peter Maydell
@ 2025-12-09 19:17 ` Philippe Mathieu-Daudé
  2025-12-09 20:07   ` Philippe Mathieu-Daudé
  2025-12-10  6:03   ` Cédric Le Goater
  2025-12-10 10:35 ` Michael Tokarev
  2 siblings, 2 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-12-09 19:17 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Markus Armbruster, Peter Maydell, Daniel P . Berrangé,
	Laurent Vivier

On 9/12/25 18:43, Cédric Le Goater wrote:
> A recent change in glibc 2.42.9000 [1] changes the return type of
> strstr() and other string functions to be 'const char *' when the
> input is a 'const char *'.
> 
> This breaks the build in various files with errors such as :
> 
>    error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>      208 |         char *pidstr = strstr(filename, "%");
>          |                        ^~~~~~
> 
> Fix this by changing the type of the variables that store the result
> of these functions to 'const char *'.
> 
> [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> 
>   Most changes are straight forward apart from vubr_parse_host_port.

Better keep the vubr_parse_host_port() change in a distinct patch (the
change isn't really what this commit describes).

For the others:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

>   Please check.
> 
>   Thanks,
> 
>   C.
> 
>   backends/tpm/tpm_passthrough.c | 2 +-
>   block/vmdk.c                   | 2 +-
>   block/vvfat.c                  | 2 +-
>   gdbstub/gdbstub.c              | 2 +-
>   qga/commands-linux.c           | 7 ++++---
>   tests/vhost-user-bridge.c      | 2 +-
>   ui/ui-hmp-cmds.c               | 2 +-
>   util/log.c                     | 2 +-
>   8 files changed, 11 insertions(+), 10 deletions(-)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-09 19:17 ` Philippe Mathieu-Daudé
@ 2025-12-09 20:07   ` Philippe Mathieu-Daudé
  2025-12-10  6:03   ` Cédric Le Goater
  1 sibling, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-12-09 20:07 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Markus Armbruster, Peter Maydell, Daniel P . Berrangé,
	Laurent Vivier

On 9/12/25 20:17, Philippe Mathieu-Daudé wrote:
> On 9/12/25 18:43, Cédric Le Goater wrote:
>> A recent change in glibc 2.42.9000 [1] changes the return type of
>> strstr() and other string functions to be 'const char *' when the
>> input is a 'const char *'.
>>
>> This breaks the build in various files with errors such as :
>>
>>    error: initialization discards 'const' qualifier from pointer 
>> target type [-Werror=discarded-qualifiers]
>>      208 |         char *pidstr = strstr(filename, "%");
>>          |                        ^~~~~~
>>
>> Fix this by changing the type of the variables that store the result
>> of these functions to 'const char *'.
>>
>> [1] https://sourceware.org/git/? 
>> p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>
>>   Most changes are straight forward apart from vubr_parse_host_port.
> 
> Better keep the vubr_parse_host_port() change in a distinct patch (the
> change isn't really what this commit describes).
> 
> For the others:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Queued without the vubr_parse_host_port() change, thanks.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-09 19:17 ` Philippe Mathieu-Daudé
  2025-12-09 20:07   ` Philippe Mathieu-Daudé
@ 2025-12-10  6:03   ` Cédric Le Goater
  1 sibling, 0 replies; 7+ messages in thread
From: Cédric Le Goater @ 2025-12-10  6:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Markus Armbruster, Peter Maydell, Daniel P . Berrangé,
	Laurent Vivier

On 12/9/25 20:17, Philippe Mathieu-Daudé wrote:
> On 9/12/25 18:43, Cédric Le Goater wrote:
>> A recent change in glibc 2.42.9000 [1] changes the return type of
>> strstr() and other string functions to be 'const char *' when the
>> input is a 'const char *'.
>>
>> This breaks the build in various files with errors such as :
>>
>>    error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>>      208 |         char *pidstr = strstr(filename, "%");
>>          |                        ^~~~~~
>>
>> Fix this by changing the type of the variables that store the result
>> of these functions to 'const char *'.
>>
>> [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>
>>   Most changes are straight forward apart from vubr_parse_host_port.
> 
> Better keep the vubr_parse_host_port() change in a distinct patch (the
> change isn't really what this commit describes).

A rewrite is preferable anyhow.

> For the others:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks,

C.
  
>>   Please check.
>>
>>   Thanks,
>>
>>   C.
>>
>>   backends/tpm/tpm_passthrough.c | 2 +-
>>   block/vmdk.c                   | 2 +-
>>   block/vvfat.c                  | 2 +-
>>   gdbstub/gdbstub.c              | 2 +-
>>   qga/commands-linux.c           | 7 ++++---
>>   tests/vhost-user-bridge.c      | 2 +-
>>   ui/ui-hmp-cmds.c               | 2 +-
>>   util/log.c                     | 2 +-
>>   8 files changed, 11 insertions(+), 10 deletions(-)
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-09 17:43 [PATCH v3] Fix const qualifier build errors with recent glibc Cédric Le Goater
  2025-12-09 18:56 ` Peter Maydell
  2025-12-09 19:17 ` Philippe Mathieu-Daudé
@ 2025-12-10 10:35 ` Michael Tokarev
  2025-12-10 10:50   ` Cédric Le Goater
  2 siblings, 1 reply; 7+ messages in thread
From: Michael Tokarev @ 2025-12-10 10:35 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Philippe Mathieu-Daudé, Markus Armbruster, Peter Maydell,
	Daniel P . Berrangé, Laurent Vivier, qemu-stable,
	Thomas Huth

On 12/9/25 20:43, Cédric Le Goater wrote:
> A recent change in glibc 2.42.9000 [1] changes the return type of
> strstr() and other string functions to be 'const char *' when the
> input is a 'const char *'.
> 
> This breaks the build in various files with errors such as :
> 
>    error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>      208 |         char *pidstr = strstr(filename, "%");
>          |                        ^~~~~~
> 
> Fix this by changing the type of the variables that store the result
> of these functions to 'const char *'.
> 
> [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

I'm picking this up for qemu-stable (10.0 & 10.1 series)
(together with 83f6dceb8f5c "qga: Fix ubsan warning").
Please let me know if I shouldn't.

Thanks,

/mjt


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] Fix const qualifier build errors with recent glibc
  2025-12-10 10:35 ` Michael Tokarev
@ 2025-12-10 10:50   ` Cédric Le Goater
  0 siblings, 0 replies; 7+ messages in thread
From: Cédric Le Goater @ 2025-12-10 10:50 UTC (permalink / raw)
  To: Michael Tokarev, qemu-devel
  Cc: qemu-block, Stefan Berger, Fam Zheng, Kevin Wolf, Hanna Reitz,
	Alex Bennée, Kostiantyn Kostiuk, Marc-André Lureau,
	Philippe Mathieu-Daudé, Markus Armbruster, Peter Maydell,
	Daniel P . Berrangé, Laurent Vivier, qemu-stable,
	Thomas Huth

On 12/10/25 11:35, Michael Tokarev wrote:
> On 12/9/25 20:43, Cédric Le Goater wrote:
>> A recent change in glibc 2.42.9000 [1] changes the return type of
>> strstr() and other string functions to be 'const char *' when the
>> input is a 'const char *'.
>>
>> This breaks the build in various files with errors such as :
>>
>>    error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>>      208 |         char *pidstr = strstr(filename, "%");
>>          |                        ^~~~~~
>>
>> Fix this by changing the type of the variables that store the result
>> of these functions to 'const char *'.
>>
>> [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
> 
> I'm picking this up for qemu-stable (10.0 & 10.1 series)
> (together with 83f6dceb8f5c "qga: Fix ubsan warning").
> Please let me know if I shouldn't.

This is a partial fix for the recent glibc update. We need at least
two other patches. One rewriting vubr_parse_host_port() as Peter
proposed and another for :

../hw/i386/x86-common.c:827:11: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   827 |     vmode = strstr(kernel_cmdline, "vga=");

which is missing in v3.

Anyhow, there is no harm in taking this first part. Future backports
should be simple enough.

Thanks,

C.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-10 10:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 17:43 [PATCH v3] Fix const qualifier build errors with recent glibc Cédric Le Goater
2025-12-09 18:56 ` Peter Maydell
2025-12-09 19:17 ` Philippe Mathieu-Daudé
2025-12-09 20:07   ` Philippe Mathieu-Daudé
2025-12-10  6:03   ` Cédric Le Goater
2025-12-10 10:35 ` Michael Tokarev
2025-12-10 10:50   ` Cédric Le Goater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).